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

sc-transcation-pool refactor #9228

Merged
17 commits merged into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions client/consensus/manual-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use sp_blockchain::HeaderBackend;
use sp_inherents::CreateInherentDataProviders;
use sp_runtime::{traits::Block as BlockT, Justifications, ConsensusEngineId};
use sc_client_api::backend::{Backend as ClientBackend, Finalizer};
use sc_transaction_pool::{ChainApi, Pool};
use std::{sync::Arc, marker::PhantomData};
use prometheus_endpoint::Registry;

Expand All @@ -48,6 +47,7 @@ pub use self::{
rpc::{EngineCommand, CreatedBlock},
};
use sp_api::{ProvideRuntimeApi, TransactionFor};
use sp_transaction_pool::TransactionPool;

/// The `ConsensusEngineId` of Manual Seal.
pub const MANUAL_SEAL_ENGINE_ID: ConsensusEngineId = [b'm', b'a', b'n', b'l'];
Expand Down Expand Up @@ -94,7 +94,7 @@ pub fn import_queue<Block, Transaction>(
}

/// Params required to start the instant sealing authorship task.
pub struct ManualSealParams<B: BlockT, BI, E, C: ProvideRuntimeApi<B>, A: ChainApi, SC, CS, CIDP> {
pub struct ManualSealParams<B: BlockT, BI, E, C: ProvideRuntimeApi<B>, P, SC, CS, CIDP> {
/// Block import instance for well. importing blocks.
pub block_import: BI,

Expand All @@ -105,7 +105,7 @@ pub struct ManualSealParams<B: BlockT, BI, E, C: ProvideRuntimeApi<B>, A: ChainA
pub client: Arc<C>,

/// Shared reference to the transaction pool.
pub pool: Arc<Pool<A>>,
pub pool: Arc<P>,
seunlanlege marked this conversation as resolved.
Show resolved Hide resolved

/// Stream<Item = EngineCommands>, Basically the receiving end of a channel for sending commands to
/// the authorship task.
Expand All @@ -122,7 +122,7 @@ pub struct ManualSealParams<B: BlockT, BI, E, C: ProvideRuntimeApi<B>, A: ChainA
}

/// Params required to start the manual sealing authorship task.
pub struct InstantSealParams<B: BlockT, BI, E, C: ProvideRuntimeApi<B>, A: ChainApi, SC, CIDP> {
pub struct InstantSealParams<B: BlockT, BI, E, C: ProvideRuntimeApi<B>, P, SC, CIDP> {
/// Block import instance for well. importing blocks.
pub block_import: BI,

Expand All @@ -133,7 +133,7 @@ pub struct InstantSealParams<B: BlockT, BI, E, C: ProvideRuntimeApi<B>, A: Chain
pub client: Arc<C>,

/// Shared reference to the transaction pool.
pub pool: Arc<Pool<A>>,
pub pool: Arc<P>,

/// SelectChain strategy.
pub select_chain: SC,
Expand All @@ -146,7 +146,7 @@ pub struct InstantSealParams<B: BlockT, BI, E, C: ProvideRuntimeApi<B>, A: Chain
}

/// Creates the background authorship task for the manual seal engine.
pub async fn run_manual_seal<B, BI, CB, E, C, A, SC, CS, CIDP>(
pub async fn run_manual_seal<B, BI, CB, E, C, P, SC, CS, CIDP>(
ManualSealParams {
mut block_import,
mut env,
Expand All @@ -156,10 +156,9 @@ pub async fn run_manual_seal<B, BI, CB, E, C, A, SC, CS, CIDP>(
select_chain,
consensus_data_provider,
create_inherent_data_providers,
}: ManualSealParams<B, BI, E, C, A, SC, CS, CIDP>
}: ManualSealParams<B, BI, E, C, P, SC, CS, CIDP>
)
where
A: ChainApi<Block=B> + 'static,
B: BlockT + 'static,
BI: BlockImport<B, Error = sp_consensus::Error, Transaction = sp_api::TransactionFor<C, B>>
+ Send + Sync + 'static,
Expand All @@ -170,6 +169,7 @@ pub async fn run_manual_seal<B, BI, CB, E, C, A, SC, CS, CIDP>(
CS: Stream<Item=EngineCommand<<B as BlockT>::Hash>> + Unpin + 'static,
SC: SelectChain<B> + 'static,
TransactionFor<C, B>: 'static,
P: TransactionPool<Block = B>,
CIDP: CreateInherentDataProviders<B, ()>,
{
while let Some(command) = commands_stream.next().await {
Expand Down Expand Up @@ -215,7 +215,7 @@ pub async fn run_manual_seal<B, BI, CB, E, C, A, SC, CS, CIDP>(
/// runs the background authorship task for the instant seal engine.
/// instant-seal creates a new block for every transaction imported into
/// the transaction pool.
pub async fn run_instant_seal<B, BI, CB, E, C, A, SC, CIDP>(
pub async fn run_instant_seal<B, BI, CB, E, C, P, SC, CIDP>(
InstantSealParams {
block_import,
env,
Expand All @@ -224,10 +224,9 @@ pub async fn run_instant_seal<B, BI, CB, E, C, A, SC, CIDP>(
select_chain,
consensus_data_provider,
create_inherent_data_providers,
}: InstantSealParams<B, BI, E, C, A, SC, CIDP>
}: InstantSealParams<B, BI, E, C, P, SC, CIDP>
)
where
A: ChainApi<Block=B> + 'static,
B: BlockT + 'static,
BI: BlockImport<B, Error = sp_consensus::Error, Transaction = sp_api::TransactionFor<C, B>>
+ Send + Sync + 'static,
Expand All @@ -237,12 +236,12 @@ pub async fn run_instant_seal<B, BI, CB, E, C, A, SC, CIDP>(
E::Proposer: Proposer<B, Transaction = TransactionFor<C, B>>,
SC: SelectChain<B> + 'static,
TransactionFor<C, B>: 'static,
P: TransactionPool<Block = B>,
CIDP: CreateInherentDataProviders<B, ()>,
{
// instant-seal creates blocks as soon as transactions are imported
// into the transaction pool.
let commands_stream = pool.validated_pool()
.import_notification_stream()
let commands_stream = pool.import_notification_stream()
.map(|_| {
EngineCommand::SealNewBlock {
create_empty: false,
Expand Down Expand Up @@ -331,7 +330,7 @@ mod tests {
block_import: client.clone(),
env,
client: client.clone(),
pool: pool.pool().clone(),
pool: pool.clone(),
commands_stream,
select_chain,
create_inherent_data_providers: |_, _| async { Ok(()) },
Expand Down Expand Up @@ -395,7 +394,7 @@ mod tests {
block_import: client.clone(),
env,
client: client.clone(),
pool: pool.pool().clone(),
pool: pool.clone(),
commands_stream,
select_chain,
consensus_data_provider: None,
Expand Down Expand Up @@ -476,7 +475,7 @@ mod tests {
block_import: client.clone(),
env,
client: client.clone(),
pool: pool.pool().clone(),
pool: pool.clone(),
commands_stream,
select_chain,
consensus_data_provider: None,
Expand Down
10 changes: 5 additions & 5 deletions client/consensus/manual-seal/src/seal_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use sp_runtime::{
generic::BlockId,
};
use futures::prelude::*;
use sc_transaction_pool::{ChainApi, Pool};
use sp_consensus::{
self, BlockImport, Environment, Proposer, ForkChoiceStrategy,
BlockImportParams, BlockOrigin, ImportResult, SelectChain, StateAction,
Expand All @@ -35,12 +34,13 @@ use std::collections::HashMap;
use std::time::Duration;
use sp_inherents::{CreateInherentDataProviders, InherentDataProvider};
use sp_api::{ProvideRuntimeApi, TransactionFor};
use sp_transaction_pool::TransactionPool;

/// max duration for creating a proposal in secs
pub const MAX_PROPOSAL_DURATION: u64 = 10;

/// params for sealing a new block
pub struct SealBlockParams<'a, B: BlockT, BI, SC, C: ProvideRuntimeApi<B>, E, P: ChainApi, CIDP> {
pub struct SealBlockParams<'a, B: BlockT, BI, SC, C: ProvideRuntimeApi<B>, E, P, CIDP> {
/// if true, empty blocks(without extrinsics) will be created.
/// otherwise, will return Error::EmptyTransactionPool.
pub create_empty: bool,
Expand All @@ -51,7 +51,7 @@ pub struct SealBlockParams<'a, B: BlockT, BI, SC, C: ProvideRuntimeApi<B>, E, P:
/// sender to report errors/success to the rpc.
pub sender: rpc::Sender<CreatedBlock<<B as BlockT>::Hash>>,
/// transaction pool
pub pool: Arc<Pool<P>>,
pub pool: Arc<P>,
/// header backend
pub client: Arc<C>,
/// Environment trait object for creating a proposer
Expand Down Expand Up @@ -90,13 +90,13 @@ pub async fn seal_block<B, BI, SC, C, E, P, CIDP>(
C: HeaderBackend<B> + ProvideRuntimeApi<B>,
E: Environment<B>,
E::Proposer: Proposer<B, Transaction = TransactionFor<C, B>>,
P: ChainApi<Block = B>,
P: TransactionPool<Block = B>,
SC: SelectChain<B>,
TransactionFor<C, B>: 'static,
CIDP: CreateInherentDataProviders<B, ()>,
{
let future = async {
if pool.validated_pool().status().ready == 0 && !create_empty {
if pool.status().ready == 0 && !create_empty {
return Err(Error::EmptyTransactionPool);
}

Expand Down
2 changes: 1 addition & 1 deletion test-utils/test-runner/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<T: ChainInfo> Node<T> {
block_import,
env,
client: client.clone(),
pool: transaction_pool.pool().clone(),
pool: transaction_pool.clone(),
commands_stream,
select_chain,
consensus_data_provider,
Expand Down