From afe5d9703072383b5609c6d68648510e0ff0a0a8 Mon Sep 17 00:00:00 2001 From: Povilas Liubauskas Date: Fri, 20 Dec 2024 14:21:21 +0200 Subject: [PATCH] Disconnect peers with outdated finalized root if it cannot be validated due to missing historical data --- p2p/src/network.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/p2p/src/network.rs b/p2p/src/network.rs index bfe5840..4d2234a 100644 --- a/p2p/src/network.rs +++ b/p2p/src/network.rs @@ -1631,8 +1631,8 @@ impl Network

{ if let Some(root) = local_finalized_root_at_remote_finalized_epoch { if root != remote.finalized_root { warn!( - "peer {} has different block finalized at epoch {} ({:?} != {:?})", - peer_id, remote.finalized_epoch, root, remote.finalized_root, + "peer {peer_id} has different block finalized at epoch {} ({root:?} != {:?})", + remote.finalized_epoch, remote.finalized_root, ); P2pToSync::RemovePeer(peer_id).send(&self.channels.p2p_to_sync_tx); @@ -1645,6 +1645,22 @@ impl Network

{ return; } + } else if matches!(sync_status, SyncStatus::Behind { .. }) { + debug!( + "disconnecting peer {peer_id} due to missing historical data \ + required to validate finalized root {:?} at epoch {}", + remote.finalized_root, remote.finalized_epoch, + ); + + P2pToSync::RemovePeer(peer_id).send(&self.channels.p2p_to_sync_tx); + ServiceInboundMessage::GoodbyePeer( + peer_id, + GoodbyeReason::IrrelevantNetwork, + ReportSource::SyncService, + ) + .send(&self.network_to_service_tx); + + return; } // Update status