Skip to content

Commit

Permalink
Vote processor tiers
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 7, 2024
1 parent 254aa88 commit d4a3451
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
26 changes: 23 additions & 3 deletions nano/node/vote_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,32 @@ void nano::vote_processor::run ()
}
}

auto nano::vote_processor::representative_tier (const nano::account & representative) const -> rep_tier
{
if (representatives_3.find (representative) != representatives_3.end ())
{
return rep_tier::tier_3;
}
if (representatives_2.find (representative) != representatives_2.end ())
{
return rep_tier::tier_2;
}
if (representatives_1.find (representative) != representatives_1.end ())
{
return rep_tier::tier_1;
}
return rep_tier::tier_none;
}

bool nano::vote_processor::vote (std::shared_ptr<nano::vote> const & vote_a, std::shared_ptr<nano::transport::channel> const & channel_a)
{
debug_assert (channel_a != nullptr);
bool process (false);
nano::unique_lock<nano::mutex> lock{ mutex };
if (!stopped)
{
auto tier = representative_tier (vote_a->account);

// Level 0 (< 0.1%)
if (votes.size () < 6.0 / 9.0 * max_votes)
{
Expand All @@ -119,17 +138,17 @@ bool nano::vote_processor::vote (std::shared_ptr<nano::vote> const & vote_a, std
// Level 1 (0.1-1%)
else if (votes.size () < 7.0 / 9.0 * max_votes)
{
process = (representatives_1.find (vote_a->account) != representatives_1.end ());
process = (tier == rep_tier::tier_1);
}
// Level 2 (1-5%)
else if (votes.size () < 8.0 / 9.0 * max_votes)
{
process = (representatives_2.find (vote_a->account) != representatives_2.end ());
process = (tier == rep_tier::tier_2);
}
// Level 3 (> 5%)
else if (votes.size () < max_votes)
{
process = (representatives_3.find (vote_a->account) != representatives_3.end ());
process = (tier == rep_tier::tier_3);
}
if (process)
{
Expand Down Expand Up @@ -236,6 +255,7 @@ void nano::vote_processor::calculate_weights ()
auto rep_amounts = ledger.cache.rep_weights.get_rep_amounts ();
for (auto const & rep_amount : rep_amounts)
{
// TODO: Base this calculation on online weight, not total supply
nano::account const & representative (rep_amount.first);
auto weight (ledger.weight (representative));
if (weight > supply / 1000) // 0.1% or above (level 1)
Expand Down
23 changes: 21 additions & 2 deletions nano/node/vote_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace nano
{
class signature_checker;
class active_transactions;
namespace store
{
Expand All @@ -35,6 +34,13 @@ namespace transport

class vote_processor final
{
public:
enum class vote_source
{
live,
cache,
};

public:
vote_processor (nano::active_transactions & active_a, nano::node_observers & observers_a, nano::stats & stats_a, nano::node_config & config_a, nano::node_flags & flags_a, nano::logger &, nano::online_reps & online_reps_a, nano::rep_crawler & rep_crawler_a, nano::ledger & ledger_a, nano::network_params & network_params_a);
~vote_processor ();
Expand Down Expand Up @@ -71,10 +77,23 @@ class vote_processor final
private:
void run ();

private:
// Higher number means higher priority
enum class rep_tier
{
tier_none, // Not a principal representative
tier_1, // (0.1-1%)
tier_2, // (1-5%)
tier_3, // (> 5%)
};

rep_tier representative_tier (nano::account const & representative) const;

private:
std::size_t const max_votes;
std::deque<std::pair<std::shared_ptr<nano::vote>, std::shared_ptr<nano::transport::channel>>> votes;

/** Representatives levels for random early detection */
/** Representatives levels for early prioritization */
std::unordered_set<nano::account> representatives_1;
std::unordered_set<nano::account> representatives_2;
std::unordered_set<nano::account> representatives_3;
Expand Down

0 comments on commit d4a3451

Please sign in to comment.