From b7fc721bfc86e1c47c6dd03e4b7f674fccff764c Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 12 Sep 2023 12:17:34 +0100 Subject: [PATCH] Use limiter in hinted scheduler --- nano/node/scheduler/hinted.cpp | 16 ++++++++++------ nano/node/scheduler/hinted.hpp | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/nano/node/scheduler/hinted.cpp b/nano/node/scheduler/hinted.cpp index 6c5d4933bd..92222b6ef2 100644 --- a/nano/node/scheduler/hinted.cpp +++ b/nano/node/scheduler/hinted.cpp @@ -1,6 +1,7 @@ #include #include #include +#include nano::scheduler::hinted::config::config (nano::node_config const & config) : vote_cache_check_interval_ms{ config.network_params.network.is_dev_network () ? 100u : 1000u } @@ -11,9 +12,8 @@ nano::scheduler::hinted::hinted (config const & config_a, nano::node & node_a, n config_m{ config_a }, node{ node_a }, inactive_vote_cache{ inactive_vote_cache_a }, - active{ active_a }, - online_reps{ online_reps_a }, - stats{ stats_a } + limiter{ std::make_shared (node.active.insert_fn (), std::max (node.config.active_elections_hinted_limit_percentage * node.config.active_elections_size / 100, 1u), nano::election_behavior::hinted) }, + online_reps{ online_reps_a }, stats{ stats_a } { } @@ -51,7 +51,7 @@ void nano::scheduler::hinted::notify () bool nano::scheduler::hinted::predicate (nano::uint128_t const & minimum_tally) const { // Check if there is space inside AEC for a new hinted election - if (active.vacancy (nano::election_behavior::hinted) > 0) + if (limiter->available ()) { // Check if there is any vote cache entry surpassing our minimum vote tally threshold if (inactive_vote_cache.peek (minimum_tally)) @@ -59,6 +59,10 @@ bool nano::scheduler::hinted::predicate (nano::uint128_t const & minimum_tally) return true; } } + else + { + std::cerr << '\0'; + } return false; } @@ -77,9 +81,9 @@ bool nano::scheduler::hinted::run_one (nano::uint128_t const & minimum_tally) { // Try to insert it into AEC as hinted election // We check for AEC vacancy inside our predicate - auto result = node.active.insert (block, nano::election_behavior::hinted); + auto result = limiter->activate (block); - stats.inc (nano::stat::type::hinting, result.inserted ? nano::stat::detail::insert : nano::stat::detail::insert_failed); + stats.inc (nano::stat::type::hinting, result.inserted ? nano::stat::detail::hinted : nano::stat::detail::insert_failed); return result.inserted; // Return whether block was inserted } diff --git a/nano/node/scheduler/hinted.hpp b/nano/node/scheduler/hinted.hpp index ba344095d2..1d974ad2d3 100644 --- a/nano/node/scheduler/hinted.hpp +++ b/nano/node/scheduler/hinted.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -17,6 +18,7 @@ class online_reps; } namespace nano::scheduler { +class limiter; /* * Monitors inactive vote cache and schedules elections with the highest observed vote tally. */ @@ -53,7 +55,7 @@ class hinted final private: // Dependencies nano::node & node; nano::vote_cache & inactive_vote_cache; - nano::active_transactions & active; + std::shared_ptr limiter; nano::online_reps & online_reps; nano::stats & stats;