mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 23:21:02 +00:00
Client::info() no longer returns a Result (#2776)
This commit is contained in:
committed by
Bastian Köcher
parent
53e8ad8728
commit
5df89a8a6f
@@ -662,7 +662,7 @@ where
|
||||
|
||||
#[allow(deprecated)]
|
||||
let blockchain = self.inner.backend().blockchain();
|
||||
let status = blockchain.info()?;
|
||||
let status = blockchain.info();
|
||||
if number <= status.finalized_number && blockchain.hash(number)? == Some(hash) {
|
||||
// This can happen after a forced change (triggered by the finality tracker when finality is stalled), since
|
||||
// the voter will be restarted at the median last finalized block, which can be lower than the local best
|
||||
@@ -812,7 +812,7 @@ pub(crate) fn finalize_block<B, Block: BlockT<Hash=H256>, E, RA>(
|
||||
// finalization to remote nodes
|
||||
if !justification_required {
|
||||
if let Some(justification_period) = justification_period {
|
||||
let last_finalized_number = client.info()?.chain.finalized_number;
|
||||
let last_finalized_number = client.info().chain.finalized_number;
|
||||
justification_required =
|
||||
(!last_finalized_number.is_zero() || number - last_finalized_number == justification_period) &&
|
||||
(last_finalized_number / justification_period != number / justification_period);
|
||||
|
||||
@@ -268,7 +268,7 @@ pub(crate) fn prove_finality<Block: BlockT<Hash=H256>, B: BlockchainBackend<Bloc
|
||||
let begin_number = blockchain.expect_block_number_from_id(&begin_id)?;
|
||||
|
||||
// early-return if we sure that there are no blocks finalized AFTER begin block
|
||||
let info = blockchain.info()?;
|
||||
let info = blockchain.info();
|
||||
if info.finalized_number <= begin_number {
|
||||
trace!(
|
||||
target: "finality",
|
||||
|
||||
@@ -77,10 +77,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> JustificationImport<Block>
|
||||
type Error = ConsensusError;
|
||||
|
||||
fn on_start(&self, link: &::consensus_common::import_queue::Link<Block>) {
|
||||
let chain_info = match self.inner.info() {
|
||||
Ok(info) => info.chain,
|
||||
_ => return,
|
||||
};
|
||||
let chain_info = self.inner.info().chain;
|
||||
|
||||
// request justifications for all pending changes for which change blocks have already been imported
|
||||
let authorities = self.authority_set.inner().read();
|
||||
@@ -320,7 +317,6 @@ where
|
||||
|
||||
#[allow(deprecated)]
|
||||
let best_finalized_number = self.inner.backend().blockchain().info()
|
||||
.map_err(|e| ConsensusError::ClientImport(e.to_string()))?
|
||||
.finalized_number;
|
||||
|
||||
let canon_number = best_finalized_number.min(median_last_finalized_number);
|
||||
|
||||
@@ -316,7 +316,7 @@ where
|
||||
{
|
||||
use runtime_primitives::traits::Zero;
|
||||
|
||||
let chain_info = client.info()?;
|
||||
let chain_info = client.info();
|
||||
let genesis_hash = chain_info.chain.genesis_hash;
|
||||
|
||||
let persistent_data = aux_schema::load_persistent(
|
||||
@@ -431,15 +431,13 @@ fn register_finality_tracker_inherent_data_provider<B, E, Block: BlockT<Hash=H25
|
||||
inherent_data_providers
|
||||
.register_provider(srml_finality_tracker::InherentDataProvider::new(move || {
|
||||
#[allow(deprecated)]
|
||||
match client.backend().blockchain().info() {
|
||||
Err(e) => Err(std::borrow::Cow::Owned(e.to_string())),
|
||||
Ok(info) => {
|
||||
telemetry!(CONSENSUS_INFO; "afg.finalized";
|
||||
"finalized_number" => ?info.finalized_number,
|
||||
"finalized_hash" => ?info.finalized_hash,
|
||||
);
|
||||
Ok(info.finalized_number)
|
||||
},
|
||||
{
|
||||
let info = client.backend().blockchain().info();
|
||||
telemetry!(CONSENSUS_INFO; "afg.finalized";
|
||||
"finalized_number" => ?info.finalized_number,
|
||||
"finalized_hash" => ?info.finalized_hash,
|
||||
);
|
||||
Ok(info.finalized_number)
|
||||
}
|
||||
}))
|
||||
.map_err(|err| consensus_common::Error::InherentData(err.into()))
|
||||
@@ -579,10 +577,7 @@ pub fn run_grandpa_voter<B, E, Block: BlockT<Hash=H256>, N, RA, SC, X>(
|
||||
|
||||
let mut maybe_voter = match &*env.voter_set_state.read() {
|
||||
VoterSetState::Live { completed_rounds, .. } => {
|
||||
let chain_info = match client.info() {
|
||||
Ok(i) => i,
|
||||
Err(e) => return future::Either::B(future::err(Error::Client(e))),
|
||||
};
|
||||
let chain_info = client.info();
|
||||
|
||||
let last_finalized = (
|
||||
chain_info.chain.finalized_hash,
|
||||
@@ -691,7 +686,7 @@ pub fn run_grandpa_voter<B, E, Block: BlockT<Hash=H256>, N, RA, SC, X>(
|
||||
}
|
||||
};
|
||||
|
||||
future::Either::A(poll_voter.select2(voter_commands_rx).then(move |res| match res {
|
||||
poll_voter.select2(voter_commands_rx).then(move |res| match res {
|
||||
Ok(future::Either::A(((), _))) => {
|
||||
// voters don't conclude naturally; this could reasonably be an error.
|
||||
Ok(FutureLoop::Break(()))
|
||||
@@ -716,7 +711,7 @@ pub fn run_grandpa_voter<B, E, Block: BlockT<Hash=H256>, N, RA, SC, X>(
|
||||
// some command issued internally.
|
||||
handle_voter_command(command, voter_commands_rx)
|
||||
},
|
||||
}))
|
||||
})
|
||||
});
|
||||
|
||||
let voter_work = voter_work
|
||||
|
||||
@@ -63,7 +63,7 @@ pub fn light_block_import<B, E, Block: BlockT<Hash=H256>, RA, PRA>(
|
||||
PRA: ProvideRuntimeApi,
|
||||
PRA::Api: GrandpaApi<Block>,
|
||||
{
|
||||
let info = client.info()?;
|
||||
let info = client.info();
|
||||
#[allow(deprecated)]
|
||||
let import_data = load_aux_import_data(info.chain.finalized_hash, &**client.backend(), api)?;
|
||||
Ok(GrandpaLightBlockImport {
|
||||
@@ -145,10 +145,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> FinalityProofImport<Block>
|
||||
type Error = ConsensusError;
|
||||
|
||||
fn on_start(&self, link: &::consensus_common::import_queue::Link<Block>) {
|
||||
let chain_info = match self.client.info() {
|
||||
Ok(info) => info.chain,
|
||||
_ => return,
|
||||
};
|
||||
let chain_info = self.client.info().chain;
|
||||
|
||||
let data = self.data.read();
|
||||
for (pending_number, pending_hash) in data.consensus_changes.pending_changes() {
|
||||
@@ -620,7 +617,7 @@ pub mod tests {
|
||||
origin: BlockOrigin::Own,
|
||||
header: Header {
|
||||
number: 1,
|
||||
parent_hash: client.info().unwrap().chain.best_hash,
|
||||
parent_hash: client.info().chain.best_hash,
|
||||
state_root: Default::default(),
|
||||
digest: Default::default(),
|
||||
extrinsics_root: Default::default(),
|
||||
|
||||
@@ -31,7 +31,7 @@ use substrate_primitives::{ed25519::Public as AuthorityId, H256, Blake2Hasher};
|
||||
|
||||
use crate::{
|
||||
AuthoritySignature, global_communication, CommandOrError, Config, environment,
|
||||
Error, LinkHalf, Network, aux_schema::PersistentData, VoterCommand, VoterSetState,
|
||||
LinkHalf, Network, aux_schema::PersistentData, VoterCommand, VoterSetState,
|
||||
};
|
||||
use crate::authorities::SharedAuthoritySet;
|
||||
use crate::communication::NetworkBridge;
|
||||
@@ -191,12 +191,7 @@ pub fn run_grandpa_observer<B, E, Block: BlockT<Hash=H256>, N, RA, SC>(
|
||||
&network,
|
||||
);
|
||||
|
||||
let chain_info = match client.info() {
|
||||
Ok(i) => i,
|
||||
Err(e) => return future::Either::B(future::err(Error::Client(e))),
|
||||
};
|
||||
|
||||
let last_finalized_number = chain_info.chain.finalized_number;
|
||||
let last_finalized_number = client.info().chain.finalized_number;
|
||||
|
||||
// create observer for the current set
|
||||
let observer = grandpa_observer(
|
||||
@@ -250,7 +245,7 @@ pub fn run_grandpa_observer<B, E, Block: BlockT<Hash=H256>, N, RA, SC>(
|
||||
};
|
||||
|
||||
// run observer and listen to commands (switch authorities or pause)
|
||||
future::Either::A(observer.select2(voter_commands_rx).then(move |res| match res {
|
||||
observer.select2(voter_commands_rx).then(move |res| match res {
|
||||
Ok(future::Either::A((_, _))) => {
|
||||
// observer commit stream doesn't conclude naturally; this could reasonably be an error.
|
||||
Ok(FutureLoop::Break(()))
|
||||
@@ -275,7 +270,7 @@ pub fn run_grandpa_observer<B, E, Block: BlockT<Hash=H256>, N, RA, SC>(
|
||||
// some command issued internally
|
||||
handle_voter_command(command, voter_commands_rx)
|
||||
},
|
||||
}))
|
||||
})
|
||||
});
|
||||
|
||||
let observer_work = observer_work
|
||||
|
||||
@@ -561,7 +561,7 @@ fn finalize_3_voters_no_observers() {
|
||||
net.sync();
|
||||
|
||||
for i in 0..3 {
|
||||
assert_eq!(net.peer(i).client().info().unwrap().chain.best_number, 20,
|
||||
assert_eq!(net.peer(i).client().info().chain.best_number, 20,
|
||||
"Peer #{} failed to sync", i);
|
||||
}
|
||||
|
||||
@@ -673,7 +673,7 @@ fn transition_3_voters_twice_1_full_observer() {
|
||||
|
||||
for (i, peer) in net.lock().peers().iter().enumerate() {
|
||||
let full_client = peer.client().as_full().expect("only full clients are used in test");
|
||||
assert_eq!(full_client.info().unwrap().chain.best_number, 1,
|
||||
assert_eq!(full_client.info().chain.best_number, 1,
|
||||
"Peer #{} failed to sync", i);
|
||||
|
||||
let set: AuthoritySet<Hash, BlockNumber> = crate::aux_schema::load_authorities(
|
||||
@@ -895,7 +895,7 @@ fn sync_justifications_on_change_blocks() {
|
||||
net.sync();
|
||||
|
||||
for i in 0..4 {
|
||||
assert_eq!(net.peer(i).client().info().unwrap().chain.best_number, 25,
|
||||
assert_eq!(net.peer(i).client().info().chain.best_number, 25,
|
||||
"Peer #{} failed to sync", i);
|
||||
}
|
||||
|
||||
@@ -966,7 +966,7 @@ fn finalizes_multiple_pending_changes_in_order() {
|
||||
|
||||
// all peers imported both change blocks
|
||||
for i in 0..6 {
|
||||
assert_eq!(net.peer(i).client().info().unwrap().chain.best_number, 30,
|
||||
assert_eq!(net.peer(i).client().info().chain.best_number, 30,
|
||||
"Peer #{} failed to sync", i);
|
||||
}
|
||||
|
||||
@@ -986,7 +986,7 @@ fn doesnt_vote_on_the_tip_of_the_chain() {
|
||||
net.sync();
|
||||
|
||||
for i in 0..3 {
|
||||
assert_eq!(net.peer(i).client().info().unwrap().chain.best_number, 100,
|
||||
assert_eq!(net.peer(i).client().info().chain.best_number, 100,
|
||||
"Peer #{} failed to sync", i);
|
||||
}
|
||||
|
||||
@@ -1016,7 +1016,7 @@ fn force_change_to_new_set() {
|
||||
|
||||
{
|
||||
// add a forced transition at block 12.
|
||||
let parent_hash = net.lock().peer(0).client().info().unwrap().chain.best_hash;
|
||||
let parent_hash = net.lock().peer(0).client().info().chain.best_hash;
|
||||
forced_transitions.lock().insert(parent_hash, (0, ScheduledChange {
|
||||
next_authorities: voters.clone(),
|
||||
delay: 10,
|
||||
@@ -1033,7 +1033,7 @@ fn force_change_to_new_set() {
|
||||
net.lock().sync();
|
||||
|
||||
for (i, peer) in net.lock().peers().iter().enumerate() {
|
||||
assert_eq!(peer.client().info().unwrap().chain.best_number, 26,
|
||||
assert_eq!(peer.client().info().chain.best_number, 26,
|
||||
"Peer #{} failed to sync", i);
|
||||
|
||||
let full_client = peer.client().as_full().expect("only full clients are used in test");
|
||||
@@ -1172,7 +1172,7 @@ fn voter_persists_its_votes() {
|
||||
net.peer(0).push_blocks(20, false);
|
||||
net.sync();
|
||||
|
||||
assert_eq!(net.peer(0).client().info().unwrap().chain.best_number, 20,
|
||||
assert_eq!(net.peer(0).client().info().chain.best_number, 20,
|
||||
"Peer #{} failed to sync", 0);
|
||||
|
||||
let mut runtime = current_thread::Runtime::new().unwrap();
|
||||
@@ -1289,7 +1289,7 @@ fn voter_persists_its_votes() {
|
||||
net.lock().peer(0).push_blocks(20, false);
|
||||
net.lock().sync();
|
||||
|
||||
assert_eq!(net.lock().peer(0).client().info().unwrap().chain.best_number, 40,
|
||||
assert_eq!(net.lock().peer(0).client().info().chain.best_number, 40,
|
||||
"Peer #{} failed to sync", 0);
|
||||
|
||||
#[allow(deprecated)]
|
||||
@@ -1366,7 +1366,7 @@ fn finalize_3_voters_1_light_observer() {
|
||||
net.sync();
|
||||
|
||||
for i in 0..4 {
|
||||
assert_eq!(net.peer(i).client().info().unwrap().chain.best_number, 20,
|
||||
assert_eq!(net.peer(i).client().info().chain.best_number, 20,
|
||||
"Peer #{} failed to sync", i);
|
||||
}
|
||||
|
||||
@@ -1412,7 +1412,7 @@ fn finality_proof_is_fetched_by_light_client_when_consensus_data_changes() {
|
||||
net.lock().sync_without_disconnects();
|
||||
|
||||
// check that the block#1 is finalized on light client
|
||||
while net.lock().peer(1).client().info().unwrap().chain.finalized_number != 1 {
|
||||
while net.lock().peer(1).client().info().chain.finalized_number != 1 {
|
||||
net.lock().tick_peer(1);
|
||||
net.lock().sync_without_disconnects();
|
||||
}
|
||||
@@ -1455,7 +1455,7 @@ fn empty_finality_proof_is_returned_to_light_client_when_authority_set_is_differ
|
||||
|
||||
// add a forced transition at block 5.
|
||||
if FORCE_CHANGE {
|
||||
let parent_hash = net.lock().peer(0).client().info().unwrap().chain.best_hash;
|
||||
let parent_hash = net.lock().peer(0).client().info().chain.best_hash;
|
||||
forced_transitions.lock().insert(parent_hash, (0, ScheduledChange {
|
||||
next_authorities: voters.clone(),
|
||||
delay: 3,
|
||||
@@ -1482,7 +1482,7 @@ fn empty_finality_proof_is_returned_to_light_client_when_authority_set_is_differ
|
||||
|
||||
// check block, finalized on light client
|
||||
assert_eq!(
|
||||
runner_net.lock().peer(3).client().info().unwrap().chain.finalized_number,
|
||||
runner_net.lock().peer(3).client().info().chain.finalized_number,
|
||||
if FORCE_CHANGE { 0 } else { 10 },
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user