Skip to content

Commit

Permalink
Rep crawler should track local representatives (#4858)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev authored Mar 6, 2025
1 parent 2c7c736 commit 50a7e30
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
24 changes: 12 additions & 12 deletions nano/core_test/rep_crawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<nano::transport::inproc::channel> (node, node);
auto vote = std::make_shared<nano::vote> (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)
{
Expand Down
7 changes: 0 additions & 7 deletions nano/node/repcrawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ void nano::rep_crawler::validate_and_process (nano::unique_lock<nano::mutex> & 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)
{
Expand Down
4 changes: 1 addition & 3 deletions nano/node/repcrawler.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <nano/lib/locks.hpp>
#include <nano/node/fwd.hpp>
#include <nano/node/transport/channel.hpp>
#include <nano/node/transport/transport.hpp>

Expand All @@ -23,9 +24,6 @@ namespace mi = boost::multi_index;

namespace nano
{
class node;
class active_elections;

struct representative
{
nano::account account;
Expand Down

0 comments on commit 50a7e30

Please sign in to comment.