From d4a34511203d55620c7529a8eb0c818d18fb418f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 7 Mar 2024 20:11:41 +0100 Subject: [PATCH] Vote processor tiers --- nano/node/vote_processor.cpp | 26 +++++++++++++++++++++++--- nano/node/vote_processor.hpp | 23 +++++++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/nano/node/vote_processor.cpp b/nano/node/vote_processor.cpp index 9c094abf45..654c126b94 100644 --- a/nano/node/vote_processor.cpp +++ b/nano/node/vote_processor.cpp @@ -104,6 +104,23 @@ 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 const & vote_a, std::shared_ptr const & channel_a) { debug_assert (channel_a != nullptr); @@ -111,6 +128,8 @@ bool nano::vote_processor::vote (std::shared_ptr const & vote_a, std nano::unique_lock lock{ mutex }; if (!stopped) { + auto tier = representative_tier (vote_a->account); + // Level 0 (< 0.1%) if (votes.size () < 6.0 / 9.0 * max_votes) { @@ -119,17 +138,17 @@ bool nano::vote_processor::vote (std::shared_ptr 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) { @@ -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) diff --git a/nano/node/vote_processor.hpp b/nano/node/vote_processor.hpp index 4591c5ee71..be5e356f19 100644 --- a/nano/node/vote_processor.hpp +++ b/nano/node/vote_processor.hpp @@ -11,7 +11,6 @@ namespace nano { -class signature_checker; class active_transactions; namespace store { @@ -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 (); @@ -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::shared_ptr>> votes; - /** Representatives levels for random early detection */ + /** Representatives levels for early prioritization */ std::unordered_set representatives_1; std::unordered_set representatives_2; std::unordered_set representatives_3;