diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 7c0e2cbcde..b34b065ad5 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1316,7 +1316,7 @@ void nano::json_handler::blocks_info () } if (receive_hash) { - std::shared_ptr receive_block = node.find_receive_block_by_send_hash (transaction, destination, hash); + std::shared_ptr receive_block = node.ledger.find_receive_block_by_send_hash (transaction, destination, hash); std::string receive_hash = receive_block ? receive_block->hash ().to_string () : nano::block_hash (0).to_string (); entry.put ("receive_hash", receive_hash); } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index a10c076b52..9eb0cd1cd4 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1774,54 +1774,6 @@ void nano::node::populate_backlog () } } -/** Given the block hash of a send block, find the associated receive block that receives that send. - * The send block hash is not checked in any way, it is assumed to be correct. - * @return Return the receive block on success and null on failure - */ -std::shared_ptr nano::node::find_receive_block_by_send_hash (nano::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash) -{ - std::shared_ptr result; - debug_assert (send_block_hash != 0); - - // get the cemented frontier - nano::confirmation_height_info info; - if (store.confirmation_height.get (transaction, destination, info)) - { - return nullptr; - } - auto possible_receive_block = store.block.get (transaction, info.frontier); - - // walk down the chain until the source field of a receive block matches the send block hash - while (possible_receive_block != nullptr) - { - // if source is non-zero then it is a legacy receive or open block - nano::block_hash source = possible_receive_block->source (); - - // if source is zero then it could be a state block, which needs a different kind of access - auto state_block = dynamic_cast (possible_receive_block.get ()); - if (state_block != nullptr) - { - // we read the block from the database, so we expect it to have sideband - debug_assert (state_block->has_sideband ()); - if (state_block->sideband ().details.is_receive) - { - source = state_block->hashables.link.as_block_hash (); - } - } - - if (send_block_hash == source) - { - // we have a match - result = possible_receive_block; - break; - } - - possible_receive_block = store.block.get (transaction, possible_receive_block->previous ()); - } - - return result; -} - nano::node_wrapper::node_wrapper (boost::filesystem::path const & path_a, boost::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a) : network_params{ nano::network_constants::active_network }, io_context (std::make_shared ()), diff --git a/nano/node/node.hpp b/nano/node/node.hpp index dc3722ab97..a188940d43 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -151,7 +151,6 @@ class node final : public std::enable_shared_from_this void set_bandwidth_params (std::size_t limit, double ratio); std::pair get_bootstrap_weights () const; void populate_backlog (); - std::shared_ptr find_receive_block_by_send_hash (nano::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash); nano::write_database_queue write_database_queue; boost::asio::io_context & io_ctx; boost::latch node_initialized_latch; diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 675c2fa989..61b5a48c54 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1237,6 +1237,54 @@ std::array nano::ledger::dependent_blocks (nano::transactio return visitor.result; } +/** Given the block hash of a send block, find the associated receive block that receives that send. + * The send block hash is not checked in any way, it is assumed to be correct. + * @return Return the receive block on success and null on failure + */ +std::shared_ptr nano::ledger::find_receive_block_by_send_hash (nano::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash) +{ + std::shared_ptr result; + debug_assert (send_block_hash != 0); + + // get the cemented frontier + nano::confirmation_height_info info; + if (store.confirmation_height.get (transaction, destination, info)) + { + return nullptr; + } + auto possible_receive_block = store.block.get (transaction, info.frontier); + + // walk down the chain until the source field of a receive block matches the send block hash + while (possible_receive_block != nullptr) + { + // if source is non-zero then it is a legacy receive or open block + nano::block_hash source = possible_receive_block->source (); + + // if source is zero then it could be a state block, which needs a different kind of access + auto state_block = dynamic_cast (possible_receive_block.get ()); + if (state_block != nullptr) + { + // we read the block from the database, so we expect it to have sideband + debug_assert (state_block->has_sideband ()); + if (state_block->sideband ().details.is_receive) + { + source = state_block->hashables.link.as_block_hash (); + } + } + + if (send_block_hash == source) + { + // we have a match + result = possible_receive_block; + break; + } + + possible_receive_block = store.block.get (transaction, possible_receive_block->previous ()); + } + + return result; +} + nano::account const & nano::ledger::epoch_signer (nano::link const & link_a) const { return constants.epochs.signer (constants.epochs.epoch (link_a)); diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index a27ee1be97..bfaaead9ab 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -63,6 +63,7 @@ class ledger final bool dependents_confirmed (nano::transaction const &, nano::block const &) const; bool is_epoch_link (nano::link const &) const; std::array dependent_blocks (nano::transaction const &, nano::block const &) const; + std::shared_ptr find_receive_block_by_send_hash (nano::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash); nano::account const & epoch_signer (nano::link const &) const; nano::link const & epoch_link (nano::epoch) const; std::multimap> unconfirmed_frontiers () const;