From 1245b7a74561c12cfe5f001b68d22d7225605ecf Mon Sep 17 00:00:00 2001 From: Nick Vincent Date: Tue, 14 Jan 2025 03:18:48 -0500 Subject: [PATCH] =?UTF-8?q?fix=20=F0=9F=90=9B:=20Added=20case=20for=20peer?= =?UTF-8?q?=20disconnection,=20additional=20testing=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ISSUE: #60 --- app/src/chain.rs | 5 ++++- app/src/network/mod.rs | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/chain.rs b/app/src/chain.rs index 83cab54..4b6ecb8 100644 --- a/app/src/chain.rs +++ b/app/src/chain.rs @@ -1183,6 +1183,9 @@ impl> Chain { let payload_prev_hash = x.message.execution_payload.parent_hash; info!("Received payload at height {number} {payload_prev_hash} -> {payload_hash}"); + let head_hash = self.head.read().await.as_ref().unwrap().hash; + let head_height = self.head.read().await.as_ref().unwrap().height; + debug!("Local head: {:#?}, height: {}", head_hash, head_height); // sync first then process block so we don't skip and trigger a re-sync if matches!(self.get_parent(&x), Err(Error::MissingParent)) { @@ -1292,7 +1295,7 @@ impl> Chain { peer_id, OutboundRequest::BlocksByRange( crate::network::rpc::methods::BlocksByRangeRequest { - start_height: head + 1, + start_height: head, count: 1024, }, ), diff --git a/app/src/network/mod.rs b/app/src/network/mod.rs index b5fc9e3..f870fb5 100644 --- a/app/src/network/mod.rs +++ b/app/src/network/mod.rs @@ -362,6 +362,11 @@ impl NetworkBackend { peers.insert(peer_id); let _ = peers_connected_tx.send(peers.clone()); } + SwarmEvent::ConnectionClosed { peer_id, connection_id, endpoint, num_established, cause } => { + debug!("Connection closed: peer_id: {peer_id}, connection_id: {connection_id}, endpoint: {endpoint:?}, num_established: {num_established}, cause: {cause:?}"); + peers.remove(&peer_id); + let _ = peers_connected_tx.send(peers.clone()); + } x => { trace!("Unhandled message {x:?}"); }