Client::info() no longer returns a Result (#2776)

This commit is contained in:
Pierre Krieger
2019-06-04 16:09:46 +02:00
committed by Bastian Köcher
parent 53e8ad8728
commit 5df89a8a6f
33 changed files with 235 additions and 274 deletions
+6 -6
View File
@@ -163,7 +163,7 @@ impl PeersClient {
}
}
pub fn info(&self) -> ClientResult<ClientInfo<Block>> {
pub fn info(&self) -> ClientInfo<Block> {
match *self {
PeersClient::Full(ref client) => client.info(),
PeersClient::Light(ref client) => client.info(),
@@ -465,7 +465,7 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
/// Called after blockchain has been populated to updated current state.
fn start(&self) {
// Update the sync state to the latest chain state.
let info = self.client.info().expect("In-mem client does not fail");
let info = self.client.info();
let header = self
.client
.header(&BlockId::Hash(info.chain.best_hash))
@@ -538,7 +538,7 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
/// Send block import notifications.
fn send_import_notifications(&self) {
let info = self.client.info().expect("In-mem client does not fail");
let info = self.client.info();
let mut best_hash = self.best_hash.lock();
match *best_hash {
@@ -554,7 +554,7 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
/// Send block finalization notifications.
fn send_finality_notifications(&self) {
let info = self.client.info().expect("In-mem client does not fail");
let info = self.client.info();
let mut finalized_hash = self.finalized_hash.lock();
match *finalized_hash {
@@ -625,7 +625,7 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
pub fn generate_blocks<F>(&self, count: usize, origin: BlockOrigin, edit_block: F) -> H256
where F: FnMut(BlockBuilder<Block, PeersFullClient>) -> Block
{
let best_hash = self.client.info().unwrap().chain.best_hash;
let best_hash = self.client.info().chain.best_hash;
self.generate_blocks_at(BlockId::Hash(best_hash), count, origin, edit_block)
}
@@ -674,7 +674,7 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
/// Push blocks to the peer (simplified: with or without a TX)
pub fn push_blocks(&self, count: usize, with_tx: bool) -> H256 {
let best_hash = self.client.info().unwrap().chain.best_hash;
let best_hash = self.client.info().chain.best_hash;
self.push_blocks_at(BlockId::Hash(best_hash), count, with_tx)
}
+12 -12
View File
@@ -320,8 +320,8 @@ fn own_blocks_are_announced() {
net.peer(0).on_block_imported(header.hash(), &header);
net.sync();
assert_eq!(net.peer(0).client.as_in_memory_backend().blockchain().info().unwrap().best_number, 1);
assert_eq!(net.peer(1).client.as_in_memory_backend().blockchain().info().unwrap().best_number, 1);
assert_eq!(net.peer(0).client.as_in_memory_backend().blockchain().info().best_number, 1);
assert_eq!(net.peer(1).client.as_in_memory_backend().blockchain().info().best_number, 1);
let peer0_chain = net.peer(0).client.as_in_memory_backend().blockchain().clone();
assert!(net.peer(1).client.as_in_memory_backend().blockchain().canon_equals_to(&peer0_chain));
assert!(net.peer(2).client.as_in_memory_backend().blockchain().canon_equals_to(&peer0_chain));
@@ -356,9 +356,9 @@ fn blocks_are_not_announced_by_light_nodes() {
// peer 0 has the best chain
// peer 1 has the best chain
// peer 2 has genesis-chain only
assert_eq!(net.peer(0).client.info().unwrap().chain.best_number, 1);
assert_eq!(net.peer(1).client.info().unwrap().chain.best_number, 1);
assert_eq!(net.peer(2).client.info().unwrap().chain.best_number, 0);
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(2).client.info().chain.best_number, 0);
}
#[test]
@@ -371,13 +371,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().unwrap().chain.best_hash;
let small_hash = net.peer(0).client().info().chain.best_hash;
net.peer(0).push_blocks_at(BlockId::Number(30), 10, false);
assert_eq!(net.peer(0).client().info().unwrap().chain.best_number, 40);
assert_eq!(net.peer(0).client().info().chain.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().unwrap().chain.best_number, 40);
assert_eq!(net.peer(1).client().info().chain.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());
@@ -386,7 +386,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().unwrap().chain.best_number, 40);
assert_eq!(net.peer(0).client().info().chain.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());
@@ -416,8 +416,8 @@ fn can_not_sync_from_light_peer() {
net.sync();
// ensure #0 && #1 have the same best block
let full0_info = net.peer(0).client.info().unwrap().chain;
let light_info = net.peer(1).client.info().unwrap().chain;
let full0_info = net.peer(0).client.info().chain;
let light_info = net.peer(1).client.info().chain;
assert_eq!(full0_info.best_number, 1);
assert_eq!(light_info.best_number, 1);
assert_eq!(light_info.best_hash, full0_info.best_hash);
@@ -430,7 +430,7 @@ fn can_not_sync_from_light_peer() {
net.sync_with(true, Some(vec![0].into_iter().collect()));
// ensure that the #2 has failed to sync block #1
assert_eq!(net.peer(2).client.info().unwrap().chain.best_number, 0);
assert_eq!(net.peer(2).client.info().chain.best_number, 0);
// and that the #1 is still connected to #2
// (because #2 has not tried to fetch block data from the #1 light node)
assert_eq!(net.peer(1).protocol_status().num_peers, 2);