Warp sync part II (#9284)

* Gap sync

* Gap epoch test

* Simplified network requests

* Update client/db/src/utils.rs

Co-authored-by: cheme <emericchevalier.pro@gmail.com>

* Fixed v1 migration and added some comments

* Next epoch is always regular

* Removed fork tree change

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Added a comment and converted assert to error

Co-authored-by: cheme <emericchevalier.pro@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Arkadiy Paronyan
2021-10-07 11:31:39 +02:00
committed by GitHub
parent 9f1c3acb7d
commit e6ff531d0b
29 changed files with 800 additions and 169 deletions
+32
View File
@@ -1202,6 +1202,38 @@ fn syncs_indexed_blocks() {
.is_some());
}
#[test]
fn warp_sync() {
sp_tracing::try_init_simple();
let mut net = TestNet::new(0);
// Create 3 synced peers and 1 peer trying to warp sync.
net.add_full_peer_with_config(Default::default());
net.add_full_peer_with_config(Default::default());
net.add_full_peer_with_config(Default::default());
net.add_full_peer_with_config(FullPeerConfig {
sync_mode: SyncMode::Warp,
..Default::default()
});
let gap_end = net.peer(0).push_blocks(63, false);
net.peer(0).push_blocks(1, false);
net.peer(1).push_blocks(64, false);
net.peer(2).push_blocks(64, false);
// Wait for peer 1 to sync state.
net.block_until_sync();
assert!(!net.peer(3).client().has_state_at(&BlockId::Number(1)));
assert!(net.peer(3).client().has_state_at(&BlockId::Number(64)));
// Wait for peer 1 download block history
block_on(futures::future::poll_fn::<(), _>(|cx| {
net.poll(cx);
if net.peer(3).has_block(&gap_end) {
Poll::Ready(())
} else {
Poll::Pending
}
}));
}
#[test]
fn syncs_huge_blocks() {
use sp_core::storage::well_known_keys::HEAP_PAGES;