Skip to content

Commit 09d8490

Browse files
committed
fix(node): update stale block time after resetting connections
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.
1 parent 04a038b commit 09d8490

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/core/node.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
188188
let mut client_recv = self.client_recv.lock().await;
189189
loop {
190190
// Try to advance the state of the node
191-
self.advance_state(&last_block).await;
191+
self.advance_state(&mut last_block).await;
192192
// Connect to more peers if we need them and remove old connections
193193
self.dispatch().await?;
194194
// If there are blocks we need in the queue, we should request them of a random peer
@@ -424,7 +424,7 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
424424
}
425425

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

0 commit comments

Comments
 (0)