mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21:02 +00:00
start to refactor block import wrapper a bit
This commit is contained in:
@@ -39,7 +39,7 @@ impl<'a, Block, A> BlockBuilder<'a, Block, A>
|
||||
where
|
||||
Block: BlockT<Hash=H256>,
|
||||
A: ProvideRuntimeApi + HeaderBackend<Block> + 'a,
|
||||
A::Api: BlockBuilderApi<Block>,
|
||||
A::Api: BlockBuilderApi<Block> + Core<Block>,
|
||||
{
|
||||
/// Create a new instance of builder from the given client, building on the latest block.
|
||||
pub fn new(api: &'a A) -> error::Result<Self> {
|
||||
@@ -84,7 +84,7 @@ where
|
||||
block_id: &BlockId<Block>,
|
||||
xt: Block::Extrinsic,
|
||||
extrinsics: &mut Vec<Block::Extrinsic>
|
||||
) -> error::Result<()> where T: BlockBuilderApi<Block> {
|
||||
) -> error::Result<()> where T: BlockBuilderApi<Block> + Core<Block> {
|
||||
api.map_api_result(|api| {
|
||||
match api.apply_extrinsic(block_id, &xt)? {
|
||||
Ok(ApplyOutcome::Success) | Ok(ApplyOutcome::Fail) => {
|
||||
|
||||
@@ -547,7 +547,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
&self
|
||||
) -> error::Result<block_builder::BlockBuilder<Block, Self>> where
|
||||
E: Clone + Send + Sync,
|
||||
RA: BlockBuilderAPI<Block>
|
||||
RA: BlockBuilderAPI<Block> + CoreAPI<Block>,
|
||||
{
|
||||
block_builder::BlockBuilder::new(self)
|
||||
}
|
||||
@@ -557,7 +557,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
&self, parent: &BlockId<Block>
|
||||
) -> error::Result<block_builder::BlockBuilder<Block, Self>> where
|
||||
E: Clone + Send + Sync,
|
||||
RA: BlockBuilderAPI<Block>
|
||||
RA: BlockBuilderAPI<Block> + CoreAPI<Block>,
|
||||
{
|
||||
block_builder::BlockBuilder::at_block(parent, &self)
|
||||
}
|
||||
@@ -568,7 +568,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
at: Block::Hash,
|
||||
body: &Option<Vec<Block::Extrinsic>>
|
||||
) -> error::Result<Vec<TransactionTag>> where
|
||||
RA: TaggedTransactionQueue<Block>,
|
||||
RA: TaggedTransactionQueue<Block> + CoreAPI<Block>,
|
||||
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + Clone,
|
||||
{
|
||||
let id = BlockId::Hash(at);
|
||||
@@ -604,7 +604,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
finalized: bool,
|
||||
aux: Vec<(Vec<u8>, Option<Vec<u8>>)>,
|
||||
) -> error::Result<ImportResult> where
|
||||
RA: TaggedTransactionQueue<Block>,
|
||||
RA: TaggedTransactionQueue<Block> + CoreAPI<Block>,
|
||||
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + Clone,
|
||||
{
|
||||
let parent_hash = import_headers.post().parent_hash().clone();
|
||||
@@ -1058,7 +1058,7 @@ impl<B, E, Block, RA> consensus::BlockImport<Block> for Client<B, E, Block, RA>
|
||||
B: backend::Backend<Block, Blake2Hasher>,
|
||||
E: CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync,
|
||||
Block: BlockT<Hash=H256>,
|
||||
RA: TaggedTransactionQueue<Block>
|
||||
RA: TaggedTransactionQueue<Block> + CoreAPI<Block>,
|
||||
{
|
||||
type Error = Error;
|
||||
|
||||
|
||||
@@ -347,7 +347,7 @@ macro_rules! decl_runtime_apis {
|
||||
) => {
|
||||
$( #[$attr] )*
|
||||
#[cfg(feature = "std")]
|
||||
pub trait $name < $( $generic_param_parsed $( : $generic_bound_parsed )* ),* > : $crate::runtime_api::Core<Block> {
|
||||
pub trait $name < $( $generic_param_parsed $( : $generic_bound_parsed )* ),* > {
|
||||
$( type $client_generic_param $( : $client_generic_bound )*; )*
|
||||
|
||||
$(
|
||||
|
||||
@@ -23,7 +23,7 @@ pub use state_machine::OverlayedChanges;
|
||||
#[doc(hidden)]
|
||||
pub use runtime_primitives::{traits::Block as BlockT, generic::BlockId};
|
||||
#[cfg(feature = "std")]
|
||||
use runtime_primitives::traits::ApiRef;
|
||||
pub use runtime_primitives::traits::ApiRef;
|
||||
pub use runtime_version::ApiId;
|
||||
#[doc(hidden)]
|
||||
pub use rstd::slice;
|
||||
|
||||
@@ -84,7 +84,7 @@ use futures::stream::Fuse;
|
||||
use futures::sync::mpsc;
|
||||
use client::{Client, error::Error as ClientError, ImportNotifications, backend::Backend, CallExecutor};
|
||||
use client::blockchain::HeaderBackend;
|
||||
use client::runtime_api::TaggedTransactionQueue;
|
||||
use client::runtime_api::{Core as CoreAPI, TaggedTransactionQueue};
|
||||
use codec::{Encode, Decode};
|
||||
use consensus_common::{BlockImport, ImportBlock, ImportResult};
|
||||
use runtime_primitives::traits::{
|
||||
@@ -775,16 +775,16 @@ impl<B, E, Block: BlockT<Hash=H256>, N, RA> voter::Environment<Block::Hash, Numb
|
||||
/// This scans each imported block for signals of changing authority set.
|
||||
/// When using GRANDPA, the block import worker should be using this block import
|
||||
/// object.
|
||||
pub struct GrandpaBlockImport<B, E, Block: BlockT<Hash=H256>, RA> {
|
||||
inner: Arc<Client<B, E, Block, RA>>,
|
||||
pub struct GrandpaBlockImport<Import, Api, Block: BlockT> {
|
||||
import: Import,
|
||||
authority_set: SharedAuthoritySet<Block::Hash, NumberFor<Block>>,
|
||||
api: Api,
|
||||
}
|
||||
|
||||
impl<B, E, Block: BlockT<Hash=H256>, RA> BlockImport<Block> for GrandpaBlockImport<B, E, Block, RA> where
|
||||
B: Backend<Block, Blake2Hasher> + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
DigestFor<Block>: Encode,
|
||||
RA: GrandpaApi<Block> + TaggedTransactionQueue<Block>,
|
||||
impl<Import, Api, Block: BlockT<Hash=H256>> BlockImport<Block> for GrandpaBlockImport<Import, Api, Block> where
|
||||
Import: BlockImport<Block>,
|
||||
Api: ProvideRuntimeApi,
|
||||
Api::Api: GrandpaApi<Block>,
|
||||
{
|
||||
type Error = ClientError;
|
||||
|
||||
@@ -793,7 +793,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> BlockImport<Block> for GrandpaBlockImpo
|
||||
{
|
||||
use authorities::PendingChange;
|
||||
|
||||
let maybe_change = self.inner.runtime_api().grandpa_pending_change(
|
||||
let maybe_change = self.api.runtime_api().grandpa_pending_change(
|
||||
&BlockId::hash(*block.header.parent_hash()),
|
||||
&block.header.digest().clone(),
|
||||
)?;
|
||||
@@ -818,7 +818,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> BlockImport<Block> for GrandpaBlockImpo
|
||||
(old_set, authorities)
|
||||
});
|
||||
|
||||
let result = self.inner.import_block(block, new_authorities);
|
||||
let result = self.import.import_block(block, new_authorities);
|
||||
if let Err(ref e) = result {
|
||||
if let Some((old_set, mut authorities)) = just_in_case {
|
||||
debug!(target: "afg", "Restoring old set after block import error: {:?}", e);
|
||||
@@ -832,15 +832,15 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> BlockImport<Block> for GrandpaBlockImpo
|
||||
|
||||
/// Half of a link between a block-import worker and a the background voter.
|
||||
// This should remain non-clone.
|
||||
pub struct LinkHalf<B, E, Block: BlockT<Hash=H256>, RA> {
|
||||
client: Arc<Client<B, E, Block, RA>>,
|
||||
pub struct LinkHalf<C, RA> {
|
||||
client: C,
|
||||
authority_set: SharedAuthoritySet<Block::Hash, NumberFor<Block>>,
|
||||
}
|
||||
|
||||
/// Make block importer and link half necessary to tie the background voter
|
||||
/// to it.
|
||||
pub fn block_import<B, E, Block: BlockT<Hash=H256>, RA>(client: Arc<Client<B, E, Block, RA>>)
|
||||
-> Result<(GrandpaBlockImport<B, E, Block, RA>, LinkHalf<B, E, Block, RA>), ClientError>
|
||||
pub fn block_import<C, Api>(client: Arc<Client<B, E, Block>>)
|
||||
-> Result<(GrandpaBlockImport<C RA>, LinkHalf<B, E, Block, RA>), ClientError>
|
||||
where
|
||||
B: Backend<Block, Blake2Hasher> + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
@@ -881,7 +881,7 @@ pub fn block_import<B, E, Block: BlockT<Hash=H256>, RA>(client: Arc<Client<B, E,
|
||||
/// block import worker that has already been instantiated with `block_import`.
|
||||
pub fn run_grandpa<B, E, Block: BlockT<Hash=H256>, N, RA>(
|
||||
config: Config,
|
||||
link: LinkHalf<B, E, Block, RA>,
|
||||
link: LinkHalf<Client<B, E, Block, RA>>,
|
||||
network: N,
|
||||
) -> ::client::error::Result<impl Future<Item=(),Error=()>> where
|
||||
Block::Hash: Ord,
|
||||
|
||||
@@ -22,6 +22,7 @@ use keyring;
|
||||
use runtime;
|
||||
use runtime_primitives::traits::ProvideRuntimeApi;
|
||||
use client::block_builder::api::BlockBuilder;
|
||||
use client::runtime_api::Core as CoreAPI;
|
||||
|
||||
/// Extension trait for test block builder.
|
||||
pub trait BlockBuilderExt {
|
||||
@@ -31,7 +32,7 @@ pub trait BlockBuilderExt {
|
||||
|
||||
impl<'a, A> BlockBuilderExt for client::block_builder::BlockBuilder<'a, runtime::Block, A> where
|
||||
A: ProvideRuntimeApi + client::blockchain::HeaderBackend<runtime::Block> + 'a,
|
||||
A::Api: BlockBuilder<runtime::Block>
|
||||
A::Api: BlockBuilder<runtime::Block> + CoreAPI<runtime::Block>,
|
||||
{
|
||||
fn push_transfer(&mut self, transfer: runtime::Transfer) -> Result<(), client::error::Error> {
|
||||
self.push(sign_tx(transfer))
|
||||
|
||||
Reference in New Issue
Block a user