From eaddf00242519013e0e5416dc1e8911bf73040c1 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Sep 2023 17:23:27 +0100 Subject: [PATCH] Using limiter in optimistic scheduler --- nano/node/scheduler/optimistic.cpp | 7 ++++--- nano/node/scheduler/optimistic.hpp | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/nano/node/scheduler/optimistic.cpp b/nano/node/scheduler/optimistic.cpp index a00fa4d96c..5fd48c783d 100644 --- a/nano/node/scheduler/optimistic.cpp +++ b/nano/node/scheduler/optimistic.cpp @@ -1,13 +1,14 @@ #include #include #include +#include #include nano::scheduler::optimistic::optimistic (optimistic_config const & config_a, nano::node & node_a, nano::ledger & ledger_a, nano::active_transactions & active_a, nano::network_constants const & network_constants_a, nano::stats & stats_a) : config{ config_a }, node{ node_a }, ledger{ ledger_a }, - active{ active_a }, + limiter{ std::make_shared (node.active.insert_fn (), std::max (node.config.active_elections_optimistic_limit_percentage * node.config.active_elections_size / 100, 1u), nano::election_behavior::optimistic) }, network_constants{ network_constants_a }, stats{ stats_a } { @@ -100,7 +101,7 @@ bool nano::scheduler::optimistic::predicate () const { debug_assert (!mutex.try_lock ()); - if (active.vacancy (nano::election_behavior::optimistic) <= 0) + if (!limiter->available ()) { return false; } @@ -154,7 +155,7 @@ void nano::scheduler::optimistic::run_one (nano::transaction const & transaction { // Try to insert it into AEC // We check for AEC vacancy inside our predicate - auto result = node.active.insert (block, nano::election_behavior::optimistic); + auto result = limiter->activate (block); stats.inc (nano::stat::type::optimistic_scheduler, result.inserted ? nano::stat::detail::insert : nano::stat::detail::insert_failed); } diff --git a/nano/node/scheduler/optimistic.hpp b/nano/node/scheduler/optimistic.hpp index 3c16c72059..283e921a6a 100644 --- a/nano/node/scheduler/optimistic.hpp +++ b/nano/node/scheduler/optimistic.hpp @@ -22,13 +22,14 @@ namespace mi = boost::multi_index; namespace nano { -class node; -class ledger; class active_transactions; +class ledger; +class node; } namespace nano::scheduler { +class limiter; class optimistic_config final { public: @@ -76,7 +77,7 @@ class optimistic final optimistic_config const & config; nano::node & node; nano::ledger & ledger; - nano::active_transactions & active; + std::shared_ptr limiter; nano::network_constants const & network_constants; nano::stats & stats;