Skip to content

Commit

Permalink
Backlog scan callback event
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 25, 2024
1 parent 83954e4 commit 9d131be
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
5 changes: 2 additions & 3 deletions nano/core_test/backlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ TEST (backlog, population)
nano::test::system system{};
auto & node = *system.add_node ();

node.backlog_scan.activate_callback.add ([&] (nano::secure::transaction const & transaction, nano::account const & account) {
node.backlog_scan.activated.add ([&] (nano::secure::transaction const & transaction, auto const & info) {
nano::lock_guard<nano::mutex> lock{ mutex };

activated.insert (account);
activated.insert (info.account);
});

auto blocks = nano::test::setup_independent_blocks (system, node, 256);
Expand Down
9 changes: 3 additions & 6 deletions nano/node/backlog_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
#include <nano/store/component.hpp>
#include <nano/store/confirmation_height.hpp>

nano::backlog_scan::backlog_scan (backlog_scan_config const & config_a, nano::scheduler::component & schedulers, nano::ledger & ledger, nano::stats & stats_a) :
nano::backlog_scan::backlog_scan (backlog_scan_config const & config_a, nano::ledger & ledger, nano::stats & stats_a) :
config{ config_a },
schedulers{ schedulers },
ledger{ ledger },
stats{ stats_a }
{
Expand Down Expand Up @@ -135,10 +134,8 @@ void nano::backlog_scan::activate (secure::transaction const & transaction, nano
{
stats.inc (nano::stat::type::backlog, nano::stat::detail::activated);

activate_callback.notify (transaction, account);

schedulers.optimistic.activate (account, account_info, conf_info);
schedulers.priority.activate (transaction, account, account_info, conf_info);
activated_info info{ account, account_info, conf_info };
activated.notify (transaction, info);
}
}

Expand Down
16 changes: 11 additions & 5 deletions nano/node/backlog_scan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <nano/lib/numbers.hpp>
#include <nano/lib/observer_set.hpp>
#include <nano/node/fwd.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/secure/account_info.hpp>
#include <nano/secure/common.hpp>

#include <condition_variable>
Expand All @@ -30,7 +30,7 @@ class backlog_scan_config final
class backlog_scan final
{
public:
backlog_scan (backlog_scan_config const &, nano::scheduler::component &, nano::ledger &, nano::stats &);
backlog_scan (backlog_scan_config const &, nano::ledger &, nano::stats &);
~backlog_scan ();

void start ();
Expand All @@ -43,15 +43,21 @@ class backlog_scan final
void notify ();

public:
struct activated_info
{
nano::account account;
nano::account_info account_info;
nano::confirmation_height_info conf_info;
};

/**
* Callback called for each backlogged account
*/
using callback_t = nano::observer_set<secure::transaction const &, nano::account const &>;
callback_t activate_callback;
using callback_t = nano::observer_set<nano::secure::transaction const &, activated_info const &>;
callback_t activated;

private: // Dependencies
backlog_scan_config const & config;
nano::scheduler::component & schedulers;
nano::ledger & ledger;
nano::stats & stats;

Expand Down
7 changes: 6 additions & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
aggregator_impl{ std::make_unique<nano::request_aggregator> (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) },
aggregator{ *aggregator_impl },
wallets (wallets_store.init_error (), *this),
backlog_scan_impl{ std::make_unique<nano::backlog_scan> (config.backlog_scan, scheduler, ledger, stats) },
backlog_scan_impl{ std::make_unique<nano::backlog_scan> (config.backlog_scan, ledger, stats) },
backlog_scan{ *backlog_scan_impl },
bootstrap_server_impl{ std::make_unique<nano::bootstrap_server> (config.bootstrap_server, store, ledger, network_params.network, stats) },
bootstrap_server{ *bootstrap_server_impl },
Expand All @@ -180,6 +180,11 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
return ledger.weight (rep);
};

backlog_scan.activated.add ([this] (nano::secure::transaction const & transaction, auto const & info) {
scheduler.optimistic.activate (info.account, info.account_info, info.conf_info);
scheduler.priority.activate (transaction, info.account, info.account_info, info.conf_info);
});

// Republish vote if it is new and the node does not host a principal representative (or close to)
vote_router.vote_processed.add ([this] (std::shared_ptr<nano::vote> const & vote, nano::vote_source source, std::unordered_map<nano::block_hash, nano::vote_code> const & results) {
bool processed = std::any_of (results.begin (), results.end (), [] (auto const & result) {
Expand Down

0 comments on commit 9d131be

Please sign in to comment.