Update common block in sync after importing blocks of a peer, please read UPDATE (#7733)

* Update common block in sync after importing blocks of a peer

This updates the sync code to update the common block of a peer, after
we have imported blocks from this peer. This fixes a bug for when we are
connected to one or more nodes that are doing a full sync as our node.
Nodes in full sync will not announce new blocks, as we don't send import
notifications on full sync. The problem as now that we were connected to
some peer that reported some low number as its best and we tried to sync
these blocks. But, as we did not update the common block of this peer,
we would sync these blocks over and over again. Being captured in some
time warp.
The solution to this problem is that we increase the common number as we
import blocks from this peer.

* Test

* Test name..

* Fix test

* Cleanup some code and write some new regression test

* Implement the ancestor search

* Check that the common number is smaller than the last finalized block

* Update client/network/src/protocol/sync.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

* Update client/network/src/protocol/sync.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

* Update client/network/src/protocol/sync.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

* Change the way we build the status messages

* Start some new test...

* Finish test

* Rename test

* Update client/network/src/protocol.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
Bastian Köcher
2020-12-18 12:04:17 +01:00
committed by GitHub
parent 9a3cab74ac
commit d3c7a99d3c
7 changed files with 546 additions and 107 deletions
@@ -545,6 +545,7 @@ mod tests {
impl Arbitrary for ArbitraryPeerSync {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
let ps = PeerSync {
peer_id: PeerId::random(),
common_number: g.gen(),
best_hash: Hash::random(),
best_number: g.gen(),
@@ -561,10 +562,10 @@ mod tests {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
let mut peers = HashMap::with_capacity(g.size());
for _ in 0 .. g.size() {
peers.insert(PeerId::random(), ArbitraryPeerSync::arbitrary(g).0);
let ps = ArbitraryPeerSync::arbitrary(g).0;
peers.insert(ps.peer_id.clone(), ps);
}
ArbitraryPeers(peers)
}
}
}