mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 01:07:57 +00:00
Fix sync downloading ancient chains (#4060)
* Update best block on announcement * Added a test
This commit is contained in:
committed by
Gavin Wood
parent
1789ed732f
commit
4b8578e7e4
@@ -1037,7 +1037,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
peer.recently_announced.pop_front();
|
||||
}
|
||||
peer.recently_announced.push_back(hash.clone());
|
||||
if is_best && number > peer.best_number {
|
||||
if is_best {
|
||||
// update their best block
|
||||
peer.best_number = number;
|
||||
peer.best_hash = hash;
|
||||
|
||||
@@ -633,3 +633,21 @@ fn syncs_header_only_forks() {
|
||||
})).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_not_sync_announced_old_best_block() {
|
||||
let _ = ::env_logger::try_init();
|
||||
let mut runtime = current_thread::Runtime::new().unwrap();
|
||||
let mut net = TestNet::new(3);
|
||||
|
||||
let old_hash = net.peer(0).push_blocks(1, false);
|
||||
net.peer(0).push_blocks(19, true);
|
||||
net.peer(1).push_blocks(20, true);
|
||||
|
||||
net.peer(0).announce_block(old_hash, 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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user