From 50a7e3086708ee805857e7ef65909c64db1f54fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 6 Mar 2025 18:15:06 +0100 Subject: [PATCH] Rep crawler should track local representatives (#4858) --- nano/core_test/rep_crawler.cpp | 24 ++++++++++++------------ nano/node/repcrawler.cpp | 7 ------- nano/node/repcrawler.hpp | 4 +--- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/nano/core_test/rep_crawler.cpp b/nano/core_test/rep_crawler.cpp index 2977f3bfca..dc1aecdd29 100644 --- a/nano/core_test/rep_crawler.cpp +++ b/nano/core_test/rep_crawler.cpp @@ -250,6 +250,18 @@ TEST (rep_crawler, rep_connection_close) ASSERT_TIMELY_EQ (10s, node1.rep_crawler.representative_count (), 0); } +TEST (rep_crawler, rep_local) +{ + nano::test::system system; + auto & node = *system.add_node (); + ASSERT_EQ (0, node.online_reps.online ()); + system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); + ASSERT_TIMELY_EQ (5s, node.rep_crawler.representative_count (), 1); + auto reps = node.rep_crawler.representatives (); + ASSERT_EQ (1, reps.size ()); + ASSERT_EQ (nano::dev::genesis_key.pub, reps[0].account); +} + // This test checks that if a block is in the recently_confirmed list then the repcrawler will not send a request for it. // The behaviour of this test previously was the opposite, that the repcrawler eventually send out such a block and deleted the block // from the recently confirmed list to try to make ammends for sending it, which is bad behaviour. @@ -270,18 +282,6 @@ TEST (rep_crawler, DISABLED_recently_confirmed) ASSERT_ALWAYS_EQ (0.5s, node1.rep_crawler.representative_count (), 0); } -// Votes from local channels should be ignored -TEST (rep_crawler, ignore_local) -{ - nano::test::system system; - nano::node_flags flags; - auto & node = *system.add_node (flags); - auto loopback = std::make_shared (node, node); - auto vote = std::make_shared (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector{ nano::dev::genesis->hash () }); - node.rep_crawler.force_process (vote, loopback); - ASSERT_ALWAYS_EQ (0.5s, node.rep_crawler.representative_count (), 0); -} - // Test that nodes can track PRs when multiple PRs are inside one node TEST (rep_crawler, two_reps_one_node) { diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index cdcc6bd5b6..5d92ab826b 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -86,13 +86,6 @@ void nano::rep_crawler::validate_and_process (nano::unique_lock & l release_assert (vote != nullptr); release_assert (channel != nullptr); - 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; // Skip this vote - } - nano::uint128_t const rep_weight = node.ledger.weight (vote->account); if (rep_weight < minimum) { diff --git a/nano/node/repcrawler.hpp b/nano/node/repcrawler.hpp index d9fd865bf1..2fc667ecc6 100644 --- a/nano/node/repcrawler.hpp +++ b/nano/node/repcrawler.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -23,9 +24,6 @@ namespace mi = boost::multi_index; namespace nano { -class node; -class active_elections; - struct representative { nano::account account;