Skip to content

Commit

Permalink
fix 🐛: Added case for peer disconnection, additional testing needed
Browse files Browse the repository at this point in the history
ISSUE: #60
  • Loading branch information
emailnjv committed Jan 14, 2025
1 parent 954f5ed commit 1245b7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,9 @@ impl<DB: ItemStore<MainnetEthSpec>> Chain<DB> {
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)) {
Expand Down Expand Up @@ -1292,7 +1295,7 @@ impl<DB: ItemStore<MainnetEthSpec>> Chain<DB> {
peer_id,
OutboundRequest::BlocksByRange(
crate::network::rpc::methods::BlocksByRangeRequest {
start_height: head + 1,
start_height: head,
count: 1024,
},
),
Expand Down
5 changes: 5 additions & 0 deletions app/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
}
Expand Down

0 comments on commit 1245b7a

Please sign in to comment.