mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 20:31:04 +00:00
Remove client.backend (#2960)
* generalize tree_root to remove client.backend dependency * replace client.backend.blockchain.header with client.header * move used_state_cache_size into client info * Create intermediate Setup State. Fixes #1134 * remove client.backend from finality proof * update node-template * move memory backend into test helper mode * move test helper into client * starting the big refactor, remove unused functions * apply_finality * apply_finality * replacing more .backend from environment with client directly * remove .backend from grandpa by using traits * remove .backend from babe * remove .backend from tests where it is not needed * remove .backend from tests * fixing tests * fixing tests * fixing more tests * fixing tests * fix all forks test * fix style * fixing unnecessary allocation * remove old test. * fix service docs * apply suggestion * minor clean ups * turns out the test-helper features actually is being used! * fixing line length. * fix line length * minor cleaning * Apply suggestions from code review thanks, @Basti Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * address grumbles * simplify finalize block on client * move block back into inner function * Apply suggestions from code review Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com> * use as.ref instead of match * Update core/client/src/backend.rs Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
26202c66f7
commit
0cae7217d8
@@ -26,8 +26,9 @@ use tokio_timer::Delay;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use client::{
|
||||
backend::Backend, BlockchainEvents, CallExecutor, Client, error::Error as ClientError,
|
||||
utils::is_descendent_of,
|
||||
backend::Backend, apply_aux, BlockchainEvents, CallExecutor,
|
||||
Client, error::Error as ClientError, utils::is_descendent_of,
|
||||
blockchain::HeaderBackend, backend::Finalizer,
|
||||
};
|
||||
use grandpa::{
|
||||
BlockNumberOps, Equivocation, Error as GrandpaError, round::State as RoundState,
|
||||
@@ -498,8 +499,7 @@ pub(crate) fn ancestry<B, Block: BlockT<Hash=H256>, E, RA>(
|
||||
if base == block { return Err(GrandpaError::NotDescendent) }
|
||||
|
||||
let tree_route_res = ::client::blockchain::tree_route(
|
||||
#[allow(deprecated)]
|
||||
client.backend().blockchain(),
|
||||
|id| client.header(&id)?.ok_or(client::error::Error::UnknownBlock(format!("{:?}", id))),
|
||||
BlockId::Hash(block),
|
||||
BlockId::Hash(base),
|
||||
);
|
||||
@@ -632,8 +632,7 @@ where
|
||||
current_rounds,
|
||||
};
|
||||
|
||||
#[allow(deprecated)]
|
||||
crate::aux_schema::write_voter_set_state(&**self.inner.backend(), &set_state)?;
|
||||
crate::aux_schema::write_voter_set_state(&*self.inner, &set_state)?;
|
||||
|
||||
Ok(Some(set_state))
|
||||
})?;
|
||||
@@ -674,8 +673,7 @@ where
|
||||
current_rounds,
|
||||
};
|
||||
|
||||
#[allow(deprecated)]
|
||||
crate::aux_schema::write_voter_set_state(&**self.inner.backend(), &set_state)?;
|
||||
crate::aux_schema::write_voter_set_state(&*self.inner, &set_state)?;
|
||||
|
||||
Ok(Some(set_state))
|
||||
})?;
|
||||
@@ -726,8 +724,7 @@ where
|
||||
current_rounds,
|
||||
};
|
||||
|
||||
#[allow(deprecated)]
|
||||
crate::aux_schema::write_voter_set_state(&**self.inner.backend(), &set_state)?;
|
||||
crate::aux_schema::write_voter_set_state(&*self.inner, &set_state)?;
|
||||
|
||||
Ok(Some(set_state))
|
||||
})?;
|
||||
@@ -785,8 +782,7 @@ where
|
||||
current_rounds,
|
||||
};
|
||||
|
||||
#[allow(deprecated)]
|
||||
crate::aux_schema::write_voter_set_state(&**self.inner.backend(), &set_state)?;
|
||||
crate::aux_schema::write_voter_set_state(&*self.inner, &set_state)?;
|
||||
|
||||
Ok(Some(set_state))
|
||||
})?;
|
||||
@@ -875,24 +871,15 @@ pub(crate) fn finalize_block<B, Block: BlockT<Hash=H256>, E, RA>(
|
||||
E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
|
||||
RA: Send + Sync,
|
||||
{
|
||||
use client::blockchain::HeaderBackend;
|
||||
|
||||
#[allow(deprecated)]
|
||||
let blockchain = client.backend().blockchain();
|
||||
let info = blockchain.info();
|
||||
if number <= info.finalized_number && blockchain.hash(number)? == Some(hash) {
|
||||
// We might have a race condition on finality, since we can finalize
|
||||
// through either sync (import justification) or through grandpa gossip.
|
||||
// so let's make sure that this finalization request is no longer stale.
|
||||
// This can also 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 finalized block.
|
||||
warn!(target: "afg",
|
||||
"Re-finalized block #{:?} ({:?}) in the canonical chain, current best finalized is #{:?}",
|
||||
hash,
|
||||
number,
|
||||
info.finalized_number,
|
||||
let status = client.info().chain;
|
||||
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
|
||||
// finalized block.
|
||||
warn!(target: "afg", "Re-finalized block #{:?} ({:?}) in the canonical chain, current best finalized is #{:?}",
|
||||
hash,
|
||||
number,
|
||||
status.finalized_number,
|
||||
);
|
||||
|
||||
return Ok(());
|
||||
@@ -929,7 +916,7 @@ pub(crate) fn finalize_block<B, Block: BlockT<Hash=H256>, E, RA>(
|
||||
|
||||
let write_result = crate::aux_schema::update_consensus_changes(
|
||||
&*consensus_changes,
|
||||
|insert| client.apply_aux(import_op, insert, &[]),
|
||||
|insert| apply_aux(import_op, insert, &[]),
|
||||
);
|
||||
|
||||
if let Err(e) = write_result {
|
||||
@@ -1022,7 +1009,7 @@ pub(crate) fn finalize_block<B, Block: BlockT<Hash=H256>, E, RA>(
|
||||
let write_result = crate::aux_schema::update_authority_set::<Block, _, _>(
|
||||
&authority_set,
|
||||
new_authorities.as_ref(),
|
||||
|insert| client.apply_aux(import_op, insert, &[]),
|
||||
|insert| apply_aux(import_op, insert, &[]),
|
||||
);
|
||||
|
||||
if let Err(e) = write_result {
|
||||
@@ -1053,15 +1040,12 @@ pub(crate) fn finalize_block<B, Block: BlockT<Hash=H256>, E, RA>(
|
||||
|
||||
/// Using the given base get the block at the given height on this chain. The
|
||||
/// target block must be an ancestor of base, therefore `height <= base.height`.
|
||||
pub(crate) fn canonical_at_height<B, E, Block: BlockT<Hash=H256>, RA>(
|
||||
client: &Client<B, E, Block, RA>,
|
||||
pub(crate) fn canonical_at_height<Block: BlockT<Hash=H256>, C: HeaderBackend<Block>>(
|
||||
provider: C,
|
||||
base: (Block::Hash, NumberFor<Block>),
|
||||
base_is_canonical: bool,
|
||||
height: NumberFor<Block>,
|
||||
) -> Result<Option<Block::Hash>, ClientError> where
|
||||
B: Backend<Block, Blake2Hasher>,
|
||||
E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
|
||||
{
|
||||
) -> Result<Option<Block::Hash>, ClientError> {
|
||||
if height > base.1 {
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -1070,17 +1054,17 @@ pub(crate) fn canonical_at_height<B, E, Block: BlockT<Hash=H256>, RA>(
|
||||
if base_is_canonical {
|
||||
return Ok(Some(base.0));
|
||||
} else {
|
||||
return Ok(client.block_hash(height).unwrap_or(None));
|
||||
return Ok(provider.hash(height).unwrap_or(None));
|
||||
}
|
||||
} else if base_is_canonical {
|
||||
return Ok(client.block_hash(height).unwrap_or(None));
|
||||
return Ok(provider.hash(height).unwrap_or(None));
|
||||
}
|
||||
|
||||
let one = NumberFor::<Block>::one();
|
||||
|
||||
// start by getting _canonical_ block with number at parent position and then iterating
|
||||
// backwards by hash.
|
||||
let mut current = match client.header(&BlockId::Number(base.1 - one))? {
|
||||
let mut current = match provider.header(BlockId::Number(base.1 - one))? {
|
||||
Some(header) => header,
|
||||
_ => return Ok(None),
|
||||
};
|
||||
@@ -1089,7 +1073,7 @@ pub(crate) fn canonical_at_height<B, E, Block: BlockT<Hash=H256>, RA>(
|
||||
let mut steps = base.1 - height - one;
|
||||
|
||||
while steps > NumberFor::<Block>::zero() {
|
||||
current = match client.header(&BlockId::Hash(*current.parent_hash()))? {
|
||||
current = match provider.header(BlockId::Hash(*current.parent_hash()))? {
|
||||
Some(header) => header,
|
||||
_ => return Ok(None),
|
||||
};
|
||||
|
||||
@@ -130,36 +130,31 @@ impl<Block: BlockT> AuthoritySetForFinalityChecker<Block> for Arc<dyn FetchCheck
|
||||
}
|
||||
|
||||
/// Finality proof provider for serving network requests.
|
||||
pub struct FinalityProofProvider<B, E, Block: BlockT<Hash=H256>, RA> {
|
||||
client: Arc<Client<B, E, Block, RA>>,
|
||||
pub struct FinalityProofProvider<B, Block: BlockT<Hash=H256>> {
|
||||
backend: Arc<B>,
|
||||
authority_provider: Arc<dyn AuthoritySetForFinalityProver<Block>>,
|
||||
}
|
||||
|
||||
impl<B, E, Block: BlockT<Hash=H256>, RA> FinalityProofProvider<B, E, Block, RA>
|
||||
where
|
||||
B: Backend<Block, Blake2Hasher> + Send + Sync + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
RA: Send + Sync,
|
||||
impl<B, Block: BlockT<Hash=H256>> FinalityProofProvider<B, Block>
|
||||
where B: Backend<Block, Blake2Hasher> + Send + Sync + 'static
|
||||
{
|
||||
/// Create new finality proof provider using:
|
||||
///
|
||||
/// - client for accessing blockchain data;
|
||||
/// - backend for accessing blockchain data;
|
||||
/// - authority_provider for calling and proving runtime methods.
|
||||
pub fn new(
|
||||
client: Arc<Client<B, E, Block, RA>>,
|
||||
backend: Arc<B>,
|
||||
authority_provider: Arc<dyn AuthoritySetForFinalityProver<Block>>,
|
||||
) -> Self {
|
||||
FinalityProofProvider { client, authority_provider }
|
||||
FinalityProofProvider { backend, authority_provider }
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, E, Block, RA> network::FinalityProofProvider<Block> for FinalityProofProvider<B, E, Block, RA>
|
||||
impl<B, Block> network::FinalityProofProvider<Block> for FinalityProofProvider<B, Block>
|
||||
where
|
||||
Block: BlockT<Hash=H256>,
|
||||
NumberFor<Block>: BlockNumberOps,
|
||||
B: Backend<Block, Blake2Hasher> + Send + Sync + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
RA: Send + Sync,
|
||||
{
|
||||
fn prove_finality(
|
||||
&self,
|
||||
@@ -173,8 +168,7 @@ impl<B, E, Block, RA> network::FinalityProofProvider<Block> for FinalityProofPro
|
||||
})?;
|
||||
match request {
|
||||
FinalityProofRequest::Original(request) => prove_finality::<_, _, GrandpaJustification<Block>>(
|
||||
#[allow(deprecated)]
|
||||
&*self.client.backend().blockchain(),
|
||||
&*self.backend.blockchain(),
|
||||
&*self.authority_provider,
|
||||
request.authorities_set_id,
|
||||
request.last_finalized,
|
||||
|
||||
@@ -333,16 +333,10 @@ 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.
|
||||
|
||||
#[allow(deprecated)]
|
||||
let best_finalized_number = self.inner.backend().blockchain().info()
|
||||
.finalized_number;
|
||||
|
||||
let best_finalized_number = self.inner.info().chain.finalized_number;
|
||||
let canon_number = best_finalized_number.min(median_last_finalized_number);
|
||||
|
||||
#[allow(deprecated)]
|
||||
let canon_hash =
|
||||
self.inner.backend().blockchain().header(BlockId::Number(canon_number))
|
||||
self.inner.header(&BlockId::Number(canon_number))
|
||||
.map_err(|e| ConsensusError::ClientImport(e.to_string()))?
|
||||
.expect("the given block number is less or equal than the current best finalized number; \
|
||||
current best finalized number must exist in chain; qed.")
|
||||
@@ -414,8 +408,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> BlockImport<Block>
|
||||
|
||||
// early exit if block already in chain, otherwise the check for
|
||||
// authority changes will error when trying to re-import a change block
|
||||
#[allow(deprecated)]
|
||||
match self.inner.backend().blockchain().status(BlockId::Hash(hash)) {
|
||||
match self.inner.status(BlockId::Hash(hash)) {
|
||||
Ok(blockchain::BlockStatus::InChain) => return Ok(ImportResult::AlreadyInChain),
|
||||
Ok(blockchain::BlockStatus::Unknown) => {},
|
||||
Err(e) => return Err(ConsensusError::ClientImport(e.to_string()).into()),
|
||||
|
||||
@@ -18,7 +18,6 @@ use std::collections::{HashMap, HashSet};
|
||||
|
||||
use client::{CallExecutor, Client};
|
||||
use client::backend::Backend;
|
||||
use client::blockchain::HeaderBackend;
|
||||
use client::error::Error as ClientError;
|
||||
use codec::{Encode, Decode};
|
||||
use grandpa::voter_set::VoterSet;
|
||||
@@ -71,8 +70,7 @@ impl<Block: BlockT<Hash=H256>> GrandpaJustification<Block> {
|
||||
loop {
|
||||
if current_hash == commit.target_hash { break; }
|
||||
|
||||
#[allow(deprecated)]
|
||||
match client.backend().blockchain().header(BlockId::Hash(current_hash))? {
|
||||
match client.header(&BlockId::Hash(current_hash))? {
|
||||
Some(current_header) => {
|
||||
if *current_header.number() <= commit.target_number {
|
||||
return error();
|
||||
|
||||
@@ -359,8 +359,7 @@ where
|
||||
let genesis_hash = chain_info.chain.genesis_hash;
|
||||
|
||||
let persistent_data = aux_schema::load_persistent(
|
||||
#[allow(deprecated)]
|
||||
&**client.backend(),
|
||||
&*client,
|
||||
genesis_hash,
|
||||
<NumberFor<Block>>::zero(),
|
||||
|| {
|
||||
@@ -452,7 +451,7 @@ fn register_finality_tracker_inherent_data_provider<B, E, Block: BlockT<Hash=H25
|
||||
.register_provider(srml_finality_tracker::InherentDataProvider::new(move || {
|
||||
#[allow(deprecated)]
|
||||
{
|
||||
let info = client.backend().blockchain().info();
|
||||
let info = client.info().chain;
|
||||
telemetry!(CONSENSUS_INFO; "afg.finalized";
|
||||
"finalized_number" => ?info.finalized_number,
|
||||
"finalized_hash" => ?info.finalized_hash,
|
||||
@@ -693,8 +692,7 @@ where
|
||||
(new.canon_hash, new.canon_number),
|
||||
);
|
||||
|
||||
#[allow(deprecated)]
|
||||
aux_schema::write_voter_set_state(&**self.env.inner.backend(), &set_state)?;
|
||||
aux_schema::write_voter_set_state(&*self.env.inner, &set_state)?;
|
||||
Ok(Some(set_state))
|
||||
})?;
|
||||
|
||||
@@ -722,8 +720,7 @@ where
|
||||
let completed_rounds = voter_set_state.completed_rounds();
|
||||
let set_state = VoterSetState::Paused { completed_rounds };
|
||||
|
||||
#[allow(deprecated)]
|
||||
aux_schema::write_voter_set_state(&**self.env.inner.backend(), &set_state)?;
|
||||
aux_schema::write_voter_set_state(&*self.env.inner, &set_state)?;
|
||||
Ok(Some(set_state))
|
||||
})?;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ use parking_lot::RwLock;
|
||||
|
||||
use client::{
|
||||
CallExecutor, Client,
|
||||
backend::{AuxStore, Backend},
|
||||
backend::{AuxStore, Backend, Finalizer},
|
||||
blockchain::HeaderBackend,
|
||||
error::Error as ClientError,
|
||||
};
|
||||
@@ -54,6 +54,7 @@ const LIGHT_CONSENSUS_CHANGES_KEY: &[u8] = b"grandpa_consensus_changes";
|
||||
/// Create light block importer.
|
||||
pub fn light_block_import<B, E, Block: BlockT<Hash=H256>, RA, PRA>(
|
||||
client: Arc<Client<B, E, Block, RA>>,
|
||||
backend: Arc<B>,
|
||||
authority_set_provider: Arc<dyn AuthoritySetForFinalityChecker<Block>>,
|
||||
api: Arc<PRA>,
|
||||
) -> Result<GrandpaLightBlockImport<B, E, Block, RA>, ClientError>
|
||||
@@ -65,10 +66,10 @@ pub fn light_block_import<B, E, Block: BlockT<Hash=H256>, RA, PRA>(
|
||||
PRA::Api: GrandpaApi<Block>,
|
||||
{
|
||||
let info = client.info();
|
||||
#[allow(deprecated)]
|
||||
let import_data = load_aux_import_data(info.chain.finalized_hash, &**client.backend(), api)?;
|
||||
let import_data = load_aux_import_data(info.chain.finalized_hash, &*client, api)?;
|
||||
Ok(GrandpaLightBlockImport {
|
||||
client,
|
||||
backend,
|
||||
authority_set_provider,
|
||||
data: Arc::new(RwLock::new(import_data)),
|
||||
})
|
||||
@@ -81,6 +82,7 @@ pub fn light_block_import<B, E, Block: BlockT<Hash=H256>, RA, PRA>(
|
||||
/// - fetching finality proofs for blocks that are enacting consensus changes.
|
||||
pub struct GrandpaLightBlockImport<B, E, Block: BlockT<Hash=H256>, RA> {
|
||||
client: Arc<Client<B, E, Block, RA>>,
|
||||
backend: Arc<B>,
|
||||
authority_set_provider: Arc<dyn AuthoritySetForFinalityChecker<Block>>,
|
||||
data: Arc<RwLock<LightImportData<Block>>>,
|
||||
}
|
||||
@@ -89,6 +91,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> Clone for GrandpaLightBlockImport<B, E,
|
||||
fn clone(&self) -> Self {
|
||||
GrandpaLightBlockImport {
|
||||
client: self.client.clone(),
|
||||
backend: self.backend.clone(),
|
||||
authority_set_provider: self.authority_set_provider.clone(),
|
||||
data: self.data.clone(),
|
||||
}
|
||||
@@ -131,7 +134,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> BlockImport<Block>
|
||||
block: BlockImportParams<Block>,
|
||||
new_cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
|
||||
) -> Result<ImportResult, Self::Error> {
|
||||
do_import_block::<_, _, _, _, GrandpaJustification<Block>>(
|
||||
do_import_block::<_, _, _, GrandpaJustification<Block>>(
|
||||
&*self.client, &mut *self.data.write(), block, new_cache
|
||||
)
|
||||
}
|
||||
@@ -176,8 +179,9 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> FinalityProofImport<Block>
|
||||
finality_proof: Vec<u8>,
|
||||
verifier: &mut dyn Verifier<Block>,
|
||||
) -> Result<(Block::Hash, NumberFor<Block>), Self::Error> {
|
||||
do_import_finality_proof::<_, _, _, _, GrandpaJustification<Block>>(
|
||||
do_import_finality_proof::<_, _, _, GrandpaJustification<Block>>(
|
||||
&*self.client,
|
||||
self.backend.clone(),
|
||||
&*self.authority_set_provider,
|
||||
&mut *self.data.write(),
|
||||
hash,
|
||||
@@ -227,16 +231,19 @@ impl<B: BlockT<Hash=H256>> FinalityProofRequestBuilder<B> for GrandpaFinalityPro
|
||||
}
|
||||
|
||||
/// Try to import new block.
|
||||
fn do_import_block<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
mut client: &Client<B, E, Block, RA>,
|
||||
fn do_import_block<B, C, Block: BlockT<Hash=H256>, J>(
|
||||
mut client: C,
|
||||
data: &mut LightImportData<Block>,
|
||||
mut block: BlockImportParams<Block>,
|
||||
new_cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
|
||||
) -> Result<ImportResult, ConsensusError>
|
||||
where
|
||||
C: HeaderBackend<Block>
|
||||
+ AuxStore
|
||||
+ Finalizer<Block, Blake2Hasher, B>
|
||||
+ BlockImport<Block>
|
||||
+ Clone,
|
||||
B: Backend<Block, Blake2Hasher> + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
RA: Send + Sync,
|
||||
NumberFor<Block>: grandpa::BlockNumberOps,
|
||||
DigestFor<Block>: Encode,
|
||||
J: ProvableJustification<Block::Header>,
|
||||
@@ -247,7 +254,7 @@ fn do_import_block<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
// we don't want to finalize on `inner.import_block`
|
||||
let justification = block.justification.take();
|
||||
let enacts_consensus_change = !new_cache.is_empty();
|
||||
let import_result = BlockImport::import_block(&mut client, block, new_cache);
|
||||
let import_result = client.import_block(block, new_cache);
|
||||
|
||||
let mut imported_aux = match import_result {
|
||||
Ok(ImportResult::Imported(aux)) => aux,
|
||||
@@ -264,7 +271,7 @@ fn do_import_block<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
hash,
|
||||
);
|
||||
|
||||
do_import_justification::<_, _, _, _, J>(client, data, hash, number, justification)
|
||||
do_import_justification::<_, _, _, J>(client, data, hash, number, justification)
|
||||
},
|
||||
None if enacts_consensus_change => {
|
||||
trace!(
|
||||
@@ -283,8 +290,9 @@ fn do_import_block<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
}
|
||||
|
||||
/// Try to import finality proof.
|
||||
fn do_import_finality_proof<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
client: &Client<B, E, Block, RA>,
|
||||
fn do_import_finality_proof<B, C, Block: BlockT<Hash=H256>, J>(
|
||||
client: C,
|
||||
backend: Arc<B>,
|
||||
authority_set_provider: &dyn AuthoritySetForFinalityChecker<Block>,
|
||||
data: &mut LightImportData<Block>,
|
||||
_hash: Block::Hash,
|
||||
@@ -293,9 +301,12 @@ fn do_import_finality_proof<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
verifier: &mut dyn Verifier<Block>,
|
||||
) -> Result<(Block::Hash, NumberFor<Block>), ConsensusError>
|
||||
where
|
||||
C: HeaderBackend<Block>
|
||||
+ AuxStore
|
||||
+ Finalizer<Block, Blake2Hasher, B>
|
||||
+ BlockImport<Block>
|
||||
+ Clone,
|
||||
B: Backend<Block, Blake2Hasher> + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
RA: Send + Sync,
|
||||
DigestFor<Block>: Encode,
|
||||
NumberFor<Block>: grandpa::BlockNumberOps,
|
||||
J: ProvableJustification<Block::Header>,
|
||||
@@ -303,8 +314,7 @@ fn do_import_finality_proof<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
let authority_set_id = data.authority_set.set_id();
|
||||
let authorities = data.authority_set.authorities();
|
||||
let finality_effects = crate::finality_proof::check_finality_proof(
|
||||
#[allow(deprecated)]
|
||||
&*client.backend().blockchain(),
|
||||
backend.blockchain(),
|
||||
authority_set_id,
|
||||
authorities,
|
||||
authority_set_provider,
|
||||
@@ -322,13 +332,12 @@ fn do_import_finality_proof<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
if let Some(authorities) = new_authorities {
|
||||
cache.insert(well_known_cache_keys::AUTHORITIES, authorities.encode());
|
||||
}
|
||||
do_import_block::<_, _, _, _, J>(client, data, block_to_import, cache)?;
|
||||
do_import_block::<_, _, _, J>(client.clone(), data, block_to_import, cache)?;
|
||||
}
|
||||
|
||||
// try to import latest justification
|
||||
let finalized_block_hash = finality_effects.block;
|
||||
#[allow(deprecated)]
|
||||
let finalized_block_number = client.backend().blockchain()
|
||||
let finalized_block_number = backend.blockchain()
|
||||
.expect_block_number_from_id(&BlockId::Hash(finality_effects.block))
|
||||
.map_err(|e| ConsensusError::ClientImport(e.to_string()))?;
|
||||
do_finalize_block(
|
||||
@@ -349,17 +358,19 @@ fn do_import_finality_proof<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
}
|
||||
|
||||
/// Try to import justification.
|
||||
fn do_import_justification<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
client: &Client<B, E, Block, RA>,
|
||||
fn do_import_justification<B, C, Block: BlockT<Hash=H256>, J>(
|
||||
client: C,
|
||||
data: &mut LightImportData<Block>,
|
||||
hash: Block::Hash,
|
||||
number: NumberFor<Block>,
|
||||
justification: Justification,
|
||||
) -> Result<ImportResult, ConsensusError>
|
||||
where
|
||||
C: HeaderBackend<Block>
|
||||
+ AuxStore
|
||||
+ Finalizer<Block, Blake2Hasher, B>
|
||||
+ Clone,
|
||||
B: Backend<Block, Blake2Hasher> + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
RA: Send + Sync,
|
||||
NumberFor<Block>: grandpa::BlockNumberOps,
|
||||
J: ProvableJustification<Block::Header>,
|
||||
{
|
||||
@@ -418,17 +429,19 @@ fn do_import_justification<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
}
|
||||
|
||||
/// Finalize the block.
|
||||
fn do_finalize_block<B, E, Block: BlockT<Hash=H256>, RA>(
|
||||
client: &Client<B, E, Block, RA>,
|
||||
fn do_finalize_block<B, C, Block: BlockT<Hash=H256>>(
|
||||
client: C,
|
||||
data: &mut LightImportData<Block>,
|
||||
hash: Block::Hash,
|
||||
number: NumberFor<Block>,
|
||||
justification: Justification,
|
||||
) -> Result<ImportResult, ConsensusError>
|
||||
where
|
||||
C: HeaderBackend<Block>
|
||||
+ AuxStore
|
||||
+ Finalizer<Block, Blake2Hasher, B>
|
||||
+ Clone,
|
||||
B: Backend<Block, Blake2Hasher> + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
RA: Send + Sync,
|
||||
NumberFor<Block>: grandpa::BlockNumberOps,
|
||||
{
|
||||
// finalize the block
|
||||
@@ -439,7 +452,7 @@ fn do_finalize_block<B, E, Block: BlockT<Hash=H256>, RA>(
|
||||
|
||||
// forget obsoleted consensus changes
|
||||
let consensus_finalization_res = data.consensus_changes
|
||||
.finalize((number, hash), |at_height| canonical_at_height(&client, (hash, number), true, at_height));
|
||||
.finalize((number, hash), |at_height| canonical_at_height(client.clone(), (hash, number), true, at_height));
|
||||
match consensus_finalization_res {
|
||||
Ok((true, _)) => require_insert_aux(
|
||||
&client,
|
||||
@@ -506,20 +519,14 @@ fn load_aux_import_data<B, Block: BlockT<Hash=H256>, PRA>(
|
||||
}
|
||||
|
||||
/// Insert into aux store. If failed, return error && show inconsistency warning.
|
||||
fn require_insert_aux<T: Encode, B, E, Block: BlockT<Hash=H256>, RA>(
|
||||
client: &Client<B, E, Block, RA>,
|
||||
fn require_insert_aux<T: Encode, A: AuxStore>(
|
||||
store: &A,
|
||||
key: &[u8],
|
||||
value: &T,
|
||||
value_type: &str,
|
||||
) -> Result<(), ConsensusError>
|
||||
where
|
||||
B: Backend<Block, Blake2Hasher> + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
let backend = &**client.backend();
|
||||
) -> Result<(), ConsensusError> {
|
||||
let encoded = value.encode();
|
||||
let update_res = Backend::insert_aux(backend, &[(key, &encoded[..])], &[]);
|
||||
let update_res = store.insert_aux(&[(key, &encoded[..])], &[]);
|
||||
if let Err(error) = update_res {
|
||||
return Err(on_post_finalization_error(error, value_type));
|
||||
}
|
||||
@@ -617,6 +624,7 @@ pub mod tests {
|
||||
/// Creates light block import that ignores justifications that came outside of finality proofs.
|
||||
pub fn light_block_import_without_justifications<B, E, Block: BlockT<Hash=H256>, RA, PRA>(
|
||||
client: Arc<Client<B, E, Block, RA>>,
|
||||
backend: Arc<B>,
|
||||
authority_set_provider: Arc<dyn AuthoritySetForFinalityChecker<Block>>,
|
||||
api: Arc<PRA>,
|
||||
) -> Result<NoJustificationsImport<B, E, Block, RA>, ClientError>
|
||||
@@ -627,14 +635,14 @@ pub mod tests {
|
||||
PRA: ProvideRuntimeApi,
|
||||
PRA::Api: GrandpaApi<Block>,
|
||||
{
|
||||
light_block_import(client, authority_set_provider, api).map(NoJustificationsImport)
|
||||
light_block_import(client, backend, authority_set_provider, api).map(NoJustificationsImport)
|
||||
}
|
||||
|
||||
fn import_block(
|
||||
new_cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
|
||||
justification: Option<Justification>,
|
||||
) -> ImportResult {
|
||||
let client = test_client::new_light();
|
||||
let (client, _backend) = test_client::new_light();
|
||||
let mut import_data = LightImportData {
|
||||
last_finalized: Default::default(),
|
||||
authority_set: LightAuthoritySet::genesis(vec![(AuthorityId::from_slice(&[1; 32]), 1)]),
|
||||
@@ -656,7 +664,7 @@ pub mod tests {
|
||||
auxiliary: Vec::new(),
|
||||
fork_choice: ForkChoiceStrategy::LongestChain,
|
||||
};
|
||||
do_import_block::<_, _, _, _, TestJustification>(
|
||||
do_import_block::<_, _, _, TestJustification>(
|
||||
&client,
|
||||
&mut import_data,
|
||||
block,
|
||||
|
||||
@@ -301,8 +301,7 @@ where
|
||||
let completed_rounds = self.persistent_data.set_state.read().completed_rounds();
|
||||
let set_state = VoterSetState::Paused { completed_rounds };
|
||||
|
||||
#[allow(deprecated)]
|
||||
crate::aux_schema::write_voter_set_state(&**self.client.backend(), &set_state)?;
|
||||
crate::aux_schema::write_voter_set_state(&*self.client, &set_state)?;
|
||||
|
||||
set_state
|
||||
},
|
||||
@@ -315,8 +314,7 @@ where
|
||||
(new.canon_hash, new.canon_number),
|
||||
);
|
||||
|
||||
#[allow(deprecated)]
|
||||
crate::aux_schema::write_voter_set_state(&**self.client.backend(), &set_state)?;
|
||||
crate::aux_schema::write_voter_set_state(&*self.client, &set_state)?;
|
||||
|
||||
set_state
|
||||
},
|
||||
|
||||
@@ -112,21 +112,17 @@ impl TestNetFactory for GrandpaTestNet {
|
||||
)
|
||||
{
|
||||
match client {
|
||||
PeersClient::Full(ref client) => {
|
||||
#[allow(deprecated)]
|
||||
let select_chain = LongestChain::new(
|
||||
client.backend().clone()
|
||||
);
|
||||
PeersClient::Full(ref client, ref backend) => {
|
||||
let (import, link) = block_import(
|
||||
client.clone(),
|
||||
Arc::new(self.test_config.clone()),
|
||||
select_chain,
|
||||
LongestChain::new(backend.clone()),
|
||||
).expect("Could not create block import for fresh peer.");
|
||||
let justification_import = Box::new(import.clone());
|
||||
let block_import = Box::new(import);
|
||||
(block_import, Some(justification_import), None, None, Mutex::new(Some(link)))
|
||||
},
|
||||
PeersClient::Light(ref client) => {
|
||||
PeersClient::Light(ref client, ref backend) => {
|
||||
use crate::light_import::tests::light_block_import_without_justifications;
|
||||
|
||||
let authorities_provider = Arc::new(self.test_config.clone());
|
||||
@@ -134,6 +130,7 @@ impl TestNetFactory for GrandpaTestNet {
|
||||
// => light clients will try to fetch finality proofs
|
||||
let import = light_block_import_without_justifications(
|
||||
client.clone(),
|
||||
backend.clone(),
|
||||
authorities_provider,
|
||||
Arc::new(self.test_config.clone())
|
||||
).expect("Could not create block import for fresh peer.");
|
||||
@@ -150,11 +147,11 @@ impl TestNetFactory for GrandpaTestNet {
|
||||
client: PeersClient
|
||||
) -> Option<Arc<dyn network::FinalityProofProvider<Block>>> {
|
||||
match client {
|
||||
PeersClient::Full(ref client) => {
|
||||
PeersClient::Full(_, ref backend) => {
|
||||
let authorities_provider = Arc::new(self.test_config.clone());
|
||||
Some(Arc::new(FinalityProofProvider::new(client.clone(), authorities_provider)))
|
||||
Some(Arc::new(FinalityProofProvider::new(backend.clone(), authorities_provider)))
|
||||
},
|
||||
PeersClient::Light(_) => None,
|
||||
PeersClient::Light(_, _) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,10 +586,7 @@ fn transition_3_voters_twice_1_full_observer() {
|
||||
assert_eq!(full_client.info().chain.best_number, 1,
|
||||
"Peer #{} failed to sync", i);
|
||||
|
||||
let set: AuthoritySet<Hash, BlockNumber> = crate::aux_schema::load_authorities(
|
||||
#[allow(deprecated)]
|
||||
&**full_client.backend()
|
||||
).unwrap();
|
||||
let set: AuthoritySet<Hash, BlockNumber> = crate::aux_schema::load_authorities(&*full_client).unwrap();
|
||||
|
||||
assert_eq!(set.current(), (0, make_ids(peers_a).as_slice()));
|
||||
assert_eq!(set.pending_changes().count(), 0);
|
||||
@@ -685,10 +679,7 @@ fn transition_3_voters_twice_1_full_observer() {
|
||||
.for_each(move |_| Ok(()))
|
||||
.map(move |()| {
|
||||
let full_client = client.as_full().expect("only full clients are used in test");
|
||||
let set: AuthoritySet<Hash, BlockNumber> = crate::aux_schema::load_authorities(
|
||||
#[allow(deprecated)]
|
||||
&**full_client.backend()
|
||||
).unwrap();
|
||||
let set: AuthoritySet<Hash, BlockNumber> = crate::aux_schema::load_authorities(&*full_client).unwrap();
|
||||
|
||||
assert_eq!(set.current(), (2, make_ids(peers_c).as_slice()));
|
||||
assert_eq!(set.pending_changes().count(), 0);
|
||||
@@ -963,10 +954,7 @@ fn force_change_to_new_set() {
|
||||
"Peer #{} failed to sync", i);
|
||||
|
||||
let full_client = peer.client().as_full().expect("only full clients are used in test");
|
||||
let set: AuthoritySet<Hash, BlockNumber> = crate::aux_schema::load_authorities(
|
||||
#[allow(deprecated)]
|
||||
&**full_client.backend()
|
||||
).unwrap();
|
||||
let set: AuthoritySet<Hash, BlockNumber> = crate::aux_schema::load_authorities(&*full_client).unwrap();
|
||||
|
||||
assert_eq!(set.current(), (1, voters.as_slice()));
|
||||
assert_eq!(set.pending_changes().count(), 0);
|
||||
@@ -1099,7 +1087,9 @@ fn voter_persists_its_votes() {
|
||||
assert_eq!(net.peer(0).client().info().chain.best_number, 20,
|
||||
"Peer #{} failed to sync", 0);
|
||||
|
||||
let client = net.peer(0).client().clone();
|
||||
|
||||
let peer = net.peer(0);
|
||||
let client = peer.client().clone();
|
||||
let net = Arc::new(Mutex::new(net));
|
||||
|
||||
// channel between the voter and the main controller.
|
||||
@@ -1258,9 +1248,8 @@ fn voter_persists_its_votes() {
|
||||
})
|
||||
.for_each(|_| Ok(()))
|
||||
.and_then(move |_| {
|
||||
#[allow(deprecated)]
|
||||
let block_30_hash =
|
||||
net.lock().peer(0).client().as_full().unwrap().backend().blockchain().hash(30).unwrap().unwrap();
|
||||
net.lock().peer(0).client().as_full().unwrap().hash(30).unwrap().unwrap();
|
||||
|
||||
// we restart alice's voter
|
||||
voter_tx.unbounded_send(()).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user