Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Refactor to use only chain info (#4516)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf authored and bkchr committed Jan 2, 2020
1 parent 20a9b15 commit 73049c0
Show file tree
Hide file tree
Showing 30 changed files with 178 additions and 175 deletions.
6 changes: 3 additions & 3 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ mod tests {
let keys: Vec<&ed25519::Pair> = vec![&*alice, &*bob];
let dummy_runtime = ::tokio::runtime::Runtime::new().unwrap();
let block_factory = |service: &<Factory as service::ServiceFactory>::FullService| {
let block_id = BlockId::number(service.client().info().chain.best_number);
let block_id = BlockId::number(service.client().chain_info().best_number);
let parent_header = service.client().header(&block_id).unwrap().unwrap();
let consensus_net = ConsensusNetwork::new(service.network(), service.client().clone());
let proposer_factory = consensus::ProposerFactory {
Expand Down Expand Up @@ -513,7 +513,7 @@ mod tests {
.expect("Creates inherent data.");
inherent_data.replace_data(sp_finality_tracker::INHERENT_IDENTIFIER, &1u64);

let parent_id = BlockId::number(service.client().info().chain.best_number);
let parent_id = BlockId::number(service.client().chain_info().best_number);
let parent_header = service.client().header(&parent_id).unwrap().unwrap();
let mut proposer_factory = sc_basic_authority::ProposerFactory {
client: service.client(),
Expand Down Expand Up @@ -580,7 +580,7 @@ mod tests {
let to: Address = AccountPublic::from(bob.public()).into_account().into();
let from: Address = AccountPublic::from(charlie.public()).into_account().into();
let genesis_hash = service.client().block_hash(0).unwrap().unwrap();
let best_block_id = BlockId::number(service.client().info().chain.best_number);
let best_block_id = BlockId::number(service.client().chain_info().best_number);
let version = service.client().runtime_version_at(&best_block_id).unwrap().spec_version;
let signer = charlie.clone();

Expand Down
4 changes: 2 additions & 2 deletions client/cli/src/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ pub fn build(service: &impl AbstractService) -> impl futures::Future<Output = ()
.network_status(Duration::from_millis(5000))
.compat()
.try_for_each(move |(net_status, _)| {
let info = client.info();
let info = client.usage_info();
display.display(&info, net_status);
future::ok(())
});

let client = service.client();
let mut last_best = {
let info = client.info();
let info = client.usage_info();
Some((info.chain.best_number, info.chain.best_hash))
};

Expand Down
2 changes: 1 addition & 1 deletion client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ mod tests {
fn authorities_call_works() {
let client = substrate_test_runtime_client::new();

assert_eq!(client.info().chain.best_number, 0);
assert_eq!(client.chain_info().best_number, 0);
assert_eq!(authorities(&client, &BlockId::Number(0)).unwrap(), vec![
Keyring::Alice.public().into(),
Keyring::Bob.public().into(),
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ impl<B, E, Block, I, RA, PRA> BlockImport<Block> for BabeBlockImport<B, E, Block
// this way we can revert it if there's any error
let mut old_epoch_changes = None;

let info = self.client.info().chain;
let info = self.client.chain_info();

if let Some(next_epoch_descriptor) = next_epoch_digest {
let next_epoch = epoch.increment(next_epoch_descriptor);
Expand Down Expand Up @@ -1104,7 +1104,7 @@ fn prune_finalized<B, E, Block, RA>(
B: Backend<Block, Blake2Hasher>,
RA: Send + Sync,
{
let info = client.info().chain;
let info = client.chain_info();

let finalized_slot = {
let finalized_header = client.header(&BlockId::Hash(info.finalized_hash))
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ fn importing_epoch_change_block_prunes_tree() {
// We finalize block #13 from the canon chain, so on the next epoch
// change the tree should be pruned, to not contain F (#7).
client.finalize_block(BlockId::Hash(canon_hashes[12]), None, false).unwrap();
propose_and_import_blocks(BlockId::Hash(client.info().chain.best_hash), 7);
propose_and_import_blocks(BlockId::Hash(client.chain_info().best_hash), 7);

// at this point no hashes from the first fork must exist on the tree
assert!(
Expand All @@ -725,7 +725,7 @@ fn importing_epoch_change_block_prunes_tree() {

// finalizing block #25 from the canon chain should prune out the second fork
client.finalize_block(BlockId::Hash(canon_hashes[24]), None, false).unwrap();
propose_and_import_blocks(BlockId::Hash(client.info().chain.best_hash), 8);
propose_and_import_blocks(BlockId::Hash(client.chain_info().best_hash), 8);

// at this point no hashes from the second fork must exist on the tree
assert!(
Expand Down
4 changes: 2 additions & 2 deletions client/finality-grandpa/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions client/finality-grandpa/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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))
Expand Down
16 changes: 8 additions & 8 deletions client/finality-grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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" => {
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions client/finality-grandpa/src/light_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion client/finality-grandpa/src/observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions client/finality-grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);


Expand Down Expand Up @@ -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 |_| {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 },
);
}
Expand Down Expand Up @@ -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,
);
Expand All @@ -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,
);
Expand All @@ -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,
);
Expand All @@ -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,
);
Expand All @@ -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,
);
Expand Down
10 changes: 5 additions & 5 deletions client/network/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
//! Blockchain access trait
use sc_client::Client as SubstrateClient;
use sp_blockchain::Error;
use sc_client_api::{ChangesProof, StorageProof, ClientInfo, CallExecutor};
use sp_blockchain::{Error, Info as BlockchainInfo};
use sc_client_api::{ChangesProof, StorageProof, CallExecutor};
use sp_consensus::{BlockImport, BlockStatus, Error as ConsensusError};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use sp_runtime::generic::{BlockId};
Expand All @@ -29,7 +29,7 @@ use sp_core::storage::{StorageKey, ChildInfo};
/// Local client abstraction for the network.
pub trait Client<Block: BlockT>: Send + Sync {
/// Get blockchain info.
fn info(&self) -> ClientInfo<Block>;
fn info(&self) -> BlockchainInfo<Block>;

/// Get block status.
fn block_status(&self, id: &BlockId<Block>) -> Result<BlockStatus, Error>;
Expand Down Expand Up @@ -99,8 +99,8 @@ impl<B, E, Block, RA> Client<Block> for SubstrateClient<B, E, Block, RA> where
Block: BlockT<Hash=H256>,
RA: Send + Sync
{
fn info(&self) -> ClientInfo<Block> {
(self as &SubstrateClient<B, E, Block, RA>).info()
fn info(&self) -> BlockchainInfo<Block> {
(self as &SubstrateClient<B, E, Block, RA>).chain_info()
}

fn block_status(&self, id: &BlockId<Block>) -> Result<BlockStatus, Error> {
Expand Down
Loading

0 comments on commit 73049c0

Please sign in to comment.