Skip to content

Commit

Permalink
Use limiter in hinted scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Sep 12, 2023
1 parent eaddf00 commit b7fc721
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 10 additions & 6 deletions nano/node/scheduler/hinted.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <nano/lib/stats.hpp>
#include <nano/node/node.hpp>
#include <nano/node/scheduler/hinted.hpp>
#include <nano/node/scheduler/limiter.hpp>

nano::scheduler::hinted::config::config (nano::node_config const & config) :
vote_cache_check_interval_ms{ config.network_params.network.is_dev_network () ? 100u : 1000u }
Expand All @@ -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<nano::scheduler::limiter> (node.active.insert_fn (), std::max<size_t> (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 }
{
}

Expand Down Expand Up @@ -51,14 +51,18 @@ 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))
{
return true;
}
}
else
{
std::cerr << '\0';
}
return false;
}

Expand All @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion nano/node/scheduler/hinted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <nano/lib/locks.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/node/election_insertion_result.hpp>
#include <nano/secure/common.hpp>

#include <condition_variable>
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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<nano::scheduler::limiter> limiter;
nano::online_reps & online_reps;
nano::stats & stats;

Expand Down

0 comments on commit b7fc721

Please sign in to comment.