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

Do not update peer information if ancestor search is in progress #12631

Merged
merged 2 commits into from
Nov 7, 2022
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
10 changes: 5 additions & 5 deletions client/network/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2043,17 +2043,17 @@ where
return PollBlockAnnounceValidation::Nothing { is_best, who, announce }
};

if let PeerSyncState::AncestorSearch { .. } = peer.state {
trace!(target: "sync", "Peer state is ancestor search.");
return PollBlockAnnounceValidation::Nothing { is_best, who, announce }
}

if is_best {
// update their best block
peer.best_number = number;
peer.best_hash = hash;
}

if let PeerSyncState::AncestorSearch { .. } = peer.state {
trace!(target: "sync", "Peer state is ancestor search.");
return PollBlockAnnounceValidation::Nothing { is_best, who, announce }
}

// If the announced block is the best they have and is not ahead of us, our common number
// is either one further ahead or it's the one they just announced, if we know about it.
if is_best {
Expand Down
4 changes: 4 additions & 0 deletions client/network/test/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,10 @@ fn syncs_header_only_forks() {
while !net.peer(1).has_block(&small_hash) {
net.block_until_idle();
}

net.block_until_sync();
assert_eq!(net.peer(0).client().info().best_hash, net.peer(1).client().info().best_hash);
assert_ne!(small_hash, net.peer(0).client().info().best_hash);
}

#[test]
Expand Down