From 0c26d7baebfca3cf6cafeca54f2fec7b8acc5955 Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Wed, 31 Mar 2021 10:28:52 +0300 Subject: [PATCH] Fix sync restart (#8497) --- client/network/src/protocol/sync.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/network/src/protocol/sync.rs b/client/network/src/protocol/sync.rs index ee7943ba64697..14203531fb9e1 100644 --- a/client/network/src/protocol/sync.rs +++ b/client/network/src/protocol/sync.rs @@ -1563,11 +1563,13 @@ impl ChainSync { debug!(target:"sync", "Restarted with {} ({})", self.best_queued_number, self.best_queued_hash); let old_peers = std::mem::take(&mut self.peers); - old_peers.into_iter().filter_map(move |(id, p)| { + old_peers.into_iter().filter_map(move |(id, mut p)| { // peers that were downloading justifications // should be kept in that state. match p.state { PeerSyncState::DownloadingJustification(_) => { + // We make sure our commmon number is at least something we have. + p.common_number = info.best_number; self.peers.insert(id, p); return None; } @@ -2075,6 +2077,14 @@ mod test { sync.peers.get(&peer_id3).unwrap().state, PeerSyncState::DownloadingJustification(b1_hash), ); + + // Set common block to something that we don't have (e.g. failed import) + sync.peers.get_mut(&peer_id3).unwrap().common_number = 100; + let _ = sync.restart().count(); + assert_eq!( + sync.peers.get(&peer_id3).unwrap().common_number, + 50 + ); } /// Send a block annoucnement for the given `header`.