Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some minor cleanup #2291

Merged
merged 1 commit into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions nano/core_test/epochs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,4 @@ TEST (epochs, is_epoch_link)
epochs.add (nano::epoch::epoch_1, key1.pub, 42);
ASSERT_TRUE (epochs.is_epoch_link (42));
ASSERT_FALSE (epochs.is_epoch_link (43));
/*epochs.add (nano::epoch::epoch_2, key2.pub, 43);
ASSERT_TRUE (epochs.is_epoch_link (43));
ASSERT_EQ (key1.pub, epochs.signer (nano::epoch::epoch_1));
ASSERT_EQ (key2.pub, epochs.signer (nano::epoch::epoch_2));
ASSERT_EQ (nano::uint256_union (42), epochs.link (nano::epoch::epoch_1));
ASSERT_EQ (nano::uint256_union (43), epochs.link (nano::epoch::epoch_2));*/
}
5 changes: 2 additions & 3 deletions nano/node/confirmation_height_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
#include <cassert>
#include <numeric>

nano::confirmation_height_processor::confirmation_height_processor (nano::pending_confirmation_height & pending_confirmation_height_a, nano::ledger & ledger_a, nano::active_transactions & active_a, nano::write_database_queue & write_database_queue_a, std::chrono::milliseconds batch_separate_pending_min_time_a, nano::logger_mt & logger_a, std::atomic<uint64_t> & cemented_count_a) :
nano::confirmation_height_processor::confirmation_height_processor (nano::pending_confirmation_height & pending_confirmation_height_a, nano::ledger & ledger_a, nano::active_transactions & active_a, nano::write_database_queue & write_database_queue_a, std::chrono::milliseconds batch_separate_pending_min_time_a, nano::logger_mt & logger_a) :
pending_confirmations (pending_confirmation_height_a),
ledger (ledger_a),
active (active_a),
logger (logger_a),
write_database_queue (write_database_queue_a),
batch_separate_pending_min_time (batch_separate_pending_min_time_a),
cemented_count (cemented_count_a),
thread ([this]() {
nano::thread_role::set (nano::thread_role::name::confirmation_height_processing);
this->run ();
Expand Down Expand Up @@ -302,7 +301,7 @@ bool nano::confirmation_height_processor::write_pending (std::deque<conf_height_
ledger.stats.add (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in, pending.height - confirmation_height);
assert (pending.num_blocks_confirmed == pending.height - confirmation_height);
confirmation_height = pending.height;
cemented_count += pending.num_blocks_confirmed;
ledger.cemented_count += pending.num_blocks_confirmed;
ledger.store.confirmation_height_put (transaction, pending.account, confirmation_height);
}
total_pending_write_block_count -= pending.num_blocks_confirmed;
Expand Down
3 changes: 1 addition & 2 deletions nano/node/confirmation_height_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::unique_ptr<seq_con_info_component> collect_seq_con_info (pending_confirmati
class confirmation_height_processor final
{
public:
confirmation_height_processor (pending_confirmation_height &, nano::ledger &, nano::active_transactions &, nano::write_database_queue &, std::chrono::milliseconds, nano::logger_mt &, std::atomic<uint64_t> &);
confirmation_height_processor (pending_confirmation_height &, nano::ledger &, nano::active_transactions &, nano::write_database_queue &, std::chrono::milliseconds, nano::logger_mt &);
~confirmation_height_processor ();
void add (nano::block_hash const &);
void stop ();
Expand Down Expand Up @@ -93,7 +93,6 @@ class confirmation_height_processor final
nano::timer<std::chrono::milliseconds> timer;
nano::write_database_queue & write_database_queue;
std::chrono::milliseconds batch_separate_pending_min_time;
std::atomic<uint64_t> & cemented_count;
std::thread thread;

void run ();
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ block_processor_thread ([this]() {
online_reps (*this, config.online_weight_minimum.number ()),
vote_uniquer (block_uniquer),
active (*this),
confirmation_height_processor (pending_confirmation_height, ledger, active, write_database_queue, config.conf_height_processor_batch_min_time, logger, ledger.cemented_count),
confirmation_height_processor (pending_confirmation_height, ledger, active, write_database_queue, config.conf_height_processor_batch_min_time, logger),
payment_observer_processor (observers.blocks),
wallets (wallets_store.init_error (), *this),
startup_time (std::chrono::steady_clock::now ())
Expand Down
2 changes: 1 addition & 1 deletion nano/secure/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ add_library (secure
blockstore.hpp
blockstore_partial.hpp
blockstore.cpp
epoch.cpp
epoch.hpp
epoch.cpp
ledger.hpp
ledger.cpp
utility.hpp
Expand Down
8 changes: 4 additions & 4 deletions nano/secure/epoch.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include <nano/secure/epoch.hpp>

nano::uint256_union nano::epochs::link (nano::epoch epoch_a) const
nano::uint256_union const & nano::epochs::link (nano::epoch epoch_a) const
{
return epochs_m.at (epoch_a).link;
}

bool nano::epochs::is_epoch_link (nano::uint256_union const & link_a) const
{
return std::any_of (epochs_m.begin (), epochs_m.end (), [link_a](decltype (epochs_m)::value_type const & item_a) { return item_a.second.link == link_a; });
return std::any_of (epochs_m.begin (), epochs_m.end (), [&link_a](auto const & item_a) { return item_a.second.link == link_a; });
}

nano::public_key nano::epochs::signer (nano::epoch epoch_a) const
nano::public_key const & nano::epochs::signer (nano::epoch epoch_a) const
{
return epochs_m.at (epoch_a).signer;
}

nano::epoch nano::epochs::epoch (nano::uint256_union const & link_a) const
{
auto existing (std::find_if (epochs_m.begin (), epochs_m.end (), [link_a](decltype (epochs_m)::value_type const & item_a) { return item_a.second.link == link_a; }));
auto existing (std::find_if (epochs_m.begin (), epochs_m.end (), [&link_a](auto const & item_a) { return item_a.second.link == link_a; }));
assert (existing != epochs_m.end ());
return existing->first;
}
Expand Down
4 changes: 2 additions & 2 deletions nano/secure/epoch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class epochs
{
public:
bool is_epoch_link (nano::uint256_union const & link_a) const;
nano::uint256_union link (nano::epoch epoch_a) const;
nano::public_key signer (nano::epoch epoch_a) const;
nano::uint256_union const & link (nano::epoch epoch_a) const;
nano::public_key const & signer (nano::epoch epoch_a) const;
nano::epoch epoch (nano::uint256_union const & link_a) const;
void add (nano::epoch epoch_a, nano::public_key const & signer_a, nano::uint256_union const & link_a);

Expand Down
37 changes: 16 additions & 21 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

namespace
{
void representation_add (nano::transaction const & transaction_a, nano::ledger & ledger_a, nano::account const & representative_a, nano::uint128_t const & amount_a)
{
ledger_a.rep_weights.representation_add (representative_a, amount_a);
}

/**
* Roll back the visited block
*/
Expand Down Expand Up @@ -41,7 +36,7 @@ class rollback_visitor : public nano::block_visitor
(void)error;
assert (!error);
ledger.store.pending_del (transaction, key);
representation_add (transaction, ledger, info.representative, pending.amount.number ());
ledger.rep_weights.representation_add (info.representative, pending.amount.number ());
nano::account_info new_info (block_a.hashables.previous, info.representative, info.open_block, ledger.balance (transaction, block_a.hashables.previous), nano::seconds_since_epoch (), info.block_count - 1, nano::epoch::epoch_0);
ledger.change_latest (transaction, pending.source, info, new_info);
ledger.store.block_del (transaction, hash);
Expand All @@ -61,7 +56,7 @@ class rollback_visitor : public nano::block_visitor
auto error (ledger.store.account_get (transaction, destination_account, info));
(void)error;
assert (!error);
representation_add (transaction, ledger, info.representative, 0 - amount);
ledger.rep_weights.representation_add (info.representative, 0 - amount);
nano::account_info new_info (block_a.hashables.previous, info.representative, info.open_block, ledger.balance (transaction, block_a.hashables.previous), nano::seconds_since_epoch (), info.block_count - 1, nano::epoch::epoch_0);
ledger.change_latest (transaction, destination_account, info, new_info);
ledger.store.block_del (transaction, hash);
Expand All @@ -77,7 +72,7 @@ class rollback_visitor : public nano::block_visitor
auto amount (ledger.amount (transaction, block_a.hashables.source));
auto destination_account (ledger.account (transaction, hash));
auto source_account (ledger.account (transaction, block_a.hashables.source));
representation_add (transaction, ledger, block_a.representative (), 0 - amount);
ledger.rep_weights.representation_add (block_a.representative (), 0 - amount);
nano::account_info new_info;
ledger.change_latest (transaction, destination_account, new_info, new_info);
ledger.store.block_del (transaction, hash);
Expand All @@ -98,8 +93,8 @@ class rollback_visitor : public nano::block_visitor
auto block = ledger.store.block_get (transaction, rep_block);
release_assert (block != nullptr);
auto representative = block->representative ();
representation_add (transaction, ledger, block_a.representative (), 0 - balance);
representation_add (transaction, ledger, representative, balance);
ledger.rep_weights.representation_add (block_a.representative (), 0 - balance);
ledger.rep_weights.representation_add (representative, balance);
ledger.store.block_del (transaction, hash);
nano::account_info new_info (block_a.hashables.previous, representative, info.open_block, info.balance, nano::seconds_since_epoch (), info.block_count - 1, nano::epoch::epoch_0);
ledger.change_latest (transaction, account, info, new_info);
Expand All @@ -119,15 +114,15 @@ class rollback_visitor : public nano::block_visitor
auto balance (ledger.balance (transaction, block_a.hashables.previous));
auto is_send (block_a.hashables.balance < balance);
// Add in amount delta
representation_add (transaction, ledger, block_a.representative (), 0 - block_a.hashables.balance.number ());
ledger.rep_weights.representation_add (block_a.representative (), 0 - block_a.hashables.balance.number ());
nano::account representative{ 0 };
if (!rep_block_hash.is_zero ())
{
// Move existing representation
auto block (ledger.store.block_get (transaction, rep_block_hash));
assert (block != nullptr);
representative = block->representative ();
representation_add (transaction, ledger, representative, balance);
ledger.rep_weights.representation_add (representative, balance);
}

nano::account_info info;
Expand Down Expand Up @@ -335,13 +330,13 @@ void ledger_processor::state_block_impl (nano::state_block const & block_a)
if (!info.representative.is_zero ())
{
// Move existing representation
representation_add (transaction, ledger, info.representative, 0 - info.balance.number ());
ledger.rep_weights.representation_add (info.representative, 0 - info.balance.number ());
}
// Add in amount delta
auto block (ledger.store.block_get (transaction, hash));
assert (block != nullptr);
auto representative = block->representative ();
representation_add (transaction, ledger, representative, block_a.hashables.balance.number ());
ledger.rep_weights.representation_add (representative, block_a.hashables.balance.number ());

if (is_send)
{
Expand Down Expand Up @@ -468,8 +463,8 @@ void ledger_processor::change_block (nano::change_block const & block_a)
nano::block_sideband sideband (nano::block_type::change, account, 0, info.balance, info.block_count + 1, nano::seconds_since_epoch ());
ledger.store.block_put (transaction, hash, block_a, sideband);
auto balance (ledger.balance (transaction, block_a.hashables.previous));
representation_add (transaction, ledger, block_a.representative (), balance);
representation_add (transaction, ledger, info.representative, 0 - balance);
ledger.rep_weights.representation_add (block_a.representative (), balance);
ledger.rep_weights.representation_add (info.representative, 0 - balance);
nano::account_info new_info (hash, block_a.representative (), info.open_block, info.balance, nano::seconds_since_epoch (), info.block_count + 1, nano::epoch::epoch_0);
ledger.change_latest (transaction, account, info, new_info);
ledger.store.frontier_del (transaction, block_a.hashables.previous);
Expand Down Expand Up @@ -520,7 +515,7 @@ void ledger_processor::send_block (nano::send_block const & block_a)
if (result.code == nano::process_result::progress)
{
auto amount (info.balance.number () - block_a.hashables.balance.number ());
representation_add (transaction, ledger, info.representative, 0 - amount);
ledger.rep_weights.representation_add (info.representative, 0 - amount);
nano::block_sideband sideband (nano::block_type::send, account, 0, block_a.hashables.balance /* unused */, info.block_count + 1, nano::seconds_since_epoch ());
ledger.store.block_put (transaction, hash, block_a, sideband);
nano::account_info new_info (hash, info.representative, info.open_block, block_a.hashables.balance, nano::seconds_since_epoch (), info.block_count + 1, nano::epoch::epoch_0);
Expand Down Expand Up @@ -593,7 +588,7 @@ void ledger_processor::receive_block (nano::receive_block const & block_a)
ledger.store.block_put (transaction, hash, block_a, sideband);
nano::account_info new_info (hash, info.representative, info.open_block, new_balance, nano::seconds_since_epoch (), info.block_count + 1, nano::epoch::epoch_0);
ledger.change_latest (transaction, account, info, new_info);
representation_add (transaction, ledger, info.representative, pending.amount.number ());
ledger.rep_weights.representation_add (info.representative, pending.amount.number ());
ledger.store.frontier_del (transaction, block_a.hashables.previous);
ledger.store.frontier_put (transaction, hash, account);
result.account = account;
Expand Down Expand Up @@ -657,7 +652,7 @@ void ledger_processor::open_block (nano::open_block const & block_a)
ledger.store.block_put (transaction, hash, block_a, sideband);
nano::account_info new_info (hash, block_a.representative (), hash, pending.amount.number (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0);
ledger.change_latest (transaction, block_a.hashables.account, info, new_info);
representation_add (transaction, ledger, block_a.representative (), pending.amount.number ());
ledger.rep_weights.representation_add (block_a.representative (), pending.amount.number ());
ledger.store.frontier_put (transaction, hash, block_a.hashables.account);
result.account = block_a.hashables.account;
result.amount = pending.amount;
Expand Down Expand Up @@ -1031,12 +1026,12 @@ bool nano::ledger::is_epoch_link (nano::uint256_union const & link_a)
return network_params.ledger.epochs.is_epoch_link (link_a);
}

nano::account nano::ledger::signer (nano::uint256_union const & link_a) const
nano::account const & nano::ledger::signer (nano::uint256_union const & link_a) const
{
return network_params.ledger.epochs.signer (network_params.ledger.epochs.epoch (link_a));
}

nano::uint256_union nano::ledger::link (nano::epoch epoch_a) const
nano::uint256_union const & nano::ledger::link (nano::epoch epoch_a) const
{
return network_params.ledger.epochs.link (nano::epoch::epoch_1);
}
Expand Down
4 changes: 2 additions & 2 deletions nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class ledger final
void dump_account_chain (nano::account const &);
bool could_fit (nano::transaction const &, nano::block const &);
bool is_epoch_link (nano::uint256_union const &);
nano::account signer (nano::uint256_union const &) const;
nano::uint256_union link (nano::epoch) const;
nano::account const & signer (nano::uint256_union const &) const;
nano::uint256_union const & link (nano::epoch) const;
size_t block_count () const;
static nano::uint128_t const unit;
nano::network_params network_params;
Expand Down