From cd5b6bd91f9e4245c7802787601829081832c76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:13:03 +0200 Subject: [PATCH] Pass explicit dependencies to election schedulers --- nano/node/node.cpp | 2 +- nano/node/scheduler/component.cpp | 8 ++++---- nano/node/scheduler/component.hpp | 4 +--- nano/node/scheduler/priority.cpp | 31 +++++++++++++++++-------------- nano/node/scheduler/priority.hpp | 5 ++++- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 3cb0e035..991b5c9c 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -137,7 +137,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy generator{ *generator_impl }, final_generator_impl{ std::make_unique (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true) }, final_generator{ *final_generator_impl }, - scheduler_impl{ std::make_unique (*this) }, + scheduler_impl{ std::make_unique (config, *this, ledger, active, online_reps, vote_cache, stats, logger) }, scheduler{ *scheduler_impl }, aggregator_impl{ std::make_unique (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) }, aggregator{ *aggregator_impl }, diff --git a/nano/node/scheduler/component.cpp b/nano/node/scheduler/component.cpp index de3f7469..97c5926d 100644 --- a/nano/node/scheduler/component.cpp +++ b/nano/node/scheduler/component.cpp @@ -5,11 +5,11 @@ #include #include -nano::scheduler::component::component (nano::node & node) : - hinted_impl{ std::make_unique (node.config.hinted_scheduler, node, node.vote_cache, node.active, node.online_reps, node.stats) }, +nano::scheduler::component::component (nano::node_config & node_config, nano::node & node, nano::ledger & ledger, nano::active_elections & active, nano::online_reps & online_reps, nano::vote_cache & vote_cache, nano::stats & stats, nano::logger & logger) : + hinted_impl{ std::make_unique (node_config.hinted_scheduler, node, vote_cache, active, online_reps, stats) }, manual_impl{ std::make_unique (node) }, - optimistic_impl{ std::make_unique (node.config.optimistic_scheduler, node, node.ledger, node.active, node.network_params.network, node.stats) }, - priority_impl{ std::make_unique (node, node.stats) }, + optimistic_impl{ std::make_unique (node_config.optimistic_scheduler, node, ledger, active, node_config.network_params.network, stats) }, + priority_impl{ std::make_unique (node_config, node, ledger, active, stats, logger) }, hinted{ *hinted_impl }, manual{ *manual_impl }, optimistic{ *optimistic_impl }, diff --git a/nano/node/scheduler/component.hpp b/nano/node/scheduler/component.hpp index 090b4f69..35b4a1b6 100644 --- a/nano/node/scheduler/component.hpp +++ b/nano/node/scheduler/component.hpp @@ -10,12 +10,10 @@ namespace nano::scheduler class component final { public: - explicit component (nano::node & node); + component (nano::node_config &, nano::node &, nano::ledger &, nano::active_elections &, nano::online_reps &, nano::vote_cache &, nano::stats &, nano::logger &); ~component (); - // Starts all schedulers void start (); - // Stops all schedulers void stop (); nano::container_info container_info () const; diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index b209a2c5..571753e9 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -7,10 +7,13 @@ #include #include -nano::scheduler::priority::priority (nano::node & node_a, nano::stats & stats_a) : - config{ node_a.config.priority_scheduler }, +nano::scheduler::priority::priority (nano::node_config & node_config, nano::node & node_a, nano::ledger & ledger_a, nano::active_elections & active_a, nano::stats & stats_a, nano::logger & logger_a) : + config{ node_config.priority_scheduler }, node{ node_a }, - stats{ stats_a } + ledger{ ledger_a }, + active{ active_a }, + stats{ stats_a }, + logger{ logger_a } { std::vector minimums; @@ -34,11 +37,11 @@ nano::scheduler::priority::priority (nano::node & node_a, nano::stats & stats_a) build_region (uint128_t{ 1 } << 116, uint128_t{ 1 } << 120, 2); minimums.push_back (uint128_t{ 1 } << 120); - node.logger.debug (nano::log::type::election_scheduler, "Number of buckets: {}", minimums.size ()); + logger.debug (nano::log::type::election_scheduler, "Number of buckets: {}", minimums.size ()); for (size_t i = 0u, n = minimums.size (); i < n; ++i) { - auto bucket = std::make_unique (minimums[i], node.config.priority_bucket, node.active, stats); + auto bucket = std::make_unique (minimums[i], node_config.priority_bucket, active, stats); buckets.emplace_back (std::move (bucket)); } } @@ -85,11 +88,11 @@ void nano::scheduler::priority::stop () bool nano::scheduler::priority::activate (secure::transaction const & transaction, nano::account const & account) { debug_assert (!account.is_zero ()); - auto info = node.ledger.any.account_get (transaction, account); + auto info = ledger.any.account_get (transaction, account); if (info) { nano::confirmation_height_info conf_info; - node.store.confirmation_height.get (transaction, account, conf_info); + ledger.store.confirmation_height.get (transaction, account, conf_info); if (conf_info.height < info->block_count) { return activate (transaction, account, *info, conf_info); @@ -103,14 +106,14 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio { debug_assert (conf_info.frontier != account_info.head); - auto hash = conf_info.height == 0 ? account_info.open_block : node.ledger.any.block_successor (transaction, conf_info.frontier).value (); - auto block = node.ledger.any.block_get (transaction, hash); + auto hash = conf_info.height == 0 ? account_info.open_block : ledger.any.block_successor (transaction, conf_info.frontier).value (); + auto block = ledger.any.block_get (transaction, hash); release_assert (block != nullptr); - if (node.ledger.dependents_confirmed (transaction, *block)) + if (ledger.dependents_confirmed (transaction, *block)) { auto const balance = block->balance (); - auto const previous_balance = node.ledger.any.block_balance (transaction, conf_info.frontier).value_or (0); + auto const previous_balance = ledger.any.block_balance (transaction, conf_info.frontier).value_or (0); auto const balance_priority = std::max (balance, previous_balance); bool added = false; @@ -120,8 +123,8 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio } if (added) { - node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated); - node.logger.trace (nano::log::type::election_scheduler, nano::log::detail::block_activated, + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated); + logger.trace (nano::log::type::election_scheduler, nano::log::detail::block_activated, nano::log::arg{ "account", account.to_account () }, // TODO: Convert to lazy eval nano::log::arg{ "block", block }, nano::log::arg{ "time", account_info.modified }, @@ -131,7 +134,7 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio } else { - node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activate_full); + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activate_full); } return true; // Activated diff --git a/nano/node/scheduler/priority.hpp b/nano/node/scheduler/priority.hpp index 72759818..0cf0252f 100644 --- a/nano/node/scheduler/priority.hpp +++ b/nano/node/scheduler/priority.hpp @@ -26,7 +26,7 @@ public: class priority final { public: - priority (nano::node &, nano::stats &); + priority (nano::node_config &, nano::node &, nano::ledger &, nano::active_elections &, nano::stats &, nano::logger &); ~priority (); void start (); @@ -48,7 +48,10 @@ public: private: // Dependencies priority_config const & config; nano::node & node; + nano::ledger & ledger; + nano::active_elections & active; nano::stats & stats; + nano::logger & logger; private: void run ();