mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 08:51:09 +00:00
Refactor to use only chain info (#4516)
This commit is contained in:
committed by
Bastian Köcher
parent
8ecc450fd9
commit
6d06a19f41
@@ -28,10 +28,10 @@ use libp2p::build_multiaddr;
|
||||
use log::trace;
|
||||
use sc_network::FinalityProofProvider;
|
||||
use sp_blockchain::{
|
||||
Result as ClientResult, well_known_cache_keys::{self, Id as CacheKeyId},
|
||||
Result as ClientResult, well_known_cache_keys::{self, Id as CacheKeyId}, Info as BlockchainInfo,
|
||||
};
|
||||
use sc_client_api::{
|
||||
ClientInfo, BlockchainEvents, BlockImportNotification,
|
||||
BlockchainEvents, BlockImportNotification,
|
||||
FinalityNotifications, ImportNotifications,
|
||||
FinalityNotification,
|
||||
backend::{AuxStore, Backend, Finalizer}
|
||||
@@ -161,10 +161,10 @@ impl PeersClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn info(&self) -> ClientInfo<Block> {
|
||||
pub fn info(&self) -> BlockchainInfo<Block> {
|
||||
match *self {
|
||||
PeersClient::Full(ref client, ref _backend) => client.info(),
|
||||
PeersClient::Light(ref client, ref _backend) => client.info(),
|
||||
PeersClient::Full(ref client, ref _backend) => client.chain_info(),
|
||||
PeersClient::Light(ref client, ref _backend) => client.chain_info(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
|
||||
pub fn generate_blocks<F>(&mut self, count: usize, origin: BlockOrigin, edit_block: F) -> H256
|
||||
where F: FnMut(BlockBuilder<Block, PeersFullClient>) -> Block
|
||||
{
|
||||
let best_hash = self.client.info().chain.best_hash;
|
||||
let best_hash = self.client.info().best_hash;
|
||||
self.generate_blocks_at(BlockId::Hash(best_hash), count, origin, edit_block)
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
|
||||
|
||||
/// Push blocks to the peer (simplified: with or without a TX)
|
||||
pub fn push_blocks(&mut self, count: usize, with_tx: bool) -> H256 {
|
||||
let best_hash = self.client.info().chain.best_hash;
|
||||
let best_hash = self.client.info().best_hash;
|
||||
self.push_blocks_at(BlockId::Hash(best_hash), count, with_tx)
|
||||
}
|
||||
|
||||
@@ -689,7 +689,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().best_hash) {
|
||||
(None, b) => highest = Some(b),
|
||||
(Some(ref a), ref b) if a == b => {},
|
||||
(Some(_), _) => return Async::NotReady,
|
||||
|
||||
@@ -374,8 +374,8 @@ fn own_blocks_are_announced() {
|
||||
|
||||
net.block_until_sync(&mut runtime);
|
||||
|
||||
assert_eq!(net.peer(0).client.info().chain.best_number, 1);
|
||||
assert_eq!(net.peer(1).client.info().chain.best_number, 1);
|
||||
assert_eq!(net.peer(0).client.info().best_number, 1);
|
||||
assert_eq!(net.peer(1).client.info().best_number, 1);
|
||||
let peer0 = &net.peers()[0];
|
||||
assert!(net.peers()[1].blockchain_canon_equals(peer0));
|
||||
(net.peers()[2].blockchain_canon_equals(peer0));
|
||||
@@ -396,9 +396,9 @@ fn blocks_are_not_announced_by_light_nodes() {
|
||||
|
||||
// Sync between 0 and 1.
|
||||
net.peer(0).push_blocks(1, false);
|
||||
assert_eq!(net.peer(0).client.info().chain.best_number, 1);
|
||||
assert_eq!(net.peer(0).client.info().best_number, 1);
|
||||
net.block_until_sync(&mut runtime);
|
||||
assert_eq!(net.peer(1).client.info().chain.best_number, 1);
|
||||
assert_eq!(net.peer(1).client.info().best_number, 1);
|
||||
|
||||
// Add another node and remove node 0.
|
||||
net.add_full_peer(&ProtocolConfig::default());
|
||||
@@ -410,7 +410,7 @@ fn blocks_are_not_announced_by_light_nodes() {
|
||||
net.poll();
|
||||
delay.poll().map_err(|_| ())
|
||||
})).unwrap();
|
||||
assert_eq!(net.peer(1).client.info().chain.best_number, 0);
|
||||
assert_eq!(net.peer(1).client.info().best_number, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -423,13 +423,13 @@ fn can_sync_small_non_best_forks() {
|
||||
|
||||
// small fork + reorg on peer 1.
|
||||
net.peer(0).push_blocks_at(BlockId::Number(30), 2, true);
|
||||
let small_hash = net.peer(0).client().info().chain.best_hash;
|
||||
let small_hash = net.peer(0).client().info().best_hash;
|
||||
net.peer(0).push_blocks_at(BlockId::Number(30), 10, false);
|
||||
assert_eq!(net.peer(0).client().info().chain.best_number, 40);
|
||||
assert_eq!(net.peer(0).client().info().best_number, 40);
|
||||
|
||||
// peer 1 only ever had the long fork.
|
||||
net.peer(1).push_blocks(10, false);
|
||||
assert_eq!(net.peer(1).client().info().chain.best_number, 40);
|
||||
assert_eq!(net.peer(1).client().info().best_number, 40);
|
||||
|
||||
assert!(net.peer(0).client().header(&BlockId::Hash(small_hash)).unwrap().is_some());
|
||||
assert!(net.peer(1).client().header(&BlockId::Hash(small_hash)).unwrap().is_none());
|
||||
@@ -446,7 +446,7 @@ fn can_sync_small_non_best_forks() {
|
||||
|
||||
// synchronization: 0 synced to longer chain and 1 didn't sync to small chain.
|
||||
|
||||
assert_eq!(net.peer(0).client().info().chain.best_number, 40);
|
||||
assert_eq!(net.peer(0).client().info().best_number, 40);
|
||||
|
||||
assert!(net.peer(0).client().header(&BlockId::Hash(small_hash)).unwrap().is_some());
|
||||
assert!(!net.peer(1).client().header(&BlockId::Hash(small_hash)).unwrap().is_some());
|
||||
@@ -493,8 +493,8 @@ fn can_not_sync_from_light_peer() {
|
||||
net.block_until_sync(&mut runtime);
|
||||
|
||||
// ensure #0 && #1 have the same best block
|
||||
let full0_info = net.peer(0).client.info().chain;
|
||||
let light_info = net.peer(1).client.info().chain;
|
||||
let full0_info = net.peer(0).client.info();
|
||||
let light_info = net.peer(1).client.info();
|
||||
assert_eq!(full0_info.best_number, 1);
|
||||
assert_eq!(light_info.best_number, 1);
|
||||
assert_eq!(light_info.best_hash, full0_info.best_hash);
|
||||
@@ -555,14 +555,14 @@ fn can_sync_explicit_forks() {
|
||||
|
||||
// small fork + reorg on peer 1.
|
||||
net.peer(0).push_blocks_at(BlockId::Number(30), 2, true);
|
||||
let small_hash = net.peer(0).client().info().chain.best_hash;
|
||||
let small_number = net.peer(0).client().info().chain.best_number;
|
||||
let small_hash = net.peer(0).client().info().best_hash;
|
||||
let small_number = net.peer(0).client().info().best_number;
|
||||
net.peer(0).push_blocks_at(BlockId::Number(30), 10, false);
|
||||
assert_eq!(net.peer(0).client().info().chain.best_number, 40);
|
||||
assert_eq!(net.peer(0).client().info().best_number, 40);
|
||||
|
||||
// peer 1 only ever had the long fork.
|
||||
net.peer(1).push_blocks(10, false);
|
||||
assert_eq!(net.peer(1).client().info().chain.best_number, 40);
|
||||
assert_eq!(net.peer(1).client().info().best_number, 40);
|
||||
|
||||
assert!(net.peer(0).client().header(&BlockId::Hash(small_hash)).unwrap().is_some());
|
||||
assert!(net.peer(1).client().header(&BlockId::Hash(small_hash)).unwrap().is_none());
|
||||
@@ -579,7 +579,7 @@ fn can_sync_explicit_forks() {
|
||||
|
||||
// synchronization: 0 synced to longer chain and 1 didn't sync to small chain.
|
||||
|
||||
assert_eq!(net.peer(0).client().info().chain.best_number, 40);
|
||||
assert_eq!(net.peer(0).client().info().best_number, 40);
|
||||
|
||||
assert!(net.peer(0).client().header(&BlockId::Hash(small_hash)).unwrap().is_some());
|
||||
assert!(!net.peer(1).client().header(&BlockId::Hash(small_hash)).unwrap().is_some());
|
||||
@@ -612,8 +612,8 @@ fn syncs_header_only_forks() {
|
||||
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;
|
||||
let small_hash = net.peer(0).client().info().best_hash;
|
||||
let small_number = net.peer(0).client().info().best_number;
|
||||
net.peer(1).push_blocks(4, false);
|
||||
|
||||
net.block_until_sync(&mut runtime);
|
||||
|
||||
Reference in New Issue
Block a user