diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 79925e3f2f..05e7376b3a 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -3781,7 +3781,7 @@ void nano::json_handler::republish_dependencies () bool broadcast_votes = true; - auto [num_blocks, num_votes] = republish_dependencies_impl (account, depth, count, broadcast_votes); + auto [num_blocks, num_votes] = republish_dependencies_impl (account, depth, count); response_l.put ("blocks", num_blocks); response_l.put ("votes", num_votes); @@ -3793,8 +3793,12 @@ void nano::json_handler::republish_dependencies () response_errors (); } -std::tuple nano::json_handler::republish_dependencies_impl (nano::account account, size_t depth, size_t count, bool broadcast_votes) +std::tuple nano::json_handler::republish_dependencies_impl (nano::account account, size_t depth, size_t count) { + bool const broadcast_votes = true; + bool const republish_receivable = true; + uint128_t const receivable_threshold = 1 * nano::Mxrb_ratio; + node.logger.info (nano::log::type::rpc, "Republishing blocks for account: {} with depth: {}, count: {}", account.to_account (), depth, count); auto transaction = node.store.tx_begin_read (); @@ -3944,10 +3948,28 @@ std::tuple nano::json_handler::republish_dependencies_impl (nano for (auto & block : blocks) { - node.logger.info (nano::log::type::rpc, "Republishing for block: {} with depth: {}", block->hash ().to_string (), depth); + node.logger.info (nano::log::type::rpc, "Republishing block: {} with depth: {}", block->hash ().to_string (), depth); dfs_traversal (depth, block, block_visitor); } + if (republish_receivable) + { + auto receivable = node.ledger.account_receivable_blocks (transaction, account, receivable_threshold); + + node.logger.info (nano::log::type::rpc, "Found {} receivable blocks for account: {} (threshold: {})", + receivable.size (), + account.to_account (), + receivable_threshold.convert_to ()); + + for (auto & hash : receivable) + { + auto block = node.ledger.block (transaction, hash); + release_assert (block); + node.logger.info (nano::log::type::rpc, "Republishing receivable block: {}", block->hash ().to_string ()); + dfs_traversal (depth, block, block_visitor); + } + } + node.logger.info (nano::log::type::rpc, "Republishing finished"); return { num_blocks, num_votes }; diff --git a/nano/node/json_handler.hpp b/nano/node/json_handler.hpp index 4be4515949..8b79ae770b 100644 --- a/nano/node/json_handler.hpp +++ b/nano/node/json_handler.hpp @@ -102,7 +102,7 @@ class json_handler : public std::enable_shared_from_this void republish (); void republish_dependencies (); /// @returns - std::tuple republish_dependencies_impl (nano::account account, size_t depth, size_t count, bool broadcast_votes); + std::tuple republish_dependencies_impl (nano::account account, size_t depth, size_t count); void search_pending (); void search_receivable (); void search_pending_all (); diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index fdddb045b8..6735f2516b 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -900,6 +900,21 @@ nano::uint128_t nano::ledger::account_receivable (store::transaction const & tra return result; } +std::vector nano::ledger::account_receivable_blocks (const store::transaction & transaction, const nano::account & account, nano::uint128_t threshold) +{ + std::vector result; + nano::account end{ account.number () + 1 }; + for (auto i (store.pending.begin (transaction, nano::pending_key (account, 0))), n (store.pending.begin (transaction, nano::pending_key{ end, 0 })); i != n; ++i) + { + nano::pending_info const & info = i->second; + if (info.amount.number () >= threshold) + { + result.push_back (i->first.hash); + } + } + return result; +} + std::optional nano::ledger::pending_info (store::transaction const & transaction, nano::pending_key const & key) const { nano::pending_info result; diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index 02a5c09828..1781911d8f 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -47,6 +47,7 @@ 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); + std::vector account_receivable_blocks (store::transaction const &, nano::account const &, nano::uint128_t threshold); nano::uint128_t weight (nano::account const &); std::shared_ptr block (store::transaction const &, nano::block_hash const &); std::shared_ptr successor (store::transaction const &, nano::qualified_root const &);