Skip to content

Commit

Permalink
RECEIVABLE REPUBLISH
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 10, 2024
1 parent ba5c78d commit 545761f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
28 changes: 25 additions & 3 deletions nano/node/json_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -3793,8 +3793,12 @@ void nano::json_handler::republish_dependencies ()
response_errors ();
}

std::tuple<size_t, size_t> nano::json_handler::republish_dependencies_impl (nano::account account, size_t depth, size_t count, bool broadcast_votes)
std::tuple<size_t, size_t> 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 ();
Expand Down Expand Up @@ -3944,10 +3948,28 @@ std::tuple<size_t, size_t> 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<std::string> ());

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 };
Expand Down
2 changes: 1 addition & 1 deletion nano/node/json_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class json_handler : public std::enable_shared_from_this<nano::json_handler>
void republish ();
void republish_dependencies ();
/// @returns <num_blocks, num_votes>
std::tuple<size_t, size_t> republish_dependencies_impl (nano::account account, size_t depth, size_t count, bool broadcast_votes);
std::tuple<size_t, size_t> republish_dependencies_impl (nano::account account, size_t depth, size_t count);
void search_pending ();
void search_receivable ();
void search_pending_all ();
Expand Down
15 changes: 15 additions & 0 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,21 @@ nano::uint128_t nano::ledger::account_receivable (store::transaction const & tra
return result;
}

std::vector<nano::block_hash> nano::ledger::account_receivable_blocks (const store::transaction & transaction, const nano::account & account, nano::uint128_t threshold)
{
std::vector<nano::block_hash> 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::pending_info> nano::ledger::pending_info (store::transaction const & transaction, nano::pending_key const & key) const
{
nano::pending_info result;
Expand Down
1 change: 1 addition & 0 deletions nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::block_hash> account_receivable_blocks (store::transaction const &, nano::account const &, nano::uint128_t threshold);
nano::uint128_t weight (nano::account const &);
std::shared_ptr<nano::block> block (store::transaction const &, nano::block_hash const &);
std::shared_ptr<nano::block> successor (store::transaction const &, nano::qualified_root const &);
Expand Down

0 comments on commit 545761f

Please sign in to comment.