Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix sync restart (#8497)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar authored Mar 31, 2021
1 parent 88243c1 commit 3e96c69
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/network/src/protocol/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1552,11 +1552,13 @@ impl<B: BlockT> ChainSync<B> {
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;
}
Expand Down Expand Up @@ -2064,6 +2066,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`.
Expand Down

0 comments on commit 3e96c69

Please sign in to comment.