diff --git a/nano/core_test/rep_crawler.cpp b/nano/core_test/rep_crawler.cpp index e9d0ba8d41..18ee676fbb 100644 --- a/nano/core_test/rep_crawler.cpp +++ b/nano/core_test/rep_crawler.cpp @@ -128,53 +128,56 @@ TEST (rep_crawler, rep_remove) nano::keypair keys_rep2; // Principal representative 2 nano::block_builder builder; + auto const rep_weight = nano::test::minimum_principal_weight () * 2; + // Send enough nanos to Rep1 to make it a principal representative - std::shared_ptr send_to_rep1 = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - searching_node.minimum_principal_weight () * 2) - .link (keys_rep1.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*system.work.generate (nano::dev::genesis->hash ())) - .build (); + auto send_to_rep1 = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (nano::dev::genesis->hash ()) + .representative (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount - rep_weight) + .link (keys_rep1.pub) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*system.work.generate (nano::dev::genesis->hash ())) + .build (); // Receive by Rep1 - std::shared_ptr receive_rep1 = builder - .state () - .account (keys_rep1.pub) - .previous (0) - .representative (keys_rep1.pub) - .balance (searching_node.minimum_principal_weight () * 2) - .link (send_to_rep1->hash ()) - .sign (keys_rep1.prv, keys_rep1.pub) - .work (*system.work.generate (keys_rep1.pub)) - .build (); + auto receive_rep1 = builder + .state () + .account (keys_rep1.pub) + .previous (0) + .representative (keys_rep1.pub) + .balance (rep_weight) + .link (send_to_rep1->hash ()) + .sign (keys_rep1.prv, keys_rep1.pub) + .work (*system.work.generate (keys_rep1.pub)) + .build (); // Send enough nanos to Rep2 to make it a principal representative - std::shared_ptr send_to_rep2 = builder - .state () - .account (nano::dev::genesis_key.pub) - .previous (send_to_rep1->hash ()) - .representative (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - searching_node.minimum_principal_weight () * 4) - .link (keys_rep2.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*system.work.generate (send_to_rep1->hash ())) - .build (); + auto send_to_rep2 = builder + .state () + .account (nano::dev::genesis_key.pub) + .previous (send_to_rep1->hash ()) + .representative (nano::dev::genesis_key.pub) + .balance (nano::dev::constants.genesis_amount - rep_weight * 2) + .link (keys_rep2.pub) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*system.work.generate (send_to_rep1->hash ())) + .build (); // Receive by Rep2 - std::shared_ptr receive_rep2 = builder - .state () - .account (keys_rep2.pub) - .previous (0) - .representative (keys_rep2.pub) - .balance (searching_node.minimum_principal_weight () * 2) - .link (send_to_rep2->hash ()) - .sign (keys_rep2.prv, keys_rep2.pub) - .work (*system.work.generate (keys_rep2.pub)) - .build (); + auto receive_rep2 = builder + .state () + .account (keys_rep2.pub) + .previous (0) + .representative (keys_rep2.pub) + .balance (rep_weight) + .link (send_to_rep2->hash ()) + .sign (keys_rep2.prv, keys_rep2.pub) + .work (*system.work.generate (keys_rep2.pub)) + .build (); + { auto transaction = searching_node.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, searching_node.ledger.process (transaction, send_to_rep1)); @@ -188,11 +191,12 @@ TEST (rep_crawler, rep_remove) // Ensure Rep1 is found by the rep_crawler after receiving a vote from it auto vote_rep1 = std::make_shared (keys_rep1.pub, keys_rep1.prv, 0, 0, std::vector{ nano::dev::genesis->hash () }); + ASSERT_LE (searching_node.minimum_principal_weight (), rep_weight); searching_node.rep_crawler.force_process (vote_rep1, channel_rep1); ASSERT_TIMELY_EQ (5s, searching_node.rep_crawler.representative_count (), 1); auto reps (searching_node.rep_crawler.representatives (1)); ASSERT_EQ (1, reps.size ()); - ASSERT_EQ (searching_node.minimum_principal_weight () * 2, searching_node.ledger.weight (reps[0].account)); + ASSERT_LE (searching_node.minimum_principal_weight (), searching_node.ledger.weight (reps[0].account)); ASSERT_EQ (keys_rep1.pub, reps[0].account); ASSERT_EQ (channel_rep1, reps[0].channel); diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index 797077cc6d..8f93ab726e 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.cpp @@ -114,7 +114,7 @@ TEST (vote_processor, weights) auto & node (*system.nodes[0]); // Create representatives of different weight levels - auto const stake = node.balance (nano::dev::genesis_key.pub); + auto const stake = node.config.online_weight_minimum.number (); auto const level0 = stake / 5000; // 0.02% auto const level1 = stake / 500; // 0.2% auto const level2 = stake / 50; // 2% diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index d0af99712b..d04a1d0e2d 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -83,7 +83,8 @@ void nano::rep_crawler::validate_and_process (nano::unique_lock & l if (channel->get_type () == nano::transport::transport_type::loopback) { logger.debug (nano::log::type::rep_crawler, "Ignoring vote from loopback channel: {}", channel->to_string ()); - continue; + + continue; // Skip this vote } nano::uint128_t const rep_weight = node.ledger.weight (vote->account); @@ -91,8 +92,9 @@ void nano::rep_crawler::validate_and_process (nano::unique_lock & l { logger.debug (nano::log::type::rep_crawler, "Ignoring vote from account: {} with too little voting weight: {}", vote->account.to_account (), - nano::util::to_str (rep_weight)); - continue; + fmt::streamed (rep_weight)); + + continue; // Skip this vote } // temporary data used for logging after dropping the lock diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index 75a72baae3..a3400f9b9f 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -387,3 +387,8 @@ std::vector> nano::test::all_blocks (nano::node & n } return result; } + +nano::uint128_t nano::test::minimum_principal_weight () +{ + return nano::dev::genesis->balance ().number () / nano::dev::network_params.network.principal_weight_factor; +} diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index 6b23c12d8c..1964af057b 100644 --- a/nano/test_common/testutil.hpp +++ b/nano/test_common/testutil.hpp @@ -432,5 +432,7 @@ namespace test * Returns all blocks in the ledger */ std::vector> all_blocks (nano::node &); + + nano::uint128_t minimum_principal_weight (); } }