Skip to content

Commit

Permalink
Use online weight for representative tier calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 8, 2024
1 parent 3626dbf commit 83d0962
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
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 ();
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

0 comments on commit 83d0962

Please sign in to comment.