Refactor to use only chain info (#4516)

This commit is contained in:
Nikolay Volf
2020-01-02 14:46:07 +03:00
committed by Bastian Köcher
parent 8ecc450fd9
commit 6d06a19f41
30 changed files with 178 additions and 175 deletions
@@ -964,7 +964,7 @@ pub(crate) fn finalize_block<B, Block: BlockT<Hash=H256>, E, RA>(
// below.
let mut authority_set = authority_set.inner().write();
let status = client.info().chain;
let status = client.chain_info();
if number <= status.finalized_number && client.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
@@ -1037,7 +1037,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.chain_info().finalized_number;
justification_required =
(!last_finalized_number.is_zero() || number - last_finalized_number == justification_period) &&
(last_finalized_number / justification_period != number / justification_period);
@@ -87,7 +87,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, SC> JustificationImport<Block>
fn on_start(&mut self) -> Vec<(Block::Hash, NumberFor<Block>)> {
let mut out = Vec::new();
let chain_info = self.inner.info().chain;
let chain_info = self.inner.chain_info();
// request justifications for all pending changes for which change blocks have already been imported
let authorities = self.authority_set.inner().read();
@@ -324,7 +324,7 @@ where
// for the canon block the new authority set should start
// with. we use the minimum between the median and the local
// best finalized block.
let best_finalized_number = self.inner.info().chain.finalized_number;
let best_finalized_number = self.inner.chain_info().finalized_number;
let canon_number = best_finalized_number.min(median_last_finalized_number);
let canon_hash =
self.inner.header(&BlockId::Number(canon_number))
+8 -8
View File
@@ -411,8 +411,8 @@ where
RA: Send + Sync,
SC: SelectChain<Block>,
{
let chain_info = client.info();
let genesis_hash = chain_info.chain.genesis_hash;
let chain_info = client.chain_info();
let genesis_hash = chain_info.genesis_hash;
let persistent_data = aux_schema::load_persistent(
&*client,
@@ -507,7 +507,7 @@ fn register_finality_tracker_inherent_data_provider<B, E, Block: BlockT<Hash=H25
.register_provider(sp_finality_tracker::InherentDataProvider::new(move || {
#[allow(deprecated)]
{
let info = client.info().chain;
let info = client.chain_info();
telemetry!(CONSENSUS_INFO; "afg.finalized";
"finalized_number" => ?info.finalized_number,
"finalized_hash" => ?info.finalized_hash,
@@ -710,10 +710,10 @@ where
"authority_id" => authority_id.to_string(),
);
let chain_info = self.env.client.info();
let chain_info = self.env.client.chain_info();
telemetry!(CONSENSUS_INFO; "afg.authority_set";
"number" => ?chain_info.chain.finalized_number,
"hash" => ?chain_info.chain.finalized_hash,
"number" => ?chain_info.finalized_number,
"hash" => ?chain_info.finalized_hash,
"authority_id" => authority_id.to_string(),
"authority_set_id" => ?self.env.set_id,
"authorities" => {
@@ -727,8 +727,8 @@ where
match &*self.env.voter_set_state.read() {
VoterSetState::Live { completed_rounds, .. } => {
let last_finalized = (
chain_info.chain.finalized_hash,
chain_info.chain.finalized_number,
chain_info.finalized_hash,
chain_info.finalized_number,
);
let global_comms = global_communication(
@@ -62,7 +62,7 @@ pub fn light_block_import<B, E, Block: BlockT<Hash=H256>, RA>(
{
let info = client.info();
let import_data = load_aux_import_data(
info.chain.finalized_hash,
info.finalized_hash,
&*client,
genesis_authorities_provider,
)?;
@@ -158,7 +158,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> FinalityProofImport<Block>
fn on_start(&mut self) -> Vec<(Block::Hash, NumberFor<Block>)> {
let mut out = Vec::new();
let chain_info = self.client.info().chain;
let chain_info = self.client.chain_info();
let data = self.data.read();
for (pending_number, pending_hash) in data.consensus_changes.pending_changes() {
@@ -647,7 +647,7 @@ pub mod tests {
origin: BlockOrigin::Own,
header: Header {
number: 1,
parent_hash: client.info().chain.best_hash,
parent_hash: client.chain_info().best_hash,
state_root: Default::default(),
digest: Default::default(),
extrinsics_root: Default::default(),
@@ -258,7 +258,7 @@ where
&self.keystore,
);
let last_finalized_number = self.client.info().chain.finalized_number;
let last_finalized_number = self.client.chain_info().finalized_number;
// NOTE: since we are not using `round_communication` we have to
// manually note the round with the gossip validator, otherwise we won't
+16 -16
View File
@@ -469,7 +469,7 @@ fn finalize_3_voters_no_observers() {
net.block_until_sync(&mut runtime);
for i in 0..3 {
assert_eq!(net.peer(i).client().info().chain.best_number, 20,
assert_eq!(net.peer(i).client().info().best_number, 20,
"Peer #{} failed to sync", i);
}
@@ -602,7 +602,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().chain.best_number, 1,
assert_eq!(full_client.chain_info().best_number, 1,
"Peer #{} failed to sync", i);
let set: AuthoritySet<Hash, BlockNumber> = crate::aux_schema::load_authorities(&*full_client).unwrap();
@@ -821,7 +821,7 @@ fn sync_justifications_on_change_blocks() {
net.block_until_sync(&mut runtime);
for i in 0..4 {
assert_eq!(net.peer(i).client().info().chain.best_number, 25,
assert_eq!(net.peer(i).client().info().best_number, 25,
"Peer #{} failed to sync", i);
}
@@ -898,7 +898,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().chain.best_number, 30,
assert_eq!(net.peer(i).client().info().best_number, 30,
"Peer #{} failed to sync", i);
}
@@ -948,7 +948,7 @@ fn force_change_to_new_set() {
net.lock().block_until_sync(&mut runtime);
for (i, peer) in net.lock().peers().iter().enumerate() {
assert_eq!(peer.client().info().chain.best_number, 26,
assert_eq!(peer.client().info().best_number, 26,
"Peer #{} failed to sync", i);
let full_client = peer.client().as_full().expect("only full clients are used in test");
@@ -1091,7 +1091,7 @@ fn voter_persists_its_votes() {
net.peer(0).push_blocks(20, false);
net.block_until_sync(&mut runtime);
assert_eq!(net.peer(0).client().info().chain.best_number, 20,
assert_eq!(net.peer(0).client().info().best_number, 20,
"Peer #{} failed to sync", 0);
@@ -1265,7 +1265,7 @@ fn voter_persists_its_votes() {
future::Either::A(interval
.take_while(move |_| {
Ok(net2.lock().peer(1).client().info().chain.best_number != 40)
Ok(net2.lock().peer(1).client().info().best_number != 40)
})
.for_each(|_| Ok(()))
.and_then(move |_| {
@@ -1342,7 +1342,7 @@ fn finalize_3_voters_1_light_observer() {
net.block_until_sync(&mut runtime);
for i in 0..4 {
assert_eq!(net.peer(i).client().info().chain.best_number, 20,
assert_eq!(net.peer(i).client().info().best_number, 20,
"Peer #{} failed to sync", i);
}
@@ -1395,7 +1395,7 @@ fn finality_proof_is_fetched_by_light_client_when_consensus_data_changes() {
// check that the block#1 is finalized on light client
runtime.block_on(futures::future::poll_fn(move || -> std::result::Result<_, ()> {
if net.lock().peer(1).client().info().chain.finalized_number == 1 {
if net.lock().peer(1).client().info().finalized_number == 1 {
Ok(Async::Ready(()))
} else {
net.lock().poll();
@@ -1467,7 +1467,7 @@ fn empty_finality_proof_is_returned_to_light_client_when_authority_set_is_differ
// check block, finalized on light client
assert_eq!(
net.lock().peer(3).client().info().chain.finalized_number,
net.lock().peer(3).client().info().finalized_number,
if FORCE_CHANGE { 0 } else { 10 },
);
}
@@ -1662,7 +1662,7 @@ fn grandpa_environment_respects_voting_rules() {
// the unrestricted environment should just return the best block
assert_eq!(
unrestricted_env.best_chain_containing(
peer.client().info().chain.finalized_hash
peer.client().info().finalized_hash
).unwrap().1,
20,
);
@@ -1671,14 +1671,14 @@ fn grandpa_environment_respects_voting_rules() {
// way in the unfinalized chain
assert_eq!(
three_quarters_env.best_chain_containing(
peer.client().info().chain.finalized_hash
peer.client().info().finalized_hash
).unwrap().1,
15,
);
assert_eq!(
default_env.best_chain_containing(
peer.client().info().chain.finalized_hash
peer.client().info().finalized_hash
).unwrap().1,
15,
);
@@ -1689,7 +1689,7 @@ fn grandpa_environment_respects_voting_rules() {
// the 3/4 environment should propose block 20 for voting
assert_eq!(
three_quarters_env.best_chain_containing(
peer.client().info().chain.finalized_hash
peer.client().info().finalized_hash
).unwrap().1,
20,
);
@@ -1698,7 +1698,7 @@ fn grandpa_environment_respects_voting_rules() {
// on the best block
assert_eq!(
default_env.best_chain_containing(
peer.client().info().chain.finalized_hash
peer.client().info().finalized_hash
).unwrap().1,
19,
);
@@ -1711,7 +1711,7 @@ fn grandpa_environment_respects_voting_rules() {
// the given base (#20).
assert_eq!(
default_env.best_chain_containing(
peer.client().info().chain.finalized_hash
peer.client().info().finalized_hash
).unwrap().1,
20,
);