Skip to content

Commit

Permalink
Ensure limiter has space for at least 1 item.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Sep 5, 2023
1 parent 3ccec88 commit 2416631
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions nano/core_test/scheduler_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

TEST (scheduler_limiter, construction)
{
auto occupancy = std::make_shared<nano::scheduler::limiter> (nano::test::active_transactions_insert_null, 0, nano::election_behavior::normal);
ASSERT_EQ (0, occupancy->limit ());
ASSERT_FALSE (occupancy->available ());
auto occupancy = std::make_shared<nano::scheduler::limiter> (nano::test::active_transactions_insert_null, 1, nano::election_behavior::normal);
ASSERT_EQ (1, occupancy->limit ());
ASSERT_TRUE (occupancy->available ());
}

TEST (scheduler_limiter, limit)
Expand Down
4 changes: 3 additions & 1 deletion nano/node/scheduler/buckets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ nano::scheduler::buckets::buckets (insert_t const & insert, uint64_t maximum) :
minimums.push_back (uint128_t{ 1 } << 120);
for (auto i = 0u; i < minimums.size (); ++i)
{
auto limiter_l = std::make_shared<limiter> (insert, maximum / minimums.size (), nano::election_behavior::normal);
auto count = std::max<size_t> (maximum / minimums.size (), 1u);
debug_assert (count > 0);
auto limiter_l = std::make_shared<limiter> (insert, count, nano::election_behavior::normal);
buckets_m.emplace_back (limiter_l);
}
populate_schedule ();
Expand Down
2 changes: 1 addition & 1 deletion nano/node/scheduler/hinted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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 },
limiter{ std::make_shared<nano::scheduler::limiter> (node.active.insert_fn (), node.config.active_elections_hinted_limit_percentage * node.config.active_elections_size / 100, nano::election_behavior::hinted) },
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
1 change: 1 addition & 0 deletions nano/node/scheduler/limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ nano::scheduler::limiter::limiter (insert_t const & insert, size_t limit, nano::
limit_m{ limit },
behavior{ behavior }
{
debug_assert (limit > 0);
}

size_t nano::scheduler::limiter::limit () const
Expand Down
2 changes: 1 addition & 1 deletion nano/node/scheduler/optimistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nano::scheduler::optimistic::optimistic (optimistic_config const & config_a, nan
config{ config_a },
node{ node_a },
ledger{ ledger_a },
limiter{ std::make_shared<nano::scheduler::limiter> (node.active.insert_fn (), node.config.active_elections_optimistic_limit_percentage * node.config.active_elections_size / 100, nano::election_behavior::optimistic) },
limiter{ std::make_shared<nano::scheduler::limiter> (node.active.insert_fn (), std::max<size_t> (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 }
{
Expand Down

0 comments on commit 2416631

Please sign in to comment.