mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-29 20:47:25 +00:00
Add exponential search for ancestor search (#1875)
* feat: add exponential search * add tests * chore: improve code
This commit is contained in:
@@ -24,6 +24,24 @@ use std::thread;
|
||||
use std::time::Duration;
|
||||
use super::*;
|
||||
|
||||
fn test_ancestor_search_when_common_is(n: usize) {
|
||||
let _ = ::env_logger::try_init();
|
||||
let mut net = TestNet::new(3);
|
||||
|
||||
net.peer(0).push_blocks(n, false);
|
||||
net.peer(1).push_blocks(n, false);
|
||||
net.peer(2).push_blocks(n, false);
|
||||
|
||||
net.peer(0).push_blocks(10, true);
|
||||
net.peer(1).push_blocks(100, false);
|
||||
net.peer(2).push_blocks(100, false);
|
||||
|
||||
net.restart_peer(0);
|
||||
net.sync();
|
||||
assert!(net.peer(0).client.backend().as_in_memory().blockchain()
|
||||
.canon_equals_to(net.peer(1).client.backend().as_in_memory().blockchain()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_peers_works() {
|
||||
let _ = ::env_logger::try_init();
|
||||
@@ -140,6 +158,66 @@ fn sync_from_two_peers_with_ancestry_search_works() {
|
||||
.canon_equals_to(net.peer(1).client.backend().as_in_memory().blockchain()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ancestry_search_works_when_common_is_hundred() {
|
||||
let _ = ::env_logger::try_init();
|
||||
let mut net = TestNet::new(3);
|
||||
|
||||
net.peer(0).push_blocks(100, false);
|
||||
net.peer(1).push_blocks(100, false);
|
||||
net.peer(2).push_blocks(100, false);
|
||||
|
||||
net.peer(0).push_blocks(10, true);
|
||||
net.peer(1).push_blocks(100, false);
|
||||
net.peer(2).push_blocks(100, false);
|
||||
|
||||
net.restart_peer(0);
|
||||
net.sync();
|
||||
|
||||
assert!(net.peer(0).client.backend().as_in_memory().blockchain()
|
||||
.canon_equals_to(net.peer(1).client.backend().as_in_memory().blockchain()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ancestry_search_works_when_backoff_is_one() {
|
||||
let _ = ::env_logger::try_init();
|
||||
let mut net = TestNet::new(3);
|
||||
|
||||
net.peer(0).push_blocks(1, false);
|
||||
net.peer(1).push_blocks(2, false);
|
||||
net.peer(2).push_blocks(2, false);
|
||||
|
||||
net.restart_peer(0);
|
||||
net.sync();
|
||||
assert!(net.peer(0).client.backend().as_in_memory().blockchain()
|
||||
.canon_equals_to(net.peer(1).client.backend().as_in_memory().blockchain()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ancestry_search_works_when_ancestor_is_genesis() {
|
||||
let _ = ::env_logger::try_init();
|
||||
let mut net = TestNet::new(3);
|
||||
|
||||
net.peer(0).push_blocks(13, true);
|
||||
net.peer(1).push_blocks(100, false);
|
||||
net.peer(2).push_blocks(100, false);
|
||||
|
||||
net.restart_peer(0);
|
||||
net.sync();
|
||||
assert!(net.peer(0).client.backend().as_in_memory().blockchain()
|
||||
.canon_equals_to(net.peer(1).client.backend().as_in_memory().blockchain()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ancestry_search_works_when_common_is_one() {
|
||||
test_ancestor_search_when_common_is(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ancestry_search_works_when_common_is_two() {
|
||||
test_ancestor_search_when_common_is(2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_long_chain_works() {
|
||||
let mut net = TestNet::new(2);
|
||||
|
||||
Reference in New Issue
Block a user