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

Dedicated rep_tiers class #4471

Merged
merged 8 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions nano/core_test/vote_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ TEST (vote_processor, weights)
auto & node (*system.nodes[0]);

// Create representatives of different weight levels
// The online stake will be the minimum configurable due to online_reps sampling in tests
auto const online = node.config.online_weight_minimum.number ();
auto const level0 = online / 5000; // 0.02%
auto const level1 = online / 500; // 0.2%
auto const level2 = online / 50; // 2%
auto const total = nano::dev::constants.genesis_amount;
auto const level0 = total / 5000; // 0.02%
auto const level1 = total / 500; // 0.2%
auto const level2 = total / 50; // 2%

nano::keypair key0;
nano::keypair key1;
Expand All @@ -156,6 +155,7 @@ TEST (vote_processor, weights)

// Wait for representatives
ASSERT_TIMELY_EQ (10s, node.ledger.cache.rep_weights.get_rep_amounts ().size (), 4);
ASSERT_TIMELY_EQ (5s, node.online_reps.online (), total);
node.vote_processor.calculate_weights ();

ASSERT_EQ (node.vote_processor.representatives_1.end (), node.vote_processor.representatives_1.find (key0.pub));
Expand Down
42 changes: 24 additions & 18 deletions nano/node/vote_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,28 +241,34 @@ bool nano::vote_processor::empty () const
void nano::vote_processor::calculate_weights ()
{
nano::unique_lock<nano::mutex> lock{ mutex };
if (!stopped)

if (stopped)
{
return;
}

representatives_1.clear ();
representatives_2.clear ();
representatives_3.clear ();

auto online = online_reps.online ();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to change this from online_reps.trended (). Trended has hysteresis if the network is partitioned or the node is disconnected but online_reps.online doesn't, and might be 0 if the node is disconnected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, my goal was for it to be able to react to rep availability changes faster, but thinking about it now, trended makes more sense.

auto rep_amounts = ledger.cache.rep_weights.get_rep_amounts ();

for (auto const & rep_amount : rep_amounts)
{
representatives_1.clear ();
representatives_2.clear ();
representatives_3.clear ();
auto supply (online_reps.trended ());
auto rep_amounts = ledger.cache.rep_weights.get_rep_amounts ();
for (auto const & rep_amount : rep_amounts)
nano::account const & representative = rep_amount.first;

// Using ledger weight here because it takes preconfigured bootstrap weights into account
auto weight = ledger.weight (representative);
if (weight > online / 1000) // 0.1% or above (level 1)
{
// 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)
representatives_1.insert (representative);
if (weight > online / 100) // 1% or above (level 2)
{
representatives_1.insert (representative);
if (weight > supply / 100) // 1% or above (level 2)
representatives_2.insert (representative);
if (weight > online / 20) // 5% or above (level 3)
{
representatives_2.insert (representative);
if (weight > supply / 20) // 5% or above (level 3)
{
representatives_3.insert (representative);
}
representatives_3.insert (representative);
}
}
}
Expand Down