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