From 09d8490d5164497f2520e6c8c9d68c6264098fc2 Mon Sep 17 00:00:00 2001 From: Rob N Date: Fri, 17 Jan 2025 11:53:12 -1000 Subject: [PATCH] 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. --- src/core/node.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/node.rs b/src/core/node.rs index 7ae5a69..90a20a8 100644 --- a/src/core/node.rs +++ b/src/core/node.rs @@ -188,7 +188,7 @@ impl Node { 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 @@ -424,7 +424,7 @@ impl Node { } // 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 => { @@ -476,6 +476,7 @@ impl Node { .send_dialog("Disconnecting from remote nodes to find new connections") .await; self.broadcast(MainThreadMessage::Disconnect).await; + last_block.update(); } } }