Skip to content

Commit

Permalink
fix(node): update stale block time after resetting connections
Browse files Browse the repository at this point in the history
If a block is considered stale, the `advance_state` function will reset
connections with all peers. To reset the "staleness" of a block, the
`LastBlockMonitor::update` function must be called. Currently that is done
upon receiving new block headers, but no headers will ever be sent, as
`advance_state` disconnects the peers before they can send them once
a block is considered stale. Here we patch this to reset the "staleness"
of a block after disconnecting from all peers.
  • Loading branch information
rustaceanrob committed Jan 17, 2025
1 parent 04a038b commit 09d8490
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
let mut client_recv = self.client_recv.lock().await;
loop {
// Try to advance the state of the node
self.advance_state(&last_block).await;
self.advance_state(&mut last_block).await;
// Connect to more peers if we need them and remove old connections
self.dispatch().await?;
// If there are blocks we need in the queue, we should request them of a random peer
Expand Down Expand Up @@ -424,7 +424,7 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
}

// Try to continue with the syncing process
async fn advance_state(&self, last_block: &LastBlockMonitor) {
async fn advance_state(&self, last_block: &mut LastBlockMonitor) {
let mut state = self.state.write().await;
match *state {
NodeState::Behind => {
Expand Down Expand Up @@ -476,6 +476,7 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
.send_dialog("Disconnecting from remote nodes to find new connections")
.await;
self.broadcast(MainThreadMessage::Disconnect).await;
last_block.update();
}
}
}
Expand Down

0 comments on commit 09d8490

Please sign in to comment.