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

Fix sync restart for peers that provide block justifications #8497

Merged
merged 1 commit into from
Mar 31, 2021
Merged
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
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