diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 1d98e73cb9..0624c17820 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -698,7 +698,7 @@ void nano::json_handler::account_info () } if (weight) { - auto account_weight (node.ledger.weight (account)); + auto account_weight (node.ledger.weight_exact (transaction, account)); response_l.put ("weight", account_weight.convert_to ()); } if (receivable) @@ -2784,7 +2784,7 @@ void nano::json_handler::ledger () } if (weight) { - auto account_weight (node.ledger.weight (account)); + auto account_weight (node.ledger.weight_exact (transaction, account)); response_a.put ("weight", account_weight.convert_to ()); } accounts.push_back (std::make_pair (account.to_account (), response_a)); @@ -2837,7 +2837,7 @@ void nano::json_handler::ledger () } if (weight) { - auto account_weight (node.ledger.weight (account)); + auto account_weight (node.ledger.weight_exact (transaction, account)); response_a.put ("weight", account_weight.convert_to ()); } accounts.push_back (std::make_pair (account.to_account (), response_a)); @@ -4716,7 +4716,7 @@ void nano::json_handler::wallet_ledger () } if (weight) { - auto account_weight (node.ledger.weight (account)); + auto account_weight (node.ledger.weight_exact (block_transaction, account)); entry.put ("weight", account_weight.convert_to ()); } if (receivable) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 8c0ca258b9..abbc2e180e 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -739,7 +739,8 @@ std::pair nano::node::balance_pending (nano::a nano::uint128_t nano::node::weight (nano::account const & account_a) { - return ledger.weight (account_a); + auto txn{ ledger.store.tx_begin_read () }; + return ledger.weight_exact (txn, account_a); } nano::uint128_t nano::node::minimum_principal_weight () diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 864ca4f016..a160855dca 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1537,6 +1537,7 @@ void nano::wallets::foreach_representative (std::function> action_accounts_l; { auto transaction_l (tx_begin_read ()); + auto ledger_txn{ node.ledger.store.tx_begin_read () }; nano::lock_guard lock{ mutex }; for (auto i (items.begin ()), n (items.end ()); i != n; ++i) { @@ -1551,7 +1552,7 @@ void nano::wallets::foreach_representative (std::function> & list_a) { diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index 6293ac1b62..ecd2a2627b 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -53,9 +53,16 @@ class ledger final bool block_exists (store::transaction const & transaction, nano::block_hash const & hash) const; nano::uint128_t account_balance (store::transaction const &, nano::account const &, bool = false); nano::uint128_t account_receivable (store::transaction const &, nano::account const &, bool = false); + /** + * Returns the cached vote weight for the given representative. + * If the weight is below the cache limit it returns 0. + * During bootstrap it returns the preconfigured bootstrap weights. + */ nano::uint128_t weight (nano::account const &); std::optional successor (store::transaction const &, nano::qualified_root const &) const noexcept; std::optional successor (store::transaction const & transaction, nano::block_hash const & hash) const noexcept; + /* Returns the exact vote weight for the given representative by doing a database lookup */ + nano::uint128_t weight_exact (store::transaction const &, nano::account const &); std::shared_ptr forked_block (store::transaction const &, nano::block const &); std::shared_ptr head_block (store::transaction const &, nano::account const &); bool block_confirmed (store::transaction const &, nano::block_hash const &) const;