Skip to content

Commit

Permalink
Lookup channels by node id instead of endpoints in test code
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Aug 21, 2022
1 parent 2d0013d commit a862b51
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 41 deletions.
2 changes: 1 addition & 1 deletion nano/core_test/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ TEST (election, quorum_minimum_update_weight_before_quorum_checks)
auto const vote1 = std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_max, nano::vote::duration_max, std::vector<nano::block_hash>{ send1->hash () });
ASSERT_EQ (nano::vote_code::vote, node1.active.vote (vote1));

auto channel = node1.network.find_channel (node2.network.endpoint ());
auto channel = node1.network.find_node_id (node2.get_node_id ());
ASSERT_NE (channel, nullptr);

auto const vote2 = std::make_shared<nano::vote> (key1.pub, key1.prv, nano::vote::timestamp_max, nano::vote::duration_max, std::vector<nano::block_hash>{ send1->hash () });
Expand Down
21 changes: 11 additions & 10 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ TEST (network, send_node_id_handshake_tcp)
ASSERT_EQ (1, node1->network.size ());
auto list1 (node0->network.list (1));
ASSERT_EQ (nano::transport::transport_type::tcp, list1[0]->get_type ());
ASSERT_EQ (node1->network.endpoint (), list1[0]->get_endpoint ());
ASSERT_EQ (node1->get_node_id (), list1[0]->get_node_id ());
auto list2 (node1->network.list (1));
ASSERT_EQ (nano::transport::transport_type::tcp, list2[0]->get_type ());
ASSERT_EQ (node0->network.endpoint (), list2[0]->get_endpoint ());
ASSERT_EQ (node0->get_node_id (), list2[0]->get_node_id ());
node1->stop ();
}

Expand Down Expand Up @@ -384,7 +384,8 @@ TEST (network, send_insufficient_work)
.work (0)
.build_shared ();
nano::publish publish1{ nano::dev::network_params.network, block1 };
auto tcp_channel (node1.network.tcp_channels.find_channel (nano::transport::map_endpoint_to_tcp (node2.network.endpoint ())));
auto tcp_channel (node1.network.tcp_channels.find_node_id (node2.get_node_id ()));
ASSERT_NE (nullptr, tcp_channel);
tcp_channel->send (publish1, [] (boost::system::error_code const & ec, size_t size) {});
ASSERT_EQ (0, node1.stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work));
ASSERT_TIMELY (10s, node2.stats.count (nano::stat::type::error, nano::stat::detail::insufficient_work) != 0);
Expand Down Expand Up @@ -1073,7 +1074,8 @@ TEST (network, duplicate_detection)
ASSERT_TIMELY (2s, node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_publish) == 1);

// Publish duplicate detection through TCP
auto tcp_channel (node0.network.tcp_channels.find_channel (nano::transport::map_endpoint_to_tcp (node1.network.endpoint ())));
auto tcp_channel (node0.network.tcp_channels.find_node_id (node1.get_node_id ()));
ASSERT_NE (nullptr, tcp_channel);
ASSERT_EQ (1, node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_publish));
tcp_channel->send (publish);
ASSERT_TIMELY (2s, node1.stats.count (nano::stat::type::filter, nano::stat::detail::duplicate_publish) == 2);
Expand Down Expand Up @@ -1221,19 +1223,18 @@ TEST (network, tcp_no_connect_excluded_peers)
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::test::get_available_port (), nano::unique_path (), system.logging, system.work));
node1->start ();
system.nodes.push_back (node1);
auto endpoint1 (node1->network.endpoint ());
auto endpoint1_tcp (nano::transport::map_endpoint_to_tcp (endpoint1));
auto endpoint1_tcp (nano::transport::map_endpoint_to_tcp (node1->network.endpoint ()));
while (!node0->network.excluded_peers.check (endpoint1_tcp))
{
node0->network.excluded_peers.add (endpoint1_tcp, 1);
}
ASSERT_EQ (0, node0->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_excluded));
node1->network.merge_peer (node0->network.endpoint ());
ASSERT_TIMELY (5s, node0->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_excluded) >= 1);
ASSERT_EQ (nullptr, node0->network.find_channel (endpoint1));
ASSERT_EQ (nullptr, node0->network.find_node_id (node1->get_node_id ()));

// Should not actively reachout to excluded peers
ASSERT_TRUE (node0->network.reachout (endpoint1, true));
ASSERT_TRUE (node0->network.reachout (node1->network.endpoint (), true));

// Erasing from excluded peers should allow a connection
node0->network.excluded_peers.remove (endpoint1_tcp);
Expand Down Expand Up @@ -1374,7 +1375,7 @@ TEST (network, filter_invalid_network_bytes)
auto & node2 = *system.nodes[1];

// find the comms channel that goes from node2 to node1
auto channel = node2.network.find_channel (node1.network.endpoint ());
auto channel = node2.network.find_node_id (node1.get_node_id ());
ASSERT_NE (nullptr, channel);

// send a keepalive, from node2 to node1, with the wrong network bytes
Expand All @@ -1393,7 +1394,7 @@ TEST (network, filter_invalid_version_using)
auto & node2 = *system.nodes[1];

// find the comms channel that goes from node2 to node1
auto channel = node2.network.find_channel (node1.network.endpoint ());
auto channel = node2.network.find_node_id (node1.get_node_id ());
ASSERT_NE (nullptr, channel);

// send a keepalive, from node2 to node1, with the wrong version_using
Expand Down
23 changes: 12 additions & 11 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ TEST (node, auto_bootstrap_reverse)
system.wallet (0)->insert_adhoc (key2.prv);
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::test::get_available_port (), nano::unique_path (), system.logging, system.work, node_flags));
ASSERT_FALSE (node1->init_error ());
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, node0->config.receive_minimum.number ()));
node1->start ();
system.nodes.push_back (node1);
ASSERT_NE (nullptr, nano::test::establish_tcp (system, *node0, node1->network.endpoint ()));
Expand Down Expand Up @@ -652,13 +651,13 @@ TEST (node_flags, disable_udp)
// Send TCP handshake
node1->network.merge_peer (node2->network.endpoint ());
ASSERT_TIMELY (5s, node1->bootstrap.realtime_count == 1 && node2->bootstrap.realtime_count == 1);
ASSERT_EQ (1, node1->network.size ());
ASSERT_TIMELY (5s, 1 == node1->network.size ());
auto list1 (node1->network.list (2));
ASSERT_EQ (node2->network.endpoint (), list1[0]->get_endpoint ());
ASSERT_EQ (node2->get_node_id (), list1[0]->get_node_id ());
ASSERT_EQ (nano::transport::transport_type::tcp, list1[0]->get_type ());
ASSERT_EQ (1, node2->network.size ());
ASSERT_TIMELY (5s, 1 == node2->network.size ());
auto list2 (node2->network.list (2));
ASSERT_EQ (node1->network.endpoint (), list2[0]->get_endpoint ());
ASSERT_EQ (node1->get_node_id (), list2[0]->get_node_id ());
ASSERT_EQ (nano::transport::transport_type::tcp, list2[0]->get_type ());
node2->stop ();
}
Expand Down Expand Up @@ -1945,7 +1944,7 @@ TEST (node, rep_remove)
// Add working representative
auto node1 = system.add_node (nano::node_config (nano::test::get_available_port (), system.logging));
system.wallet (1)->insert_adhoc (nano::dev::genesis_key.prv);
auto channel1 (node.network.find_channel (node1->network.endpoint ()));
auto channel1 (node.network.find_node_id (node1->get_node_id ()));
ASSERT_NE (nullptr, channel1);
auto vote2 = std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash>{ nano::dev::genesis->hash () });
node.rep_crawler.response (channel1, vote2);
Expand All @@ -1956,7 +1955,7 @@ TEST (node, rep_remove)
auto vote3 = std::make_shared<nano::vote> (keypair2.pub, keypair2.prv, 0, 0, std::vector<nano::block_hash>{ nano::dev::genesis->hash () });
node.network.tcp_channels.start_tcp (node2->network.endpoint ());
std::shared_ptr<nano::transport::channel> channel2;
ASSERT_TIMELY (10s, (channel2 = node.network.tcp_channels.find_channel (nano::transport::map_endpoint_to_tcp (node2->network.endpoint ()))) != nullptr);
ASSERT_TIMELY (10s, (channel2 = node.network.tcp_channels.find_node_id (node2->get_node_id ())) != nullptr);
ASSERT_FALSE (node.rep_crawler.response (channel2, vote3));
ASSERT_TIMELY (10s, node.rep_crawler.representative_count () == 2);
node2->stop ();
Expand All @@ -1965,7 +1964,7 @@ TEST (node, rep_remove)
ASSERT_EQ (nano::dev::genesis_key.pub, reps[0].account);
ASSERT_EQ (1, node.network.size ());
auto list (node.network.list (1));
ASSERT_EQ (node1->network.endpoint (), list[0]->get_endpoint ());
ASSERT_EQ (node1->get_node_id (), list[0]->get_node_id ());
}

TEST (node, rep_connection_close)
Expand Down Expand Up @@ -3240,12 +3239,14 @@ TEST (node, peers)
// Confirm that the peers match with the endpoints we are expecting
ASSERT_EQ (1, node1->network.size ());
auto list1 (node1->network.list (2));
ASSERT_EQ (node2->network.endpoint (), list1[0]->get_endpoint ());
ASSERT_EQ (node2->get_node_id (), list1[0]->get_node_id ());
ASSERT_EQ (nano::transport::transport_type::tcp, list1[0]->get_type ());
ASSERT_EQ (1, node2->network.size ());
auto list2 (node2->network.list (2));
ASSERT_EQ (node1->network.endpoint (), list2[0]->get_endpoint ());
ASSERT_EQ (node1->get_node_id (), list2[0]->get_node_id ());
ASSERT_EQ (nano::transport::transport_type::tcp, list2[0]->get_type ());
// Trigger storing current peers in database
node2->ongoing_peer_store ();
// Stop the peer node and check that it is removed from the store
node1->stop ();

Expand Down Expand Up @@ -4295,7 +4296,7 @@ TEST (rep_crawler, recently_confirmed)
node1.active.recently_confirmed.put (block->qualified_root (), block->hash ());
auto & node2 (*system.add_node ());
system.wallet (1)->insert_adhoc (nano::dev::genesis_key.prv);
auto channel = node1.network.find_channel (node2.network.endpoint ());
auto channel = node1.network.find_node_id (node2.get_node_id ());
ASSERT_NE (nullptr, channel);
node1.rep_crawler.query (channel);
ASSERT_TIMELY (3s, node1.rep_crawler.representative_count () == 1);
Expand Down
33 changes: 21 additions & 12 deletions nano/core_test/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,18 @@ TEST (telemetry, basic)
// Request telemetry metrics
nano::telemetry_data telemetry_data;
auto server_endpoint = node_server->network.endpoint ();
auto channel = node_client->network.find_channel (node_server->network.endpoint ());
auto channel = node_client->network.find_node_id (node_server->get_node_id ());
ASSERT_NE (nullptr, channel);
{
std::atomic<bool> done{ false };
node_client->telemetry->get_metrics_single_peer_async (channel, [&done, &server_endpoint, &telemetry_data] (nano::telemetry_data_response const & response_a) {
ASSERT_FALSE (response_a.error);
ASSERT_EQ (server_endpoint, response_a.endpoint);
telemetry_data = response_a.telemetry_data;
done = true;
});

ASSERT_TIMELY (10s, done);
ASSERT_EQ (node_server->get_node_id (), telemetry_data.node_id);
}

// Check the metrics are correct
Expand Down Expand Up @@ -354,7 +355,8 @@ TEST (telemetry, over_udp)
nano::test::wait_peer_connections (system);

std::atomic<bool> done{ false };
auto channel = node_client->network.find_channel (node_server->network.endpoint ());
auto channel = node_client->network.find_node_id (node_server->get_node_id ());
ASSERT_NE (nullptr, channel);
node_client->telemetry->get_metrics_single_peer_async (channel, [&done, &node_server] (nano::telemetry_data_response const & response_a) {
ASSERT_FALSE (response_a.error);
nano::test::compare_default_telemetry_response_data (response_a.telemetry_data, node_server->network_params, node_server->config.bandwidth_limit, node_server->default_difficulty (nano::work_version::work_1), node_server->node_id);
Expand Down Expand Up @@ -420,7 +422,9 @@ TEST (telemetry, blocking_request)
node_client->workers.push_task (call_system_poll);

// Now try single request metric
auto telemetry_data_response = node_client->telemetry->get_metrics_single_peer (node_client->network.find_channel (node_server->network.endpoint ()));
auto channel = node_client->network.find_node_id (node_server->get_node_id ());
ASSERT_NE (nullptr, channel);
auto telemetry_data_response = node_client->telemetry->get_metrics_single_peer (channel);
ASSERT_FALSE (telemetry_data_response.error);
nano::test::compare_default_telemetry_response_data (telemetry_data_response.telemetry_data, node_server->network_params, node_server->config.bandwidth_limit, node_server->default_difficulty (nano::work_version::work_1), node_server->node_id);

Expand All @@ -439,7 +443,8 @@ TEST (telemetry, disconnects)
nano::test::wait_peer_connections (system);

// Try and request metrics from a node which is turned off but a channel is not closed yet
auto channel = node_client->network.find_channel (node_server->network.endpoint ());
auto channel = node_client->network.find_node_id (node_server->get_node_id ());
ASSERT_NE (nullptr, channel);
node_server->stop ();
ASSERT_TRUE (channel);

Expand All @@ -465,7 +470,8 @@ TEST (telemetry, dos_tcp)
nano::test::wait_peer_connections (system);

nano::telemetry_req message{ nano::dev::network_params.network };
auto channel = node_client->network.tcp_channels.find_channel (nano::transport::map_endpoint_to_tcp (node_server->network.endpoint ()));
auto channel = node_client->network.tcp_channels.find_node_id (node_server->get_node_id ());
ASSERT_NE (nullptr, channel);
channel->send (message, [] (boost::system::error_code const & ec, size_t size_a) {
ASSERT_FALSE (ec);
});
Expand Down Expand Up @@ -549,8 +555,8 @@ TEST (telemetry, disable_metrics)
nano::test::wait_peer_connections (system);

// Try and request metrics from a node which is turned off but a channel is not closed yet
auto channel = node_client->network.find_channel (node_server->network.endpoint ());
ASSERT_TRUE (channel);
auto channel = node_client->network.find_node_id (node_server->get_node_id ());
ASSERT_NE (nullptr, channel);

std::atomic<bool> done{ false };
node_client->telemetry->get_metrics_single_peer_async (channel, [&done] (nano::telemetry_data_response const & response_a) {
Expand All @@ -562,7 +568,8 @@ TEST (telemetry, disable_metrics)

// It should still be able to receive metrics though
done = false;
auto channel1 = node_server->network.find_channel (node_client->network.endpoint ());
auto channel1 = node_server->network.find_node_id (node_client->get_node_id ());
ASSERT_NE (nullptr, channel1);
node_server->telemetry->get_metrics_single_peer_async (channel1, [&done, node_client] (nano::telemetry_data_response const & response_a) {
ASSERT_FALSE (response_a.error);
nano::test::compare_default_telemetry_response_data (response_a.telemetry_data, node_client->network_params, node_client->config.bandwidth_limit, node_client->default_difficulty (nano::work_version::work_1), node_client->node_id);
Expand All @@ -587,7 +594,8 @@ TEST (telemetry, max_possible_size)
nano::telemetry_ack message{ nano::dev::network_params.network, data };
nano::test::wait_peer_connections (system);

auto channel = node_client->network.tcp_channels.find_channel (nano::transport::map_endpoint_to_tcp (node_server->network.endpoint ()));
auto channel = node_client->network.tcp_channels.find_node_id (node_server->get_node_id ());
ASSERT_NE (nullptr, channel);
channel->send (message, [] (boost::system::error_code const & ec, size_t size_a) {
ASSERT_FALSE (ec);
});
Expand Down Expand Up @@ -717,17 +725,18 @@ TEST (telemetry, maker_pruning)
// Request telemetry metrics
nano::telemetry_data telemetry_data;
auto server_endpoint = node_server->network.endpoint ();
auto channel = node_client->network.find_channel (node_server->network.endpoint ());
auto channel = node_client->network.find_node_id (node_server->get_node_id ());
ASSERT_NE (nullptr, channel);
{
std::atomic<bool> done{ false };
node_client->telemetry->get_metrics_single_peer_async (channel, [&done, &server_endpoint, &telemetry_data] (nano::telemetry_data_response const & response_a) {
ASSERT_FALSE (response_a.error);
ASSERT_EQ (server_endpoint, response_a.endpoint);
telemetry_data = response_a.telemetry_data;
done = true;
});

ASSERT_TIMELY (10s, done);
ASSERT_EQ (node_server->get_node_id (), telemetry_data.node_id);
}

ASSERT_EQ (nano::telemetry_maker::nf_pruned_node, static_cast<nano::telemetry_maker> (telemetry_data.maker));
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ TEST (websocket, telemetry)

ASSERT_TIMELY (10s, done);

node1->telemetry->get_metrics_single_peer_async (node1->network.find_channel (node2->network.endpoint ()), [] (auto const & response_a) {
node1->telemetry->get_metrics_single_peer_async (node1->network.find_node_id (node2->get_node_id ()), [] (auto const & response_a) {
ASSERT_FALSE (response_a.error);
});

Expand Down
4 changes: 2 additions & 2 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ TEST (rpc, keepalive)
ASSERT_EQ (0, node0->network.size ());
auto response (wait_response (system, rpc_ctx, request));
system.deadline_set (10s);
while (node0->network.find_channel (node1->network.endpoint ()) == nullptr)
while (node0->network.find_node_id (node1->get_node_id ()) == nullptr)
{
ASSERT_EQ (0, node0->network.size ());
ASSERT_NO_ERROR (system.poll ());
Expand Down Expand Up @@ -7386,7 +7386,7 @@ TEST (rpc, telemetry_all)
// First need to set up the cached data
std::atomic<bool> done{ false };
auto node = system.nodes.front ();
node1->telemetry->get_metrics_single_peer_async (node1->network.find_channel (node->network.endpoint ()), [&done] (nano::telemetry_data_response const & telemetry_data_response_a) {
node1->telemetry->get_metrics_single_peer_async (node1->network.find_node_id (node->get_node_id ()), [&done] (nano::telemetry_data_response const & telemetry_data_response_a) {
ASSERT_FALSE (telemetry_data_response_a.error);
done = true;
});
Expand Down
8 changes: 4 additions & 4 deletions nano/slow_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ TEST (confirmation_height, dynamic_algorithm)
* of blocks uncemented is > unbounded_cutoff so that it hits the bounded processor), the main `run` loop on the conf height processor is iterated.
*
* This cause unbounded pending entries not to be written, and then the bounded processor would write them, causing some inconsistencies.
*/
*/
TEST (confirmation_height, dynamic_algorithm_no_transition_while_pending)
{
// Repeat in case of intermittent issues not replicating the issue talked about above.
Expand Down Expand Up @@ -1596,7 +1596,7 @@ TEST (telemetry, cache_read_and_timeout)
nano::telemetry_data telemetry_data;
{
std::atomic<bool> done{ false };
auto channel = node_client->network.find_channel (node_server->network.endpoint ());
auto channel = node_client->network.find_node_id (node_server->get_node_id ());
node_client->telemetry->get_metrics_single_peer_async (channel, [&done, &telemetry_data] (nano::telemetry_data_response const & response_a) {
telemetry_data = response_a.telemetry_data;
done = true;
Expand Down Expand Up @@ -1626,7 +1626,7 @@ TEST (telemetry, cache_read_and_timeout)
// Request telemetry metrics again
{
std::atomic<bool> done{ false };
auto channel = node_client->network.find_channel (node_server->network.endpoint ());
auto channel = node_client->network.find_node_id (node_server->get_node_id ());
node_client->telemetry->get_metrics_single_peer_async (channel, [&done, &telemetry_data] (nano::telemetry_data_response const & response_a) {
telemetry_data = response_a.telemetry_data;
done = true;
Expand Down Expand Up @@ -1846,7 +1846,7 @@ TEST (node, mass_epoch_upgrader)
nano::test::system system;
nano::node_config node_config (nano::test::get_available_port (), system.logging);
node_config.work_threads = 4;
//node_config.work_peers = { { "192.168.1.101", 7000 } };
// node_config.work_peers = { { "192.168.1.101", 7000 } };
auto & node = *system.add_node (node_config);

auto balance = node.balance (nano::dev::genesis_key.pub);
Expand Down

0 comments on commit a862b51

Please sign in to comment.