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

Commit

Permalink
Do not update peer information if ancestor search is in progress (#12631
Browse files Browse the repository at this point in the history
)

* Do not update peer information if ancestor search is in progress

If block announcement is received from a peer while ancestor search
for that same peer is still in progress, do not update the peer's best
hash and best number as that causes the ancestor search to yield
different information from what was expected and can cause, for example,
a fork of lower height not be be downloaded.

* Block until peers are in sync
  • Loading branch information
altonen authored Nov 7, 2022
1 parent 3a450ff commit 61e7ad4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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 @@ -549,6 +549,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

0 comments on commit 61e7ad4

Please sign in to comment.