From 726d7390bc19788d6648c1a89cd64d2a6adf932c Mon Sep 17 00:00:00 2001 From: quake Date: Tue, 19 Nov 2024 12:50:57 +0900 Subject: [PATCH] chore: debug dump peerstore --- network/src/peer_registry.rs | 2 ++ network/src/services/dump_peer_store.rs | 7 ++----- test/src/net.rs | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/network/src/peer_registry.rs b/network/src/peer_registry.rs index 9f3e55536b..6d8cd27af0 100644 --- a/network/src/peer_registry.rs +++ b/network/src/peer_registry.rs @@ -76,6 +76,7 @@ impl PeerRegistry { session_type: SessionType, peer_store: &mut PeerStore, ) -> Result, Error> { + debug!("start accept peer {:?}", session_id); if self.peers.contains_key(&session_id) { return Err(PeerError::SessionExists(session_id).into()); } @@ -112,6 +113,7 @@ impl PeerRegistry { peer_store.add_connected_peer(remote_addr.clone(), session_type); let peer = Peer::new(session_id, session_type, remote_addr, is_whitelist); self.peers.insert(session_id, peer); + debug!("end accept peer {:?}", session_id); Ok(evicted_peer) } diff --git a/network/src/services/dump_peer_store.rs b/network/src/services/dump_peer_store.rs index 735ace3a71..a36a2b35b6 100644 --- a/network/src/services/dump_peer_store.rs +++ b/network/src/services/dump_peer_store.rs @@ -7,7 +7,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; -use tokio::time::{Instant, Interval, MissedTickBehavior}; +use tokio::time::{Interval, MissedTickBehavior}; const DEFAULT_DUMP_INTERVAL: Duration = Duration::from_secs(3600); // 1 hour @@ -50,10 +50,7 @@ impl Future for DumpPeerStoreService { fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { if self.interval.is_none() { self.interval = { - let mut interval = tokio::time::interval_at( - Instant::now() + DEFAULT_DUMP_INTERVAL, - DEFAULT_DUMP_INTERVAL, - ); + let mut interval = tokio::time::interval(DEFAULT_DUMP_INTERVAL); // The dump peer store service does not need to urgently compensate for the missed wake, // just delay behavior is enough interval.set_missed_tick_behavior(MissedTickBehavior::Delay); diff --git a/test/src/net.rs b/test/src/net.rs index b8f1375f7f..dcf959d661 100644 --- a/test/src/net.rs +++ b/test/src/net.rs @@ -4,7 +4,7 @@ use ckb_app_config::NetworkConfig; use ckb_async_runtime::{new_global_runtime, Runtime}; use ckb_chain_spec::consensus::Consensus; use ckb_channel::{self as channel, unbounded, Receiver, RecvTimeoutError, Sender}; -use ckb_logger::info; +use ckb_logger::{debug, info}; use ckb_network::{ async_trait, bytes::Bytes, extract_peer_id, CKBProtocol, CKBProtocolContext, CKBProtocolHandler, Flags, NetworkController, NetworkService, NetworkState, PeerIndex, @@ -217,6 +217,7 @@ impl CKBProtocolHandler for DummyProtocolHandler { peer_index: PeerIndex, _version: &str, ) { + debug!("DummyProtocolHandler connected peer_index: {:?}", peer_index); let peer = nc.get_peer(peer_index).unwrap(); let node_id = extract_peer_id(&peer.connected_addr) .map(|peer_id| peer_id.to_base58())