Skip to content

Commit

Permalink
fix: save last ping when adding a peer (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler authored Dec 3, 2024
1 parent 0d76fca commit c12ace2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/server/p2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<String>>().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::<Vec<String>>().join(","), humantime::format_duration(
message_age
));

// verify payload
if payload.new_blocks.is_empty() {
Expand Down
3 changes: 3 additions & 0 deletions src/server/p2p/peer_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit c12ace2

Please sign in to comment.