diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index 9c1b7cc5d0..aeb5b80369 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -1,5 +1,6 @@ #include #include +#include #include nano::scheduler::priority::priority (nano::node & node_a, nano::stats & stats_a) : @@ -124,30 +125,42 @@ void nano::scheduler::priority::run () if (manual_queue_predicate ()) { auto const [block, previous_balance, election_behavior] = manual_queue.front (); - manual_queue.pop_front (); lock.unlock (); - stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_manual); auto result = node.active.insert (block, election_behavior); - if (result.election != nullptr) + if (result.election) { - result.election->transition_active (); + manual_queue.pop_front (); } + else + { + std::cerr << '\0'; + } + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_manual); } else if (priority_queue_predicate ()) { - auto block = buckets->top (); - buckets->pop (); - lock.unlock (); - stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority); - auto result = node.active.insert (block.first); - if (result.inserted) + if (!buckets->top ().second->available ()) { - stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority_success); + buckets->seek (); } + auto [block, limiter] = buckets->top (); + debug_assert (limiter->available ()); + auto result = limiter->activate (block); if (result.election != nullptr) { + buckets->pop (); + lock.unlock (); result.election->transition_active (); + if (result.inserted) + { + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority_success); + } } + else + { + lock.unlock (); + } + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::insert_priority); } else {