diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index 1da68596e8..f811ba9e4f 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.cpp @@ -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; @@ -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)); diff --git a/nano/node/vote_processor.cpp b/nano/node/vote_processor.cpp index d62186b0e8..5d3f061b0c 100644 --- a/nano/node/vote_processor.cpp +++ b/nano/node/vote_processor.cpp @@ -241,28 +241,34 @@ bool nano::vote_processor::empty () const void nano::vote_processor::calculate_weights () { nano::unique_lock 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); } } }