diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index f292f4bcff..90821b54f5 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -266,7 +266,7 @@ TEST (ledger, process_receive) ASSERT_EQ (nano::dev::constants.genesis_amount - 25, ledger.account_balance (transaction, key2.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount - 25, ledger.weight (key3.pub)); ASSERT_FALSE (ledger.rollback (transaction, hash4)); - ASSERT_TRUE (store.block.successor (transaction, hash2).is_zero ()); + ASSERT_FALSE (ledger.successor (transaction, hash2)); ASSERT_EQ (key2.pub, store.frontier.get (transaction, hash2)); ASSERT_TRUE (store.frontier.get (transaction, hash4).is_zero ()); ASSERT_EQ (25, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); @@ -3156,7 +3156,7 @@ TEST (ledger, state_rollback_send) ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); - ASSERT_TRUE (store.block.successor (transaction, nano::dev::genesis->hash ()).is_zero ()); + ASSERT_FALSE (ledger.successor (transaction, nano::dev::genesis->hash ())); ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count); } diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 97268e8849..0b3c67a56d 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1588,7 +1588,7 @@ int main (int argc, char * const * argv) calculated_representative = block->representative_field ().value (); } // Retrieving successor block hash - hash = node->store.block.successor (transaction, hash); + hash = node->ledger.successor (transaction, hash).value_or (0); // Retrieving block data if (!hash.is_zero ()) { diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index a1fe5b8ec2..c5ca04b28b 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -376,7 +376,7 @@ void nano::bulk_pull_server::set_current_end () { node->logger.debug (nano::log::type::bulk_pull_server, "Bulk pull request for block hash: {}", request->start.to_string ()); - current = ascending () ? node->store.block.successor (transaction, request->start.as_block_hash ()) : request->start.as_block_hash (); + current = ascending () ? node->ledger.successor (transaction, request->start.as_block_hash ()).value_or (0) : request->start.as_block_hash (); include_start = true; } else diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 27e7c92f12..78eb9502f9 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1956,7 +1956,7 @@ void nano::json_handler::chain (bool successors) entry.put ("", hash.to_string ()); blocks.push_back (std::make_pair ("", entry)); } - hash = successors ? node.store.block.successor (transaction, hash) : block_l->previous (); + hash = successors ? node.ledger.successor (transaction, hash).value_or (0) : block_l->previous (); } else { @@ -2665,7 +2665,7 @@ void nano::json_handler::account_history () --count; } } - hash = reverse ? node.store.block.successor (transaction, hash) : block->previous (); + hash = reverse ? node.ledger.successor (transaction, hash).value_or (0) : block->previous (); block = node.ledger.block (transaction, hash); } response_l.add_child ("history", history); @@ -3698,7 +3698,7 @@ void nano::json_handler::republish () } } } - hash = node.store.block.successor (transaction, hash); + hash = node.ledger.successor (transaction, hash).value_or (0); } node.network.flood_block_many (std::move (republish_bundle), nullptr, 25); response_l.put ("success", ""); // obsolete diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index 72a5e3e405..32ad38d61d 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -246,24 +246,14 @@ std::pair>, std::vectoropen_block; - } - } - if (!successor.is_zero ()) + auto successor = ledger.successor (transaction, root.as_block_hash ()); + if (successor) { - auto successor_block = ledger.block (transaction, successor); + auto successor_block = ledger.block (transaction, successor.value ()); debug_assert (successor_block != nullptr); block = std::move (successor_block); // 5. Votes in cache for successor - auto find_successor_votes (local_votes.votes (root, successor)); + auto find_successor_votes (local_votes.votes (root, successor.value ())); if (!find_successor_votes.empty ()) { cached_votes.insert (cached_votes.end (), find_successor_votes.begin (), find_successor_votes.end ()); diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index 3fbaafda39..f8e03ff396 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -48,7 +48,7 @@ bool nano::scheduler::priority::activate (nano::account const & account_a, store if (conf_info.height < info->block_count) { debug_assert (conf_info.frontier != info->head); - auto hash = conf_info.height == 0 ? info->open_block : node.store.block.successor (transaction, conf_info.frontier); + auto hash = conf_info.height == 0 ? info->open_block : node.ledger.successor (transaction, conf_info.frontier).value_or (0); auto block = node.ledger.block (transaction, hash); debug_assert (block != nullptr); if (node.ledger.dependents_confirmed (transaction, *block)) diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 2b07123e27..78dcaf88e4 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -693,7 +693,7 @@ nano_qt::block_viewer::block_viewer (nano_qt::wallet & wallet_a) : std::string contents; block_l->serialize_json (contents); block->setPlainText (contents.c_str ()); - auto successor_l (this->wallet.node.store.block.successor (transaction, hash_l)); + auto successor_l = this->wallet.node.ledger.successor (transaction, hash_l).value_or (0); successor->setText (successor_l.to_string ().c_str ()); } else @@ -737,13 +737,13 @@ void nano_qt::block_viewer::rebroadcast_action (nano::block_hash const & hash_a) if (block != nullptr) { wallet.node.network.flood_block (block); - auto successor (wallet.node.store.block.successor (transaction, hash_a)); - if (!successor.is_zero ()) + auto successor = wallet.node.ledger.successor (transaction, hash_a); + if (successor) { done = false; wallet.node.workers.add_timed_task (std::chrono::steady_clock::now () + std::chrono::seconds (1), [this, successor] () { this->wallet.application.postEvent (&this->wallet.processor, new eventloop_event ([this, successor] () { - rebroadcast_action (successor); + rebroadcast_action (successor.value ()); })); }); } diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 5c0508eb0e..bd9299b529 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1274,12 +1274,22 @@ std::optional nano::ledger::successor (store::transaction cons } } +std::optional nano::ledger::successor (store::transaction const & transaction, nano::block_hash const & hash) noexcept +{ + return successor (transaction, { hash, hash }); +} + std::shared_ptr nano::ledger::forked_block (store::transaction const & transaction_a, nano::block const & block_a) { debug_assert (!block_exists (transaction_a, block_a.hash ())); auto root (block_a.root ()); debug_assert (block_exists (transaction_a, root.as_block_hash ()) || store.account.exists (transaction_a, root.as_account ())); - auto result = block (transaction_a, store.block.successor (transaction_a, root.as_block_hash ())); + std::shared_ptr result; + auto successor_l = successor (transaction_a, root.as_block_hash ()); + if (successor_l) + { + result = block (transaction_a, successor_l.value ()); + } if (result == nullptr) { auto info = account_info (transaction_a, root.as_account ()); diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index 5acc3e327e..711175724d 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -52,6 +52,7 @@ class ledger final nano::uint128_t account_receivable (store::transaction const &, nano::account const &, bool = false); nano::uint128_t weight (nano::account const &); std::optional successor (store::transaction const &, nano::qualified_root const &) noexcept; + std::optional successor (store::transaction const & transaction, nano::block_hash const & hash) noexcept; 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;