From c12ace2293eb805d15d5d061d36adec51fe8f114 Mon Sep 17 00:00:00 2001 From: stringhandler Date: Tue, 3 Dec 2024 19:55:37 +0200 Subject: [PATCH] fix: save last ping when adding a peer (#197) --- src/server/p2p/network.rs | 9 ++++++++- src/server/p2p/peer_store.rs | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/server/p2p/network.rs b/src/server/p2p/network.rs index 52d4ec0..0675cbc 100644 --- a/src/server/p2p/network.rs +++ b/src/server/p2p/network.rs @@ -570,7 +570,14 @@ where S: ShareChain } let payload = Arc::new(payload); let message_peer = payload.peer_id(); - info!(target: NEW_TIP_NOTIFY_LOGGING_LOG_TARGET, "[SQUAD_NEW_BLOCK_TOPIC] New block from gossip: {source_peer:?} -> [{}] Blocks: {}", payload.algo(), payload.new_blocks.iter().map(|b| format!("{}:{}", b.height, &b.hash.to_hex()[0..8])).collect::>().join(",")); + let message_age = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_else(|_| Duration::from_secs(0)) + .checked_sub(Duration::from_secs(payload.timestamp)) + .unwrap_or_else(|| Duration::from_secs(0)); + info!(target: NEW_TIP_NOTIFY_LOGGING_LOG_TARGET, "[SQUAD_NEW_BLOCK_TOPIC] New block from gossip: {source_peer:?} via {propagation_source}-> [{}] Blocks: {} Age:{}", payload.algo(), payload.new_blocks.iter().map(|b| format!("{}:{}", b.height, &b.hash.to_hex()[0..8])).collect::>().join(","), humantime::format_duration( + message_age + )); // verify payload if payload.new_blocks.is_empty() { diff --git a/src/server/p2p/peer_store.rs b/src/server/p2p/peer_store.rs index 59ccd42..0e24aea 100644 --- a/src/server/p2p/peer_store.rs +++ b/src/server/p2p/peer_store.rs @@ -258,6 +258,9 @@ impl PeerStore { new_record.last_rx_sync_attempt = previous_record.last_rx_sync_attempt; new_record.last_sha3x_sync_attempt = previous_record.last_sha3x_sync_attempt; new_record.created = entry.created; + new_record.last_ping = entry.last_ping; + new_record.num_grey_listings = entry.num_grey_listings; + new_record.last_grey_list_reason = entry.last_grey_list_reason.clone(); *entry = new_record; // self.whitelist_peers.insert(peer_id, PeerStoreRecord::new(peer_info));