Skip to content

Commit

Permalink
Rename network.publish_filter to network.filter
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Sep 24, 2024
1 parent db90344 commit c9ee536
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
18 changes: 9 additions & 9 deletions nano/core_test/active_elections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,22 +649,22 @@ TEST (active_elections, dropped_cleanup)
nano::vectorstream stream (block_bytes);
chain[0]->serialize (stream);
}
ASSERT_FALSE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
ASSERT_FALSE (node.network.filter.apply (block_bytes.data (), block_bytes.size ()));
ASSERT_TRUE (node.network.filter.apply (block_bytes.data (), block_bytes.size ()));

auto election = nano::test::start_election (system, node, hash);
ASSERT_NE (nullptr, election);

// Not yet removed
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
ASSERT_TRUE (node.network.filter.apply (block_bytes.data (), block_bytes.size ()));
ASSERT_TRUE (node.vote_router.active (hash));

// Now simulate dropping the election
ASSERT_FALSE (election->confirmed ());
node.active.erase (*chain[0]);

// The filter must have been cleared
ASSERT_FALSE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
ASSERT_FALSE (node.network.filter.apply (block_bytes.data (), block_bytes.size ()));

// An election was recently dropped
ASSERT_EQ (1, node.stats.count (nano::stat::type::active_elections_dropped, nano::stat::detail::manual));
Expand All @@ -673,7 +673,7 @@ TEST (active_elections, dropped_cleanup)
ASSERT_FALSE (node.vote_router.active (hash));

// Repeat test for a confirmed election
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
ASSERT_TRUE (node.network.filter.apply (block_bytes.data (), block_bytes.size ()));

election = nano::test::start_election (system, node, hash);
ASSERT_NE (nullptr, election);
Expand All @@ -682,7 +682,7 @@ TEST (active_elections, dropped_cleanup)
node.active.erase (*chain[0]);

// The filter should not have been cleared
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
ASSERT_TRUE (node.network.filter.apply (block_bytes.data (), block_bytes.size ()));

// Not dropped
ASSERT_EQ (1, node.stats.count (nano::stat::type::active_elections_dropped, nano::stat::detail::manual));
Expand Down Expand Up @@ -825,7 +825,7 @@ TEST (active_elections, fork_filter_cleanup)
ASSERT_TIMELY_EQ (5s, node1.ledger.block_count (), 2);

// Block is erased from the duplicate filter
ASSERT_TIMELY (5s, node1.network.publish_filter.apply (send_block_bytes.data (), send_block_bytes.size ()));
ASSERT_TIMELY (5s, node1.network.filter.apply (send_block_bytes.data (), send_block_bytes.size ()));
}

/*
Expand Down Expand Up @@ -960,7 +960,7 @@ TEST (active_elections, fork_replacement_tally)
// Process correct block
node_config.peering_port = system.get_available_port ();
auto & node2 (*system.add_node (node_config));
node1.network.publish_filter.clear ();
node1.network.filter.clear ();
node2.network.flood_block (send_last);
ASSERT_TIMELY (3s, node1.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) > 0);

Expand All @@ -974,7 +974,7 @@ TEST (active_elections, fork_replacement_tally)
node1.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node1, node1));
// ensure vote arrives before the block
ASSERT_TIMELY_EQ (5s, 1, node1.vote_cache.find (send_last->hash ()).size ());
node1.network.publish_filter.clear ();
node1.network.filter.clear ();
node2.network.flood_block (send_last);
ASSERT_TIMELY (5s, node1.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) > 1);

Expand Down
16 changes: 8 additions & 8 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,19 +735,19 @@ TEST (network, duplicate_revert_publish)
// Should be cleared when dropping due to a full block processor, as long as the message has the optional digest attached
// Test network.duplicate_detection ensures that the digest is attached when deserializing messages
nano::uint128_t digest;
ASSERT_FALSE (node.network.publish_filter.apply (bytes.data (), bytes.size (), &digest));
ASSERT_TRUE (node.network.publish_filter.apply (bytes.data (), bytes.size ()));
ASSERT_FALSE (node.network.filter.apply (bytes.data (), bytes.size (), &digest));
ASSERT_TRUE (node.network.filter.apply (bytes.data (), bytes.size ()));
auto other_node (std::make_shared<nano::node> (system.io_ctx, system.get_available_port (), nano::unique_path (), system.work));
other_node->start ();
system.nodes.push_back (other_node);
auto channel = nano::test::establish_tcp (system, *other_node, node.network.endpoint ());
ASSERT_NE (nullptr, channel);
ASSERT_EQ (0, publish.digest);
node.network.inbound (publish, channel);
ASSERT_TRUE (node.network.publish_filter.apply (bytes.data (), bytes.size ()));
ASSERT_TRUE (node.network.filter.apply (bytes.data (), bytes.size ()));
publish.digest = digest;
node.network.inbound (publish, channel);
ASSERT_FALSE (node.network.publish_filter.apply (bytes.data (), bytes.size ()));
ASSERT_FALSE (node.network.filter.apply (bytes.data (), bytes.size ()));
}

TEST (network, duplicate_vote_detection)
Expand Down Expand Up @@ -798,14 +798,14 @@ TEST (network, duplicate_revert_vote)
// First vote should be processed
tcp_channel->send (message1);
ASSERT_ALWAYS_EQ (100ms, node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_confirm_ack_message), 0);
ASSERT_TIMELY (5s, node1.network.publish_filter.check (bytes1.data (), bytes1.size ()));
ASSERT_TIMELY (5s, node1.network.filter.check (bytes1.data (), bytes1.size ()));

// Second vote should get dropped from processor queue
tcp_channel->send (message2);
ASSERT_ALWAYS_EQ (100ms, node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_confirm_ack_message), 0);
// And the filter should not have it
WAIT (500ms); // Give the node time to process the vote
ASSERT_TIMELY (5s, !node1.network.publish_filter.check (bytes2.data (), bytes2.size ()));
ASSERT_TIMELY (5s, !node1.network.filter.check (bytes2.data (), bytes2.size ()));
}

TEST (network, expire_duplicate_filter)
Expand All @@ -832,8 +832,8 @@ TEST (network, expire_duplicate_filter)
ASSERT_TIMELY_EQ (2s, node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_confirm_ack_message), 1);

// The filter should expire the vote after some time
ASSERT_TRUE (node1.network.publish_filter.check (bytes.data (), bytes.size ()));
ASSERT_TIMELY (10s, !node1.network.publish_filter.check (bytes.data (), bytes.size ()));
ASSERT_TRUE (node1.network.filter.check (bytes.data (), bytes.size ()));
ASSERT_TIMELY (10s, !node1.network.filter.check (bytes.data (), bytes.size ()));
}

// The test must be completed in less than 1 second
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,7 @@ TEST (node, vote_by_hash_republish)
ASSERT_TIMELY (5s, node2.active.active (*send1));

// give block send2 to node1 and wait until the block is received and processed by node1
node1.network.publish_filter.clear ();
node1.network.filter.clear ();
node1.process_active (send2);
ASSERT_TIMELY (5s, node1.active.active (*send2));

Expand Down
2 changes: 1 addition & 1 deletion nano/fuzzer_test/fuzz_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void fuzz_message_parser (uint8_t const * Data, size_t Size)
}

fuzz_visitor visitor;
nano::message_parser parser (node0->network.publish_filter, node0->block_uniquer, node0->vote_uniquer, visitor, node0->work);
nano::message_parser parser (node0->network.filter, node0->block_uniquer, node0->vote_uniquer, visitor, node0->work);
parser.deserialize_buffer (Data, Size);
}

Expand Down
2 changes: 1 addition & 1 deletion nano/node/active_elections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void nano::active_elections::cleanup_election (nano::unique_lock<nano::mutex> &
if (!election->confirmed ())
{
// Clear from publish filter
node.network.publish_filter.clear (block);
node.network.filter.clear (block);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ bool nano::election::publish (std::shared_ptr<nano::block> const & block_a)
if (!replace_by_weight (lock, block_a->hash ()))
{
result = true;
node.network.publish_filter.clear (block_a);
node.network.filter.clear (block_a);
}
debug_assert (lock.owns_lock ());
}
Expand Down Expand Up @@ -643,7 +643,7 @@ void nano::election::remove_block (nano::block_hash const & hash_a)
return entry.second.hash == hash_a;
});

node.network.publish_filter.clear (existing->second);
node.network.filter.clear (existing->second);
last_blocks.erase (hash_a);
}
}
Expand Down
4 changes: 2 additions & 2 deletions nano/node/message_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class process_visitor : public nano::message_visitor
bool added = node.block_processor.add (message.block, message.is_originator () ? nano::block_source::live_originator : nano::block_source::live, channel);
if (!added)
{
node.network.publish_filter.clear (message.digest);
node.network.filter.clear (message.digest);
node.stats.inc (nano::stat::type::drop, nano::stat::detail::publish, nano::stat::dir::in);
}
}
Expand Down Expand Up @@ -220,7 +220,7 @@ class process_visitor : public nano::message_visitor
bool added = node.vote_processor.vote (message.vote, channel, message.is_rebroadcasted () ? nano::vote_source::rebroadcast : nano::vote_source::live);
if (!added)
{
node.network.publish_filter.clear (message.digest);
node.network.filter.clear (message.digest);
node.stats.inc (nano::stat::type::drop, nano::stat::detail::confirm_ack, nano::stat::dir::in);
}
}
Expand Down
4 changes: 2 additions & 2 deletions nano/node/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ nano::network::network (nano::node & node, uint16_t port) :
id{ nano::network_constants::active_network },
syn_cookies{ node.config.network.max_peers_per_ip, node.logger },
resolver{ node.io_ctx },
publish_filter{ node.config.network.duplicate_filter_size, node.config.network.duplicate_filter_cutoff },
filter{ node.config.network.duplicate_filter_size, node.config.network.duplicate_filter_cutoff },
tcp_channels{ node },
port{ port }
{
Expand Down Expand Up @@ -117,7 +117,7 @@ void nano::network::run_cleanup ()
auto const syn_cookie_cutoff = std::chrono::steady_clock::now () - node.network_params.network.syn_cookie_cutoff;
syn_cookies.purge (syn_cookie_cutoff);

publish_filter.update (interval.count ());
filter.update (interval.count ());

lock.lock ();
}
Expand Down
2 changes: 1 addition & 1 deletion nano/node/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class network final
nano::syn_cookies syn_cookies;
boost::asio::ip::tcp::resolver resolver;
nano::peer_exclusion excluded_peers;
nano::network_filter publish_filter;
nano::network_filter filter;
nano::transport::tcp_channels tcp_channels;
std::atomic<uint16_t> port{ 0 };

Expand Down
2 changes: 1 addition & 1 deletion nano/node/transport/inproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void nano::transport::inproc::channel::send_buffer (nano::shared_const_buffer co
callback_a (boost::system::errc::make_error_code (boost::system::errc::success), size_a);
};

auto const message_deserializer = std::make_shared<nano::transport::message_deserializer> (node.network_params.network, node.network.publish_filter, node.block_uniquer, node.vote_uniquer, buffer_read_fn);
auto const message_deserializer = std::make_shared<nano::transport::message_deserializer> (node.network_params.network, node.network.filter, node.block_uniquer, node.vote_uniquer, buffer_read_fn);
message_deserializer->read (
[this] (boost::system::error_code ec_a, std::unique_ptr<nano::message> message_a) {
if (ec_a || !message_a)
Expand Down
2 changes: 1 addition & 1 deletion nano/node/transport/tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ nano::transport::tcp_server::tcp_server (std::shared_ptr<nano::transport::tcp_so
node{ node_a },
allow_bootstrap{ allow_bootstrap_a },
message_deserializer{
std::make_shared<nano::transport::message_deserializer> (node_a->network_params.network, node_a->network.publish_filter, node_a->block_uniquer, node_a->vote_uniquer,
std::make_shared<nano::transport::message_deserializer> (node_a->network_params.network, node_a->network.filter, node_a->block_uniquer, node_a->vote_uniquer,
[socket_l = socket] (std::shared_ptr<std::vector<uint8_t>> const & data_a, size_t size_a, std::function<void (boost::system::error_code const &, std::size_t)> callback_a) {
debug_assert (socket_l != nullptr);
socket_l->read_impl (data_a, size_a, callback_a);
Expand Down

0 comments on commit c9ee536

Please sign in to comment.