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

Commit dab6575

Browse files
arkpargavofyork
authored andcommitted
Fix sync downloading ancient chains (#4060)
* Update best block on announcement * Added a test
1 parent 61e64b4 commit dab6575

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

core/network/src/protocol/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ impl<B: BlockT> ChainSync<B> {
10371037
peer.recently_announced.pop_front();
10381038
}
10391039
peer.recently_announced.push_back(hash.clone());
1040-
if is_best && number > peer.best_number {
1040+
if is_best {
10411041
// update their best block
10421042
peer.best_number = number;
10431043
peer.best_hash = hash;

core/network/src/test/sync.rs

+18
Original file line numberDiff line numberDiff line change
@@ -633,3 +633,21 @@ fn syncs_header_only_forks() {
633633
})).unwrap();
634634
}
635635

636+
#[test]
637+
fn does_not_sync_announced_old_best_block() {
638+
let _ = ::env_logger::try_init();
639+
let mut runtime = current_thread::Runtime::new().unwrap();
640+
let mut net = TestNet::new(3);
641+
642+
let old_hash = net.peer(0).push_blocks(1, false);
643+
net.peer(0).push_blocks(19, true);
644+
net.peer(1).push_blocks(20, true);
645+
646+
net.peer(0).announce_block(old_hash, Vec::new());
647+
runtime.block_on(futures::future::poll_fn::<(), (), _>(|| -> Result<_, ()> {
648+
// poll once to import announcement
649+
net.poll();
650+
Ok(Async::Ready(()))
651+
})).unwrap();
652+
assert!(!net.peer(1).is_major_syncing());
653+
}

0 commit comments

Comments
 (0)