From 79512e6dcea0c219e50dc5fd64c72b45e28387f7 Mon Sep 17 00:00:00 2001 From: draoi Date: Thu, 1 Feb 2024 12:55:37 +0100 Subject: [PATCH] chore: fix debugs and cleanup --- src/net/hosts/refinery.rs | 7 +++++-- src/net/session/mod.rs | 3 ++- src/net/tests.rs | 24 ++++-------------------- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/net/hosts/refinery.rs b/src/net/hosts/refinery.rs index c786b0626..6309d42a9 100644 --- a/src/net/hosts/refinery.rs +++ b/src/net/hosts/refinery.rs @@ -164,11 +164,12 @@ async fn ping_node_impl(addr: Url, p2p: P2pPtr) -> bool { debug!(target: "net::refinery::ping_node()", "Attempting to connect to {}", addr); match connector.connect(&addr).await { - Ok((_url, channel)) => { - debug!(target: "net::refinery::ping_node()", "Connected successfully!"); + Ok((url, channel)) => { + debug!(target: "net::refinery::ping_node()", "Successfully created a channel with {}", url); // First initialize the version protocol and its Version, Verack subscribers. let proto_ver = ProtocolVersion::new(channel.clone(), p2p.settings()).await; + debug!(target: "net::refinery::ping_node()", "Performing handshake protocols with {}", url); // Then run the version exchange, store the channel and subscribe to a stop signal. let handshake_task = session_outbound.perform_handshake_protocols( proto_ver, @@ -176,6 +177,7 @@ async fn ping_node_impl(addr: Url, p2p: P2pPtr) -> bool { p2p.executor(), ); + debug!(target: "net::refinery::ping_node()", "Starting channel {}", url); channel.clone().start(p2p.executor()); // Ensure the channel gets stopped by adding a timeout to the handshake. Otherwise if @@ -183,6 +185,7 @@ async fn ping_node_impl(addr: Url, p2p: P2pPtr) -> bool { // zombie processes. let result = timeout(Duration::from_secs(5), handshake_task).await; + debug!(target: "net::refinery::ping_node()", "Stopping channel {}", url); channel.stop().await; match result { diff --git a/src/net/session/mod.rs b/src/net/session/mod.rs index ba3e11b30..6e66f164f 100644 --- a/src/net/session/mod.rs +++ b/src/net/session/mod.rs @@ -96,7 +96,8 @@ pub trait Session: Sync { // Perform the handshake protocol let protocol_version = ProtocolVersion::new(channel.clone(), p2p.settings().clone()).await; - debug!(target: "net::session::register_channel()", "register_channel {}", channel.clone().address()); + debug!(target: "net::session::register_channel()", + "Performing handshake protocols {}", channel.clone().address()); let handshake_task = self.perform_handshake_protocols(protocol_version, channel.clone(), executor.clone()); diff --git a/src/net/tests.rs b/src/net/tests.rs index eeba0a8cf..be2ce441a 100644 --- a/src/net/tests.rs +++ b/src/net/tests.rs @@ -66,8 +66,8 @@ fn p2p_test() { // We check this error so we can execute same file tests in parallel, // otherwise second one fails to init logger here. if simplelog::TermLogger::init( - simplelog::LevelFilter::Info, - //simplelog::LevelFilter::Debug, + //simplelog::LevelFilter::Info, + simplelog::LevelFilter::Debug, //simplelog::LevelFilter::Trace, cfg.build(), simplelog::TerminalMode::Mixed, @@ -155,26 +155,10 @@ async fn hostlist_propagation(ex: Arc>) { info!("Waiting until all peers connect"); sleep(10).await; - info!("Inspecting hostlists..."); for p2p in p2p_instances.iter() { let hosts = p2p.hosts(); - - let greylist = hosts.greylist.read().await; - let whitelist = hosts.whitelist.read().await; - let anchorlist = hosts.anchorlist.read().await; - - info!("Node {}", p2p.settings().node_id); - for (i, (url, last_seen)) in greylist.iter().enumerate() { - info!("Greylist entry {}: {}, {}", i, url, last_seen); - } - - for (i, (url, last_seen)) in whitelist.iter().enumerate() { - info!("Whitelist entry {}: {}, {}", i, url, last_seen); - } - - for (i, (url, last_seen)) in anchorlist.iter().enumerate() { - info!("Anchorlist entry {}: {}, {}", i, url, last_seen); - } + // We should have some greylist entries at this point. + assert!(!hosts.is_empty_greylist().await); } // Stop the P2P network