Pass explicit dependencies to election schedulers
This commit is contained in:
parent
5c311726d1
commit
cd5b6bd91f
5 changed files with 27 additions and 23 deletions
|
@ -137,7 +137,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
|
|||
generator{ *generator_impl },
|
||||
final_generator_impl{ std::make_unique<nano::vote_generator> (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true) },
|
||||
final_generator{ *final_generator_impl },
|
||||
scheduler_impl{ std::make_unique<nano::scheduler::component> (*this) },
|
||||
scheduler_impl{ std::make_unique<nano::scheduler::component> (config, *this, ledger, active, online_reps, vote_cache, stats, logger) },
|
||||
scheduler{ *scheduler_impl },
|
||||
aggregator_impl{ std::make_unique<nano::request_aggregator> (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) },
|
||||
aggregator{ *aggregator_impl },
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
#include <nano/node/scheduler/optimistic.hpp>
|
||||
#include <nano/node/scheduler/priority.hpp>
|
||||
|
||||
nano::scheduler::component::component (nano::node & node) :
|
||||
hinted_impl{ std::make_unique<nano::scheduler::hinted> (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<nano::scheduler::hinted> (node_config.hinted_scheduler, node, vote_cache, active, online_reps, stats) },
|
||||
manual_impl{ std::make_unique<nano::scheduler::manual> (node) },
|
||||
optimistic_impl{ std::make_unique<nano::scheduler::optimistic> (node.config.optimistic_scheduler, node, node.ledger, node.active, node.network_params.network, node.stats) },
|
||||
priority_impl{ std::make_unique<nano::scheduler::priority> (node, node.stats) },
|
||||
optimistic_impl{ std::make_unique<nano::scheduler::optimistic> (node_config.optimistic_scheduler, node, ledger, active, node_config.network_params.network, stats) },
|
||||
priority_impl{ std::make_unique<nano::scheduler::priority> (node_config, node, ledger, active, stats, logger) },
|
||||
hinted{ *hinted_impl },
|
||||
manual{ *manual_impl },
|
||||
optimistic{ *optimistic_impl },
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -7,10 +7,13 @@
|
|||
#include <nano/secure/ledger_set_any.hpp>
|
||||
#include <nano/secure/ledger_set_confirmed.hpp>
|
||||
|
||||
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<nano::uint128_t> 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<scheduler::bucket> (minimums[i], node.config.priority_bucket, node.active, stats);
|
||||
auto bucket = std::make_unique<scheduler::bucket> (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
|
||||
|
|
|
@ -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 ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue