mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-04 01:07:23 +00:00
This reverts commit 172359adad.
This commit is contained in:
@@ -37,7 +37,7 @@ fn prepare_good_block() -> (TestClient, Hash, u64, PeerId, IncomingBlock<Block>)
|
||||
(client, hash, number, peer_id.clone(), IncomingBlock {
|
||||
hash,
|
||||
header,
|
||||
body: Some(Vec::new()),
|
||||
body: None,
|
||||
justification,
|
||||
origin: Some(peer_id.clone())
|
||||
})
|
||||
@@ -53,7 +53,7 @@ fn import_single_good_block_works() {
|
||||
match import_single_block(&mut test_client::new(), BlockOrigin::File, block, &mut PassThroughVerifier(true)) {
|
||||
Ok(BlockImportResult::ImportedUnknown(ref num, ref aux, ref org))
|
||||
if *num == number && *aux == expected_aux && *org == Some(peer_id) => {}
|
||||
r @ _ => panic!("{:?}", r)
|
||||
_ => panic!()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -374,10 +374,16 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Count the total number of imported blocks.
|
||||
pub fn blocks_count(&self) -> u64 {
|
||||
/// Count the current number of known blocks. Note that:
|
||||
/// 1. this might be expensive as it creates an in-memory-copy of the chain
|
||||
/// to count the blocks, thus if you have a different way of testing this
|
||||
/// (e.g. `info.best_hash`) - use that.
|
||||
/// 2. This is not always increasing nor accurate, as the
|
||||
/// orphaned and proven-to-never-finalized blocks may be pruned at any time.
|
||||
/// Therefore, this number can drop again.
|
||||
pub fn blocks_count(&self) -> usize {
|
||||
self.backend.as_ref().map(
|
||||
|backend| backend.blocks_count()
|
||||
|backend| backend.as_in_memory().blockchain().blocks_count()
|
||||
).unwrap_or(0)
|
||||
}
|
||||
}
|
||||
@@ -513,16 +519,9 @@ pub trait TestNetFactory: Sized {
|
||||
net
|
||||
}
|
||||
|
||||
fn add_full_peer(&mut self, config: &ProtocolConfig) {
|
||||
self.add_full_peer_with_states(config, None)
|
||||
}
|
||||
|
||||
/// Add a full peer.
|
||||
fn add_full_peer_with_states(&mut self, config: &ProtocolConfig, keep_blocks: Option<u32>) {
|
||||
let test_client_builder = match keep_blocks {
|
||||
Some(keep_blocks) => TestClientBuilder::with_pruning_window(keep_blocks),
|
||||
None => TestClientBuilder::with_default_backend(),
|
||||
};
|
||||
fn add_full_peer(&mut self, config: &ProtocolConfig) {
|
||||
let test_client_builder = TestClientBuilder::with_default_backend();
|
||||
let backend = test_client_builder.backend();
|
||||
let (c, longest_chain) = test_client_builder.build_with_longest_chain();
|
||||
let client = Arc::new(c);
|
||||
@@ -680,7 +679,7 @@ pub trait TestNetFactory: Sized {
|
||||
if peer.is_major_syncing() || peer.network.num_queued_blocks() != 0 {
|
||||
return Async::NotReady
|
||||
}
|
||||
match (highest, peer.client.info().chain.best_hash) {
|
||||
match (highest, peer.client.info().chain.best_number) {
|
||||
(None, b) => highest = Some(b),
|
||||
(Some(ref a), ref b) if a == b => {},
|
||||
(Some(_), _) => return Async::NotReady,
|
||||
|
||||
@@ -236,14 +236,7 @@ fn sync_no_common_longer_chain_fails() {
|
||||
let mut net = TestNet::new(3);
|
||||
net.peer(0).push_blocks(20, true);
|
||||
net.peer(1).push_blocks(20, false);
|
||||
runtime.block_on(futures::future::poll_fn::<(), (), _>(|| -> Result<_, ()> {
|
||||
net.poll();
|
||||
if net.peer(0).is_major_syncing() {
|
||||
Ok(Async::NotReady)
|
||||
} else {
|
||||
Ok(Async::Ready(()))
|
||||
}
|
||||
})).unwrap();
|
||||
net.block_until_sync(&mut runtime);
|
||||
let peer1 = &net.peers()[1];
|
||||
assert!(!net.peers()[0].blockchain_canon_equals(peer1));
|
||||
}
|
||||
@@ -599,37 +592,3 @@ fn can_sync_explicit_forks() {
|
||||
Ok(Async::Ready(()))
|
||||
})).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn syncs_header_only_forks() {
|
||||
let _ = ::env_logger::try_init();
|
||||
let mut runtime = current_thread::Runtime::new().unwrap();
|
||||
let mut net = TestNet::new(0);
|
||||
let config = ProtocolConfig::default();
|
||||
net.add_full_peer_with_states(&config, None);
|
||||
net.add_full_peer_with_states(&config, Some(3));
|
||||
net.peer(0).push_blocks(2, false);
|
||||
net.peer(1).push_blocks(2, false);
|
||||
|
||||
net.peer(0).push_blocks(2, true);
|
||||
let small_hash = net.peer(0).client().info().chain.best_hash;
|
||||
let small_number = net.peer(0).client().info().chain.best_number;
|
||||
net.peer(1).push_blocks(4, false);
|
||||
|
||||
net.block_until_sync(&mut runtime);
|
||||
// Peer 1 won't sync the small fork because common block state is missing
|
||||
assert_eq!(9, net.peer(0).blocks_count());
|
||||
assert_eq!(7, net.peer(1).blocks_count());
|
||||
|
||||
// Request explicit header-only sync request for the ancient fork.
|
||||
let first_peer_id = net.peer(0).id();
|
||||
net.peer(1).set_sync_fork_request(vec![first_peer_id], small_hash, small_number);
|
||||
runtime.block_on(futures::future::poll_fn::<(), (), _>(|| -> Result<_, ()> {
|
||||
net.poll();
|
||||
if net.peer(1).client().header(&BlockId::Hash(small_hash)).unwrap().is_none() {
|
||||
return Ok(Async::NotReady)
|
||||
}
|
||||
Ok(Async::Ready(()))
|
||||
})).unwrap();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user