From 9defa6a281a1d8b30ba84c74dec357eb16cdf26e Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan <arkady.paronyan@gmail.com> Date: Sat, 9 Nov 2019 15:46:43 +0100 Subject: [PATCH] Further fix for common block update (#4071) --- substrate/core/network/src/protocol/sync.rs | 10 ++++++---- substrate/core/network/src/test/sync.rs | 11 ++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/substrate/core/network/src/protocol/sync.rs b/substrate/core/network/src/protocol/sync.rs index c9465e4b741..a77dfb1cdca 100644 --- a/substrate/core/network/src/protocol/sync.rs +++ b/substrate/core/network/src/protocol/sync.rs @@ -1047,10 +1047,12 @@ impl<B: BlockT> ChainSync<B> { } // If the announced block is the best they have seen, our common number // is either one further ahead or it's the one they just announced, if we know about it. - if known && is_best { - peer.common_number = number - } else if header.parent_hash() == &self.best_queued_hash || known_parent { - peer.common_number = number - One::one(); + if is_best { + if known { + peer.common_number = number + } else if header.parent_hash() == &self.best_queued_hash || known_parent { + peer.common_number = number - One::one(); + } } self.is_idle = false; diff --git a/substrate/core/network/src/test/sync.rs b/substrate/core/network/src/test/sync.rs index 768ee1c34eb..072099d6f7f 100644 --- a/substrate/core/network/src/test/sync.rs +++ b/substrate/core/network/src/test/sync.rs @@ -640,7 +640,8 @@ fn does_not_sync_announced_old_best_block() { let mut net = TestNet::new(3); let old_hash = net.peer(0).push_blocks(1, false); - net.peer(0).push_blocks(19, true); + let old_hash_with_parent = net.peer(0).push_blocks(1, false); + net.peer(0).push_blocks(18, true); net.peer(1).push_blocks(20, true); net.peer(0).announce_block(old_hash, Vec::new()); @@ -650,4 +651,12 @@ fn does_not_sync_announced_old_best_block() { Ok(Async::Ready(())) })).unwrap(); assert!(!net.peer(1).is_major_syncing()); + + net.peer(0).announce_block(old_hash_with_parent, Vec::new()); + runtime.block_on(futures::future::poll_fn::<(), (), _>(|| -> Result<_, ()> { + // poll once to import announcement + net.poll(); + Ok(Async::Ready(())) + })).unwrap(); + assert!(!net.peer(1).is_major_syncing()); } -- GitLab