Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl LastBlockMonitor {
Self { last_block: None }
}

pub(crate) fn update(&mut self) {
pub(crate) fn reset(&mut self) {
self.last_block = Some(Instant::now())
}

Expand Down
7 changes: 4 additions & 3 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 @@ -216,7 +216,7 @@ impl<H: HeaderStore, P: PeerStore> Node<H, P> {
}
PeerMessage::Addr(addresses) => self.handle_new_addrs(addresses).await,
PeerMessage::Headers(headers) => {
last_block.update();
last_block.reset();
self.dialog.send_dialog(format!("[Peer {}]: headers", peer_thread.nonce))
.await;
match self.handle_headers(peer_thread.nonce, headers).await {
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.reset();
}
}
}
Expand Down
Loading