Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fair queuing for vote processor #4536

Merged
12 changes: 5 additions & 7 deletions nano/node/vote_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ nano::vote_processor::vote_processor (nano::active_transactions & active_a, nano
rep_crawler{ rep_crawler_a },
ledger{ ledger_a },
network_params{ network_params_a },
rep_tiers{ rep_tiers_a },
max_votes{ flags_a.vote_processor_capacity }
rep_tiers{ rep_tiers_a }
{
queue.max_size_query = [this] (auto const & origin) {
switch (origin.source)
{
case nano::rep_tier::tier_3:
case nano::rep_tier::tier_2:
case nano::rep_tier::tier_1:
return 512;
return 256;
case nano::rep_tier::none:
return 32;
}
Expand Down Expand Up @@ -96,7 +95,7 @@ bool nano::vote_processor::vote (std::shared_ptr<nano::vote> const & vote, std::
bool added = false;
{
nano::lock_guard<nano::mutex> guard{ mutex };
added = queue.push ({ vote, channel }, tier);
added = queue.push (vote, { tier, channel });
}
if (added)
{
Expand Down Expand Up @@ -147,10 +146,9 @@ void nano::vote_processor::run_batch (nano::unique_lock<nano::mutex> & lock)

lock.unlock ();

for (auto const & [entry, origin] : batch)
for (auto const & [vote, origin] : batch)
{
auto const & [vote, channel] = entry;
vote_blocking (vote, channel);
vote_blocking (vote, origin.channel);
}

total_processed += batch.size ();
Expand Down
5 changes: 1 addition & 4 deletions nano/node/vote_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ class vote_processor final
void run_batch (nano::unique_lock<nano::mutex> &);

private:
std::size_t const max_votes;

using entry_t = std::pair<std::shared_ptr<nano::vote>, std::shared_ptr<nano::transport::channel>>;
nano::fair_queue<entry_t, nano::rep_tier> queue;
nano::fair_queue<std::shared_ptr<nano::vote>, nano::rep_tier> queue;

private:
bool stopped{ false };
Expand Down
Loading