diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index b3ad511d9c..e86427c52e 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -5493,9 +5493,6 @@ TEST (ledger, pruning_safe_functions) ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2, ledger.balance_safe (transaction, send2->hash (), error)); ASSERT_FALSE (error); error = false; - ASSERT_EQ (0, ledger.amount_safe (transaction, send2->hash (), error)); - ASSERT_TRUE (error); - error = false; ASSERT_TRUE (ledger.account_safe (transaction, send1->hash (), error).is_zero ()); ASSERT_TRUE (error); error = false; diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index eef6340684..4b68347f20 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1137,12 +1137,7 @@ void nano::json_handler::block_info () { nano::account account (block->account ().is_zero () ? block->sideband ().account : block->account ()); response_l.put ("block_account", account.to_account ()); - bool error_or_pruned (false); - auto amount (node.ledger.amount_safe (transaction, hash, error_or_pruned)); - if (!error_or_pruned) - { - response_l.put ("amount", amount.convert_to ()); - } + response_l.put ("amount", block->sideband ().amount.number ().convert_to ()); auto balance (node.ledger.balance (transaction, hash)); response_l.put ("balance", balance.convert_to ()); response_l.put ("height", std::to_string (block->sideband ().height)); @@ -1202,17 +1197,13 @@ void nano::json_handler::block_confirm () node.active.recently_cemented.put (status); // Trigger callback for confirmed block auto account (node.ledger.account (transaction, hash)); - bool error_or_pruned (false); - auto amount (node.ledger.amount_safe (transaction, hash, error_or_pruned)); + auto amount = block_l->sideband ().amount.number (); bool is_state_send (false); bool is_state_epoch (false); - if (!error_or_pruned) + if (auto state = dynamic_cast (block_l.get ())) { - if (auto state = dynamic_cast (block_l.get ())) - { - is_state_send = node.ledger.is_send (transaction, *state); - is_state_epoch = amount == 0 && node.ledger.is_epoch_link (state->link ()); - } + is_state_send = node.ledger.is_send (transaction, *state); + is_state_epoch = amount == 0 && node.ledger.is_epoch_link (state->link ()); } node.observers.blocks.notify (status, {}, account, amount, is_state_send, is_state_epoch); } @@ -1296,12 +1287,7 @@ void nano::json_handler::blocks_info () boost::property_tree::ptree entry; nano::account account (block->account ().is_zero () ? block->sideband ().account : block->account ()); entry.put ("block_account", account.to_account ()); - bool error_or_pruned (false); - auto amount (node.ledger.amount_safe (transaction, hash, error_or_pruned)); - if (!error_or_pruned) - { - entry.put ("amount", amount.convert_to ()); - } + entry.put ("amount", block->sideband ().amount.number ().convert_to ()); auto balance (node.ledger.balance (transaction, hash)); entry.put ("balance", balance.convert_to ()); entry.put ("height", std::to_string (block->sideband ().height)); @@ -2382,12 +2368,7 @@ class history_visitor : public nano::block_visitor tree.put ("type", "send"); auto account (block_a.hashables.destination.to_account ()); tree.put ("account", account); - bool error_or_pruned (false); - auto amount (handler.node.ledger.amount_safe (transaction, hash, error_or_pruned).convert_to ()); - if (!error_or_pruned) - { - tree.put ("amount", amount); - } + tree.put ("amount", block_a.sideband ().amount.number ()); if (raw) { tree.put ("destination", account); @@ -2398,16 +2379,12 @@ class history_visitor : public nano::block_visitor void receive_block (nano::receive_block const & block_a) { tree.put ("type", "receive"); + tree.put ("amount", block_a.sideband ().amount.number ()); bool error_or_pruned (false); - auto amount (handler.node.ledger.amount_safe (transaction, hash, error_or_pruned).convert_to ()); + auto source_account (handler.node.ledger.account_safe (transaction, block_a.hashables.source, error_or_pruned)); if (!error_or_pruned) { - auto source_account (handler.node.ledger.account_safe (transaction, block_a.hashables.source, error_or_pruned)); - if (!error_or_pruned) - { - tree.put ("account", source_account.to_account ()); - } - tree.put ("amount", amount); + tree.put ("account", source_account.to_account ()); } if (raw) { @@ -2431,16 +2408,12 @@ class history_visitor : public nano::block_visitor } if (block_a.hashables.source != handler.node.ledger.constants.genesis->account ()) { + tree.put ("amount", block_a.sideband ().amount.number ()); bool error_or_pruned (false); - auto amount (handler.node.ledger.amount_safe (transaction, hash, error_or_pruned).convert_to ()); + auto source_account (handler.node.ledger.account_safe (transaction, block_a.hashables.source, error_or_pruned)); if (!error_or_pruned) { - auto source_account (handler.node.ledger.account_safe (transaction, block_a.hashables.source, error_or_pruned)); - if (!error_or_pruned) - { - tree.put ("account", source_account.to_account ()); - } - tree.put ("amount", amount); + tree.put ("account", source_account.to_account ()); } } else diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 629653a876..1b06ba6351 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -522,18 +522,14 @@ class short_text_visitor : public nano::block_visitor type = "Send"; account = block_a.hashables.destination; bool error_or_pruned (false); - amount = ledger.amount_safe (transaction, block_a.hash (), error_or_pruned); - if (error_or_pruned) - { - type = "Send (pruned)"; - } + amount = block_a.sideband ().amount.number (); } void receive_block (nano::receive_block const & block_a) { type = "Receive"; bool error_or_pruned (false); account = ledger.account_safe (transaction, block_a.hashables.source, error_or_pruned); - amount = ledger.amount_safe (transaction, block_a.hash (), error_or_pruned); + amount = block_a.sideband ().amount.number (); if (error_or_pruned) { type = "Receive (pruned)"; @@ -546,7 +542,7 @@ class short_text_visitor : public nano::block_visitor { bool error_or_pruned (false); account = ledger.account_safe (transaction, block_a.hashables.source, error_or_pruned); - amount = ledger.amount_safe (transaction, block_a.hash (), error_or_pruned); + amount = block_a.sideband ().amount.number (); if (error_or_pruned) { type = "Receive (pruned)"; diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 73ed6bb69b..e10e155f92 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1089,16 +1089,6 @@ std::optional nano::ledger::account_info (store::transaction return store.account.get (transaction, account); } -nano::uint128_t nano::ledger::amount_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const -{ - auto block (store.block.get (transaction_a, hash_a)); - debug_assert (block); - auto block_balance (balance (transaction_a, hash_a)); - auto previous_balance (balance_safe (transaction_a, block->previous (), error_a)); - return error_a ? 0 : block_balance > previous_balance ? block_balance - previous_balance - : previous_balance - block_balance; -} - // Return latest block for account nano::block_hash nano::ledger::latest (store::transaction const & transaction_a, nano::account const & account_a) { diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index af1fa84e49..a5772fc310 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -53,8 +53,6 @@ class ledger final * Return account containing hash, returns zero account if account can not be found */ nano::account account_safe (store::transaction const &, nano::block_hash const &) const; - /** Safe for previous block, but block hash_a must exist */ - nano::uint128_t amount_safe (store::transaction const &, nano::block_hash const & hash_a, bool &) const; static nano::uint128_t balance (nano::block const & block); nano::uint128_t balance (store::transaction const &, nano::block_hash const &) const; nano::uint128_t balance_safe (store::transaction const &, nano::block_hash const &, bool &) const;