mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-22 09:05:41 +00:00
removes use of sc_client::Client from sc_basic_authorship (#5050)
* removes use of sc-client from sc-basic-authorship * refactor use of ProposerFactory * correct dep path
This commit is contained in:
Generated
+2
-1
@@ -5615,7 +5615,6 @@ dependencies = [
|
|||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
"parking_lot 0.10.0",
|
"parking_lot 0.10.0",
|
||||||
"sc-block-builder",
|
"sc-block-builder",
|
||||||
"sc-client",
|
|
||||||
"sc-client-api",
|
"sc-client-api",
|
||||||
"sc-telemetry",
|
"sc-telemetry",
|
||||||
"sc-transaction-pool",
|
"sc-transaction-pool",
|
||||||
@@ -6112,6 +6111,7 @@ dependencies = [
|
|||||||
"parking_lot 0.10.0",
|
"parking_lot 0.10.0",
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
|
"sc-block-builder",
|
||||||
"sc-client",
|
"sc-client",
|
||||||
"sc-client-api",
|
"sc-client-api",
|
||||||
"sc-keystore",
|
"sc-keystore",
|
||||||
@@ -6944,6 +6944,7 @@ dependencies = [
|
|||||||
"criterion 0.3.1",
|
"criterion 0.3.1",
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
"rustversion",
|
"rustversion",
|
||||||
|
"sc-block-builder",
|
||||||
"sp-api",
|
"sp-api",
|
||||||
"sp-blockchain",
|
"sp-blockchain",
|
||||||
"sp-consensus",
|
"sp-consensus",
|
||||||
|
|||||||
@@ -93,10 +93,10 @@ pub fn new_full(config: Configuration<GenesisConfig>)
|
|||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
if participates_in_consensus {
|
if participates_in_consensus {
|
||||||
let proposer = sc_basic_authorship::ProposerFactory {
|
let proposer = sc_basic_authorship::ProposerFactory::new(
|
||||||
client: service.client(),
|
service.client(),
|
||||||
transaction_pool: service.transaction_pool(),
|
service.transaction_pool()
|
||||||
};
|
);
|
||||||
|
|
||||||
let client = service.client();
|
let client = service.client();
|
||||||
let select_chain = service.select_chain()
|
let select_chain = service.select_chain()
|
||||||
|
|||||||
@@ -150,10 +150,10 @@ macro_rules! new_full {
|
|||||||
($with_startup_data)(&block_import, &babe_link);
|
($with_startup_data)(&block_import, &babe_link);
|
||||||
|
|
||||||
if participates_in_consensus {
|
if participates_in_consensus {
|
||||||
let proposer = sc_basic_authorship::ProposerFactory {
|
let proposer = sc_basic_authorship::ProposerFactory::new(
|
||||||
client: service.client(),
|
service.client(),
|
||||||
transaction_pool: service.transaction_pool(),
|
service.transaction_pool()
|
||||||
};
|
);
|
||||||
|
|
||||||
let client = service.client();
|
let client = service.client();
|
||||||
let select_chain = service.select_chain()
|
let select_chain = service.select_chain()
|
||||||
@@ -501,10 +501,10 @@ mod tests {
|
|||||||
let parent_header = service.client().header(&parent_id).unwrap().unwrap();
|
let parent_header = service.client().header(&parent_id).unwrap().unwrap();
|
||||||
let parent_hash = parent_header.hash();
|
let parent_hash = parent_header.hash();
|
||||||
let parent_number = *parent_header.number();
|
let parent_number = *parent_header.number();
|
||||||
let mut proposer_factory = sc_basic_authorship::ProposerFactory {
|
let mut proposer_factory = sc_basic_authorship::ProposerFactory::new(
|
||||||
client: service.client(),
|
service.client(),
|
||||||
transaction_pool: service.transaction_pool(),
|
service.transaction_pool()
|
||||||
};
|
);
|
||||||
|
|
||||||
let epoch = babe_link.epoch_changes().lock().epoch_for_child_of(
|
let epoch = babe_link.epoch_changes().lock().epoch_for_child_of(
|
||||||
descendent_query(&*service.client()),
|
descendent_query(&*service.client()),
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ sp-api = { version = "2.0.0-alpha.2", path = "../../primitives/api" }
|
|||||||
sp-runtime = { version = "2.0.0-alpha.2", path = "../../primitives/runtime" }
|
sp-runtime = { version = "2.0.0-alpha.2", path = "../../primitives/runtime" }
|
||||||
sp-core = { version = "2.0.0-alpha.2", path = "../../primitives/core" }
|
sp-core = { version = "2.0.0-alpha.2", path = "../../primitives/core" }
|
||||||
sp-blockchain = { version = "2.0.0-alpha.2", path = "../../primitives/blockchain" }
|
sp-blockchain = { version = "2.0.0-alpha.2", path = "../../primitives/blockchain" }
|
||||||
sc-client = { version = "0.8.0-alpha.2", path = "../" }
|
|
||||||
sc-client-api = { version = "2.0.0-alpha.2", path = "../api" }
|
sc-client-api = { version = "2.0.0-alpha.2", path = "../api" }
|
||||||
sp-consensus = { version = "0.8.0-alpha.2", path = "../../primitives/consensus/common" }
|
sp-consensus = { version = "0.8.0-alpha.2", path = "../../primitives/consensus/common" }
|
||||||
sp-inherents = { version = "2.0.0-alpha.2", path = "../../primitives/inherents" }
|
sp-inherents = { version = "2.0.0-alpha.2", path = "../../primitives/inherents" }
|
||||||
|
|||||||
@@ -19,8 +19,7 @@
|
|||||||
// FIXME #1021 move this into sp-consensus
|
// FIXME #1021 move this into sp-consensus
|
||||||
|
|
||||||
use std::{time, sync::Arc};
|
use std::{time, sync::Arc};
|
||||||
use sc_client_api::{CallExecutor, backend};
|
use sc_client_api::backend;
|
||||||
use sc_client::Client as SubstrateClient;
|
|
||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
use sp_consensus::{evaluation, Proposal, RecordProof};
|
use sp_consensus::{evaluation, Proposal, RecordProof};
|
||||||
use sp_inherents::InherentData;
|
use sp_inherents::InherentData;
|
||||||
@@ -32,35 +31,47 @@ use sp_runtime::{
|
|||||||
};
|
};
|
||||||
use sp_transaction_pool::{TransactionPool, InPoolTransaction};
|
use sp_transaction_pool::{TransactionPool, InPoolTransaction};
|
||||||
use sc_telemetry::{telemetry, CONSENSUS_INFO};
|
use sc_telemetry::{telemetry, CONSENSUS_INFO};
|
||||||
use sc_block_builder::BlockBuilderApi;
|
use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
|
||||||
use sp_api::{ProvideRuntimeApi, ApiExt};
|
use sp_api::{ProvideRuntimeApi, ApiExt};
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
|
use sp_blockchain::HeaderBackend;
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
/// Proposer factory.
|
/// Proposer factory.
|
||||||
pub struct ProposerFactory<C, A> where A: TransactionPool {
|
pub struct ProposerFactory<A, B, C> {
|
||||||
/// The client instance.
|
/// The client instance.
|
||||||
pub client: Arc<C>,
|
client: Arc<C>,
|
||||||
/// The transaction pool.
|
/// The transaction pool.
|
||||||
pub transaction_pool: Arc<A>,
|
transaction_pool: Arc<A>,
|
||||||
|
/// phantom member to pin the `Backend` type.
|
||||||
|
_phantom: PhantomData<B>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B, E, Block, RA, A> ProposerFactory<SubstrateClient<B, E, Block, RA>, A>
|
impl<A, B, C> ProposerFactory<A, B, C> {
|
||||||
|
pub fn new(client: Arc<C>, transaction_pool: Arc<A>) -> Self {
|
||||||
|
ProposerFactory {
|
||||||
|
client,
|
||||||
|
transaction_pool,
|
||||||
|
_phantom: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<B, Block, C, A> ProposerFactory<A, B, C>
|
||||||
where
|
where
|
||||||
A: TransactionPool<Block = Block> + 'static,
|
A: TransactionPool<Block = Block> + 'static,
|
||||||
B: backend::Backend<Block> + Send + Sync + 'static,
|
B: backend::Backend<Block> + Send + Sync + 'static,
|
||||||
E: CallExecutor<Block> + Send + Sync + Clone + 'static,
|
|
||||||
Block: BlockT,
|
Block: BlockT,
|
||||||
RA: Send + Sync + 'static,
|
C: BlockBuilderProvider<B, Block, C> + HeaderBackend<Block> + ProvideRuntimeApi<Block>
|
||||||
SubstrateClient<B, E, Block, RA>: ProvideRuntimeApi<Block>,
|
+ Send + Sync + 'static,
|
||||||
<SubstrateClient<B, E, Block, RA> as ProvideRuntimeApi<Block>>::Api:
|
C::Api: ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>
|
||||||
BlockBuilderApi<Block, Error = sp_blockchain::Error> +
|
+ BlockBuilderApi<Block, Error = sp_blockchain::Error>,
|
||||||
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>,
|
|
||||||
{
|
{
|
||||||
pub fn init_with_now(
|
pub fn init_with_now(
|
||||||
&mut self,
|
&mut self,
|
||||||
parent_header: &<Block as BlockT>::Header,
|
parent_header: &<Block as BlockT>::Header,
|
||||||
now: Box<dyn Fn() -> time::Instant + Send + Sync>,
|
now: Box<dyn Fn() -> time::Instant + Send + Sync>,
|
||||||
) -> Proposer<Block, SubstrateClient<B, E, Block, RA>, A> {
|
) -> Proposer<B, Block, C, A> {
|
||||||
let parent_hash = parent_header.hash();
|
let parent_hash = parent_header.hash();
|
||||||
|
|
||||||
let id = BlockId::hash(parent_hash);
|
let id = BlockId::hash(parent_hash);
|
||||||
@@ -75,6 +86,7 @@ impl<B, E, Block, RA, A> ProposerFactory<SubstrateClient<B, E, Block, RA>, A>
|
|||||||
parent_number: *parent_header.number(),
|
parent_number: *parent_header.number(),
|
||||||
transaction_pool: self.transaction_pool.clone(),
|
transaction_pool: self.transaction_pool.clone(),
|
||||||
now,
|
now,
|
||||||
|
_phantom: PhantomData,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -82,21 +94,19 @@ impl<B, E, Block, RA, A> ProposerFactory<SubstrateClient<B, E, Block, RA>, A>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B, E, Block, RA, A> sp_consensus::Environment<Block> for
|
impl<A, B, Block, C> sp_consensus::Environment<Block> for
|
||||||
ProposerFactory<SubstrateClient<B, E, Block, RA>, A>
|
ProposerFactory<A, B, C>
|
||||||
where
|
where
|
||||||
A: TransactionPool<Block = Block> + 'static,
|
A: TransactionPool<Block = Block> + 'static,
|
||||||
B: backend::Backend<Block> + Send + Sync + 'static,
|
B: backend::Backend<Block> + Send + Sync + 'static,
|
||||||
E: CallExecutor<Block> + Send + Sync + Clone + 'static,
|
|
||||||
Block: BlockT,
|
Block: BlockT,
|
||||||
RA: Send + Sync + 'static,
|
C: BlockBuilderProvider<B, Block, C> + HeaderBackend<Block> + ProvideRuntimeApi<Block>
|
||||||
SubstrateClient<B, E, Block, RA>: ProvideRuntimeApi<Block>,
|
+ Send + Sync + 'static,
|
||||||
<SubstrateClient<B, E, Block, RA> as ProvideRuntimeApi<Block>>::Api:
|
C::Api: ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>
|
||||||
BlockBuilderApi<Block, Error = sp_blockchain::Error> +
|
+ BlockBuilderApi<Block, Error = sp_blockchain::Error>,
|
||||||
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>,
|
|
||||||
{
|
{
|
||||||
type CreateProposer = future::Ready<Result<Self::Proposer, Self::Error>>;
|
type CreateProposer = future::Ready<Result<Self::Proposer, Self::Error>>;
|
||||||
type Proposer = Proposer<Block, SubstrateClient<B, E, Block, RA>, A>;
|
type Proposer = Proposer<B, Block, C, A>;
|
||||||
type Error = sp_blockchain::Error;
|
type Error = sp_blockchain::Error;
|
||||||
|
|
||||||
fn init(
|
fn init(
|
||||||
@@ -108,32 +118,31 @@ impl<B, E, Block, RA, A> sp_consensus::Environment<Block> for
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The proposer logic.
|
/// The proposer logic.
|
||||||
pub struct Proposer<Block: BlockT, C, A: TransactionPool> {
|
pub struct Proposer<B, Block: BlockT, C, A: TransactionPool> {
|
||||||
inner: Arc<ProposerInner<Block, C, A>>,
|
inner: Arc<ProposerInner<B, Block, C, A>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Proposer inner, to wrap parameters under Arc.
|
/// Proposer inner, to wrap parameters under Arc.
|
||||||
struct ProposerInner<Block: BlockT, C, A: TransactionPool> {
|
struct ProposerInner<B, Block: BlockT, C, A: TransactionPool> {
|
||||||
client: Arc<C>,
|
client: Arc<C>,
|
||||||
parent_hash: <Block as BlockT>::Hash,
|
parent_hash: <Block as BlockT>::Hash,
|
||||||
parent_id: BlockId<Block>,
|
parent_id: BlockId<Block>,
|
||||||
parent_number: <<Block as BlockT>::Header as HeaderT>::Number,
|
parent_number: <<Block as BlockT>::Header as HeaderT>::Number,
|
||||||
transaction_pool: Arc<A>,
|
transaction_pool: Arc<A>,
|
||||||
now: Box<dyn Fn() -> time::Instant + Send + Sync>,
|
now: Box<dyn Fn() -> time::Instant + Send + Sync>,
|
||||||
|
_phantom: PhantomData<B>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B, E, Block, RA, A> sp_consensus::Proposer<Block> for
|
impl<A, B, Block, C> sp_consensus::Proposer<Block> for
|
||||||
Proposer<Block, SubstrateClient<B, E, Block, RA>, A>
|
Proposer<B, Block, C, A>
|
||||||
where
|
where
|
||||||
A: TransactionPool<Block = Block> + 'static,
|
A: TransactionPool<Block = Block> + 'static,
|
||||||
B: backend::Backend<Block> + Send + Sync + 'static,
|
B: backend::Backend<Block> + Send + Sync + 'static,
|
||||||
E: CallExecutor<Block> + Send + Sync + Clone + 'static,
|
|
||||||
Block: BlockT,
|
Block: BlockT,
|
||||||
RA: Send + Sync + 'static,
|
C: BlockBuilderProvider<B, Block, C> + HeaderBackend<Block> + ProvideRuntimeApi<Block>
|
||||||
SubstrateClient<B, E, Block, RA>: ProvideRuntimeApi<Block>,
|
+ Send + Sync + 'static,
|
||||||
<SubstrateClient<B, E, Block, RA> as ProvideRuntimeApi<Block>>::Api:
|
C::Api: ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>
|
||||||
BlockBuilderApi<Block, Error = sp_blockchain::Error> +
|
+ BlockBuilderApi<Block, Error = sp_blockchain::Error>,
|
||||||
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>,
|
|
||||||
{
|
{
|
||||||
type Transaction = backend::TransactionFor<B, Block>;
|
type Transaction = backend::TransactionFor<B, Block>;
|
||||||
type Proposal = tokio_executor::blocking::Blocking<
|
type Proposal = tokio_executor::blocking::Blocking<
|
||||||
@@ -157,16 +166,15 @@ impl<B, E, Block, RA, A> sp_consensus::Proposer<Block> for
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Block, B, E, RA, A> ProposerInner<Block, SubstrateClient<B, E, Block, RA>, A> where
|
impl<A, B, Block, C> ProposerInner<B, Block, C, A>
|
||||||
A: TransactionPool<Block = Block>,
|
where
|
||||||
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
|
A: TransactionPool<Block = Block>,
|
||||||
E: CallExecutor<Block> + Send + Sync + Clone + 'static,
|
B: backend::Backend<Block> + Send + Sync + 'static,
|
||||||
Block: BlockT,
|
Block: BlockT,
|
||||||
RA: Send + Sync + 'static,
|
C: BlockBuilderProvider<B, Block, C> + HeaderBackend<Block> + ProvideRuntimeApi<Block>
|
||||||
SubstrateClient<B, E, Block, RA>: ProvideRuntimeApi<Block>,
|
+ Send + Sync + 'static,
|
||||||
<SubstrateClient<B, E, Block, RA> as ProvideRuntimeApi<Block>>::Api:
|
C::Api: ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>
|
||||||
BlockBuilderApi<Block, Error = sp_blockchain::Error> +
|
+ BlockBuilderApi<Block, Error = sp_blockchain::Error>,
|
||||||
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>,
|
|
||||||
{
|
{
|
||||||
fn propose_with(
|
fn propose_with(
|
||||||
&self,
|
&self,
|
||||||
@@ -315,10 +323,7 @@ mod tests {
|
|||||||
txpool.submit_at(&BlockId::number(0), vec![extrinsic(0), extrinsic(1)])
|
txpool.submit_at(&BlockId::number(0), vec![extrinsic(0), extrinsic(1)])
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let mut proposer_factory = ProposerFactory {
|
let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone());
|
||||||
client: client.clone(),
|
|
||||||
transaction_pool: txpool.clone(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let cell = Mutex::new(time::Instant::now());
|
let cell = Mutex::new(time::Instant::now());
|
||||||
let mut proposer = proposer_factory.init_with_now(
|
let mut proposer = proposer_factory.init_with_now(
|
||||||
@@ -359,10 +364,7 @@ mod tests {
|
|||||||
txpool.submit_at(&BlockId::number(0), vec![extrinsic(0)]),
|
txpool.submit_at(&BlockId::number(0), vec![extrinsic(0)]),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let mut proposer_factory = ProposerFactory {
|
let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone());
|
||||||
client: client.clone(),
|
|
||||||
transaction_pool: txpool.clone(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut proposer = proposer_factory.init_with_now(
|
let mut proposer = proposer_factory.init_with_now(
|
||||||
&client.header(&block_id).unwrap().unwrap(),
|
&client.header(&block_id).unwrap().unwrap(),
|
||||||
|
|||||||
@@ -28,10 +28,7 @@
|
|||||||
//! # let client = Arc::new(substrate_test_runtime_client::new());
|
//! # let client = Arc::new(substrate_test_runtime_client::new());
|
||||||
//! # let txpool = Arc::new(BasicPool::new(Default::default(), Arc::new(FullChainApi::new(client.clone()))).0);
|
//! # let txpool = Arc::new(BasicPool::new(Default::default(), Arc::new(FullChainApi::new(client.clone()))).0);
|
||||||
//! // The first step is to create a `ProposerFactory`.
|
//! // The first step is to create a `ProposerFactory`.
|
||||||
//! let mut proposer_factory = ProposerFactory {
|
//! let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone());
|
||||||
//! client: client.clone(),
|
|
||||||
//! transaction_pool: txpool.clone(),
|
|
||||||
//! };
|
|
||||||
//!
|
//!
|
||||||
//! // From this factory, we create a `Proposer`.
|
//! // From this factory, we create a `Proposer`.
|
||||||
//! let proposer = proposer_factory.init(
|
//! let proposer = proposer_factory.init(
|
||||||
|
|||||||
@@ -63,6 +63,27 @@ impl<Block: BlockT, StateBackend: backend::StateBackend<HasherFor<Block>>> Built
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Block builder provider
|
||||||
|
pub trait BlockBuilderProvider<B, Block, RA>
|
||||||
|
where
|
||||||
|
Block: BlockT,
|
||||||
|
B: backend::Backend<Block>,
|
||||||
|
Self: Sized,
|
||||||
|
RA: ProvideRuntimeApi<Block>,
|
||||||
|
{
|
||||||
|
/// Create a new block, built on top of `parent`.
|
||||||
|
///
|
||||||
|
/// When proof recording is enabled, all accessed trie nodes are saved.
|
||||||
|
/// These recorded trie nodes can be used by a third party to proof the
|
||||||
|
/// output of this block builder without having access to the full storage.
|
||||||
|
fn new_block_at<R: Into<RecordProof>>(
|
||||||
|
&self,
|
||||||
|
parent: &BlockId<Block>,
|
||||||
|
inherent_digests: DigestFor<Block>,
|
||||||
|
record_proof: R,
|
||||||
|
) -> sp_blockchain::Result<BlockBuilder<Block, RA, B>>;
|
||||||
|
}
|
||||||
|
|
||||||
/// Utility for building new (valid) blocks from a stream of extrinsics.
|
/// Utility for building new (valid) blocks from a stream of extrinsics.
|
||||||
pub struct BlockBuilder<'a, Block: BlockT, A: ProvideRuntimeApi<Block>, B> {
|
pub struct BlockBuilder<'a, Block: BlockT, A: ProvideRuntimeApi<Block>, B> {
|
||||||
extrinsics: Vec<Block::Extrinsic>,
|
extrinsics: Vec<Block::Extrinsic>,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use super::*;
|
|||||||
use authorship::claim_slot;
|
use authorship::claim_slot;
|
||||||
|
|
||||||
use sp_consensus_babe::{AuthorityPair, SlotNumber};
|
use sp_consensus_babe::{AuthorityPair, SlotNumber};
|
||||||
use sc_block_builder::BlockBuilder;
|
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
|
||||||
use sp_consensus::{
|
use sp_consensus::{
|
||||||
NoNetwork as DummyOracle, Proposal, RecordProof,
|
NoNetwork as DummyOracle, Proposal, RecordProof,
|
||||||
import_queue::{BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport},
|
import_queue::{BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport},
|
||||||
|
|||||||
@@ -244,10 +244,10 @@ mod tests {
|
|||||||
let select_chain = LongestChain::new(backend.clone());
|
let select_chain = LongestChain::new(backend.clone());
|
||||||
let inherent_data_providers = InherentDataProviders::new();
|
let inherent_data_providers = InherentDataProviders::new();
|
||||||
let pool = Arc::new(BasicPool::new(Options::default(), api()).0);
|
let pool = Arc::new(BasicPool::new(Options::default(), api()).0);
|
||||||
let env = ProposerFactory {
|
let env = ProposerFactory::new(
|
||||||
transaction_pool: pool.clone(),
|
client.clone(),
|
||||||
client: client.clone(),
|
pool.clone()
|
||||||
};
|
);
|
||||||
// this test checks that blocks are created as soon as transactions are imported into the pool.
|
// this test checks that blocks are created as soon as transactions are imported into the pool.
|
||||||
let (sender, receiver) = futures::channel::oneshot::channel();
|
let (sender, receiver) = futures::channel::oneshot::channel();
|
||||||
let mut sender = Arc::new(Some(sender));
|
let mut sender = Arc::new(Some(sender));
|
||||||
@@ -309,10 +309,10 @@ mod tests {
|
|||||||
let select_chain = LongestChain::new(backend.clone());
|
let select_chain = LongestChain::new(backend.clone());
|
||||||
let inherent_data_providers = InherentDataProviders::new();
|
let inherent_data_providers = InherentDataProviders::new();
|
||||||
let pool = Arc::new(BasicPool::new(Options::default(), api()).0);
|
let pool = Arc::new(BasicPool::new(Options::default(), api()).0);
|
||||||
let env = ProposerFactory {
|
let env = ProposerFactory::new(
|
||||||
transaction_pool: pool.clone(),
|
client.clone(),
|
||||||
client: client.clone(),
|
pool.clone()
|
||||||
};
|
);
|
||||||
// this test checks that blocks are created as soon as an engine command is sent over the stream.
|
// this test checks that blocks are created as soon as an engine command is sent over the stream.
|
||||||
let (mut sink, stream) = futures::channel::mpsc::channel(1024);
|
let (mut sink, stream) = futures::channel::mpsc::channel(1024);
|
||||||
let future = run_manual_seal(
|
let future = run_manual_seal(
|
||||||
@@ -378,10 +378,10 @@ mod tests {
|
|||||||
let inherent_data_providers = InherentDataProviders::new();
|
let inherent_data_providers = InherentDataProviders::new();
|
||||||
let pool_api = api();
|
let pool_api = api();
|
||||||
let pool = Arc::new(BasicPool::new(Options::default(), pool_api.clone()).0);
|
let pool = Arc::new(BasicPool::new(Options::default(), pool_api.clone()).0);
|
||||||
let env = ProposerFactory {
|
let env = ProposerFactory::new(
|
||||||
transaction_pool: pool.clone(),
|
client.clone(),
|
||||||
client: client.clone(),
|
pool.clone(),
|
||||||
};
|
);
|
||||||
// this test checks that blocks are created as soon as an engine command is sent over the stream.
|
// this test checks that blocks are created as soon as an engine command is sent over the stream.
|
||||||
let (mut sink, stream) = futures::channel::mpsc::channel(1024);
|
let (mut sink, stream) = futures::channel::mpsc::channel(1024);
|
||||||
let future = run_manual_seal(
|
let future = run_manual_seal(
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ sc-network = { version = "0.8.0-alpha.2", path = "../network" }
|
|||||||
sc-network-gossip = { version = "0.8.0-alpha.2", path = "../network-gossip" }
|
sc-network-gossip = { version = "0.8.0-alpha.2", path = "../network-gossip" }
|
||||||
sp-finality-tracker = { version = "2.0.0-alpha.2", path = "../../primitives/finality-tracker" }
|
sp-finality-tracker = { version = "2.0.0-alpha.2", path = "../../primitives/finality-tracker" }
|
||||||
sp-finality-grandpa = { version = "2.0.0-alpha.2", path = "../../primitives/finality-grandpa" }
|
sp-finality-grandpa = { version = "2.0.0-alpha.2", path = "../../primitives/finality-grandpa" }
|
||||||
|
sc-block-builder = { version = "0.8.0-alpha.2", path = "../block-builder" }
|
||||||
finality-grandpa = { version = "0.11.1", features = ["derive-codec"] }
|
finality-grandpa = { version = "0.11.1", features = ["derive-codec"] }
|
||||||
pin-project = "0.4.6"
|
pin-project = "0.4.6"
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ use finality_proof::{
|
|||||||
FinalityProofProvider, AuthoritySetForFinalityProver, AuthoritySetForFinalityChecker,
|
FinalityProofProvider, AuthoritySetForFinalityProver, AuthoritySetForFinalityChecker,
|
||||||
};
|
};
|
||||||
use consensus_changes::ConsensusChanges;
|
use consensus_changes::ConsensusChanges;
|
||||||
|
use sc_block_builder::BlockBuilderProvider;
|
||||||
|
|
||||||
type PeerData =
|
type PeerData =
|
||||||
Mutex<
|
Mutex<
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ use sc_client_api::{
|
|||||||
FinalityNotification,
|
FinalityNotification,
|
||||||
backend::{TransactionFor, AuxStore, Backend, Finalizer},
|
backend::{TransactionFor, AuxStore, Backend, Finalizer},
|
||||||
};
|
};
|
||||||
use sc_block_builder::BlockBuilder;
|
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
|
||||||
use sc_client::LongestChain;
|
use sc_client::LongestChain;
|
||||||
use sc_network::config::Roles;
|
use sc_network::config::Roles;
|
||||||
use sp_consensus::block_validation::DefaultBlockAnnounceValidator;
|
use sp_consensus::block_validation::DefaultBlockAnnounceValidator;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ use sp_api::{
|
|||||||
CallApiAt, ConstructRuntimeApi, Core as CoreApi, ApiExt, ApiRef, ProvideRuntimeApi,
|
CallApiAt, ConstructRuntimeApi, Core as CoreApi, ApiExt, ApiRef, ProvideRuntimeApi,
|
||||||
CallApiAtParams,
|
CallApiAtParams,
|
||||||
};
|
};
|
||||||
use sc_block_builder::BlockBuilderApi;
|
use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
|
||||||
|
|
||||||
pub use sc_client_api::{
|
pub use sc_client_api::{
|
||||||
backend::{
|
backend::{
|
||||||
@@ -863,33 +863,6 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new block, built on top of `parent`.
|
|
||||||
///
|
|
||||||
/// When proof recording is enabled, all accessed trie nodes are saved.
|
|
||||||
/// These recorded trie nodes can be used by a third party to proof the
|
|
||||||
/// output of this block builder without having access to the full storage.
|
|
||||||
pub fn new_block_at<R: Into<RecordProof>>(
|
|
||||||
&self,
|
|
||||||
parent: &BlockId<Block>,
|
|
||||||
inherent_digests: DigestFor<Block>,
|
|
||||||
record_proof: R,
|
|
||||||
) -> sp_blockchain::Result<sc_block_builder::BlockBuilder<Block, Self, B>> where
|
|
||||||
E: Clone + Send + Sync,
|
|
||||||
RA: Send + Sync,
|
|
||||||
Self: ProvideRuntimeApi<Block>,
|
|
||||||
<Self as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block, Error = Error> +
|
|
||||||
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>
|
|
||||||
{
|
|
||||||
sc_block_builder::BlockBuilder::new(
|
|
||||||
self,
|
|
||||||
self.expect_block_hash_from_id(parent)?,
|
|
||||||
self.expect_block_number_from_id(parent)?,
|
|
||||||
record_proof.into(),
|
|
||||||
inherent_digests,
|
|
||||||
&self.backend
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Apply a checked and validated block to an operation. If a justification is provided
|
/// Apply a checked and validated block to an operation. If a justification is provided
|
||||||
/// then `finalized` *must* be true.
|
/// then `finalized` *must* be true.
|
||||||
fn apply_block(
|
fn apply_block(
|
||||||
@@ -1421,6 +1394,32 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<B, E, Block, RA> BlockBuilderProvider<B, Block, Self> for Client<B, E, Block, RA>
|
||||||
|
where
|
||||||
|
B: backend::Backend<Block> + Send + Sync + 'static,
|
||||||
|
E: CallExecutor<Block> + Send + Sync + 'static,
|
||||||
|
Block: BlockT,
|
||||||
|
Self: ChainHeaderBackend<Block> + ProvideRuntimeApi<Block>,
|
||||||
|
<Self as ProvideRuntimeApi<Block>>::Api: ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>
|
||||||
|
+ BlockBuilderApi<Block, Error = Error>,
|
||||||
|
{
|
||||||
|
fn new_block_at<R: Into<RecordProof>>(
|
||||||
|
&self,
|
||||||
|
parent: &BlockId<Block>,
|
||||||
|
inherent_digests: DigestFor<Block>,
|
||||||
|
record_proof: R,
|
||||||
|
) -> sp_blockchain::Result<sc_block_builder::BlockBuilder<Block, Self, B>> {
|
||||||
|
sc_block_builder::BlockBuilder::new(
|
||||||
|
self,
|
||||||
|
self.expect_block_hash_from_id(parent)?,
|
||||||
|
self.expect_block_number_from_id(parent)?,
|
||||||
|
record_proof.into(),
|
||||||
|
inherent_digests,
|
||||||
|
&self.backend
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<B, E, Block, RA> HeaderMetadata<Block> for Client<B, E, Block, RA> where
|
impl<B, E, Block, RA> HeaderMetadata<Block> for Client<B, E, Block, RA> where
|
||||||
B: backend::Backend<Block>,
|
B: backend::Backend<Block>,
|
||||||
E: CallExecutor<Block>,
|
E: CallExecutor<Block>,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ sp-version = { version = "2.0.0-alpha.2", path = "../../version" }
|
|||||||
sp-runtime = { version = "2.0.0-alpha.2", path = "../../runtime" }
|
sp-runtime = { version = "2.0.0-alpha.2", path = "../../runtime" }
|
||||||
sp-blockchain = { version = "2.0.0-alpha.2", path = "../../blockchain" }
|
sp-blockchain = { version = "2.0.0-alpha.2", path = "../../blockchain" }
|
||||||
sp-consensus = { version = "0.8.0-alpha.2", path = "../../../primitives/consensus/common" }
|
sp-consensus = { version = "0.8.0-alpha.2", path = "../../../primitives/consensus/common" }
|
||||||
|
sc-block-builder = { version = "0.8.0-alpha.2", path = "../../../client/block-builder" }
|
||||||
codec = { package = "parity-scale-codec", version = "1.0.0" }
|
codec = { package = "parity-scale-codec", version = "1.0.0" }
|
||||||
sp-state-machine = { version = "0.8.0-alpha.2", path = "../../../primitives/state-machine" }
|
sp-state-machine = { version = "0.8.0-alpha.2", path = "../../../primitives/state-machine" }
|
||||||
trybuild = "1.0.17"
|
trybuild = "1.0.17"
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use sp_state_machine::{
|
|||||||
|
|
||||||
use sp_consensus::SelectChain;
|
use sp_consensus::SelectChain;
|
||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
|
use sc_block_builder::BlockBuilderProvider;
|
||||||
|
|
||||||
fn calling_function_with_strat(strat: ExecutionStrategy) {
|
fn calling_function_with_strat(strat: ExecutionStrategy) {
|
||||||
let client = TestClientBuilder::new().set_execution_strategy(strat).build();
|
let client = TestClientBuilder::new().set_execution_strategy(strat).build();
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ use substrate_test_client::sp_consensus::BlockOrigin;
|
|||||||
use substrate_test_runtime::{self, Transfer};
|
use substrate_test_runtime::{self, Transfer};
|
||||||
use sp_runtime::generic::BlockId;
|
use sp_runtime::generic::BlockId;
|
||||||
use sp_runtime::traits::{Block as BlockT, HasherFor};
|
use sp_runtime::traits::{Block as BlockT, HasherFor};
|
||||||
|
use sc_block_builder::BlockBuilderProvider;
|
||||||
|
|
||||||
/// helper to test the `leaves` implementation for various backends
|
/// helper to test the `leaves` implementation for various backends
|
||||||
pub fn test_leaves_for_backend<B: 'static>(backend: Arc<B>) where
|
pub fn test_leaves_for_backend<B: 'static>(backend: Arc<B>) where
|
||||||
|
|||||||
Reference in New Issue
Block a user