mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
sc-transcation-pool refactor (#9228)
* Use TransactionPool trait * sc-transaction-pool-primitives * sc-transaction-pool-api * TP * bye sc_transaction_graph * fix line widths * fix import errors * fix import errors * fix import errors 🤦🏾♂️ * fix import errors 🤦🏾♂️🤦🏾♂️🤦🏾♂️ * remove sp-keyring
This commit is contained in:
@@ -40,7 +40,7 @@ sp-core = { path = "../../../primitives/core", version = "3.0.0"}
|
||||
sp-keystore = { path = "../../../primitives/keystore", version = "0.9.0"}
|
||||
sp-keyring = { path = "../../../primitives/keyring", version = "3.0.0"}
|
||||
sp-api = { path = "../../../primitives/api", version = "3.0.0"}
|
||||
sp-transaction-pool = { path = "../../../primitives/transaction-pool", version = "3.0.0"}
|
||||
sc-transaction-pool-api = { path = "../../../client/transaction-pool/api", version = "3.0.0"}
|
||||
sp-timestamp = { path = "../../../primitives/timestamp", version = "3.0.0"}
|
||||
|
||||
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.9.0"}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -48,6 +47,7 @@ pub use self::{
|
||||
rpc::{EngineCommand, CreatedBlock},
|
||||
};
|
||||
use sp_api::{ProvideRuntimeApi, TransactionFor};
|
||||
use sc_transaction_pool_api::TransactionPool;
|
||||
|
||||
/// The `ConsensusEngineId` of Manual Seal.
|
||||
pub const MANUAL_SEAL_ENGINE_ID: ConsensusEngineId = [b'm', b'a', b'n', b'l'];
|
||||
@@ -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>, TP, SC, CS, CIDP> {
|
||||
/// Block import instance for well. importing blocks.
|
||||
pub block_import: BI,
|
||||
|
||||
@@ -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<TP>,
|
||||
|
||||
/// Stream<Item = EngineCommands>, Basically the receiving end of a channel for sending commands to
|
||||
/// the authorship task.
|
||||
@@ -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>, TP, SC, CIDP> {
|
||||
/// Block import instance for well. importing blocks.
|
||||
pub block_import: BI,
|
||||
|
||||
@@ -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<TP>,
|
||||
|
||||
/// SelectChain strategy.
|
||||
pub select_chain: SC,
|
||||
@@ -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, TP, SC, CS, CIDP>(
|
||||
ManualSealParams {
|
||||
mut block_import,
|
||||
mut env,
|
||||
@@ -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, TP, 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,
|
||||
@@ -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,
|
||||
TP: TransactionPool<Block = B>,
|
||||
CIDP: CreateInherentDataProviders<B, ()>,
|
||||
{
|
||||
while let Some(command) = commands_stream.next().await {
|
||||
@@ -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, TP, SC, CIDP>(
|
||||
InstantSealParams {
|
||||
block_import,
|
||||
env,
|
||||
@@ -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, TP, 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,
|
||||
@@ -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,
|
||||
TP: 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,
|
||||
@@ -277,7 +276,7 @@ mod tests {
|
||||
};
|
||||
use sc_transaction_pool::{BasicPool, RevalidationType, Options};
|
||||
use substrate_test_runtime_transaction_pool::{TestApi, uxt};
|
||||
use sp_transaction_pool::{TransactionPool, MaintainedTransactionPool, TransactionSource};
|
||||
use sc_transaction_pool_api::{TransactionPool, MaintainedTransactionPool, TransactionSource};
|
||||
use sp_runtime::generic::BlockId;
|
||||
use sp_consensus::ImportedAux;
|
||||
use sc_basic_authorship::ProposerFactory;
|
||||
@@ -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(()) },
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -522,7 +521,7 @@ mod tests {
|
||||
assert!(pool.submit_one(&BlockId::Number(1), SOURCE, uxt(Alice, 1)).await.is_ok());
|
||||
|
||||
let header = client.header(&BlockId::Number(1)).expect("db error").expect("imported above");
|
||||
pool.maintain(sp_transaction_pool::ChainEvent::NewBestBlock {
|
||||
pool.maintain(sc_transaction_pool_api::ChainEvent::NewBestBlock {
|
||||
hash: header.hash(),
|
||||
tree_route: None,
|
||||
}).await;
|
||||
|
||||
@@ -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,
|
||||
@@ -35,12 +34,13 @@ use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
use sp_inherents::{CreateInherentDataProviders, InherentDataProvider};
|
||||
use sp_api::{ProvideRuntimeApi, TransactionFor};
|
||||
use sc_transaction_pool_api::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, TP, CIDP> {
|
||||
/// if true, empty blocks(without extrinsics) will be created.
|
||||
/// otherwise, will return Error::EmptyTransactionPool.
|
||||
pub create_empty: bool,
|
||||
@@ -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<TP>,
|
||||
/// header backend
|
||||
pub client: Arc<C>,
|
||||
/// Environment trait object for creating a proposer
|
||||
@@ -67,7 +67,7 @@ pub struct SealBlockParams<'a, B: BlockT, BI, SC, C: ProvideRuntimeApi<B>, E, P:
|
||||
}
|
||||
|
||||
/// seals a new block with the given params
|
||||
pub async fn seal_block<B, BI, SC, C, E, P, CIDP>(
|
||||
pub async fn seal_block<B, BI, SC, C, E, TP, CIDP>(
|
||||
SealBlockParams {
|
||||
create_empty,
|
||||
finalize,
|
||||
@@ -80,7 +80,7 @@ pub async fn seal_block<B, BI, SC, C, E, P, CIDP>(
|
||||
create_inherent_data_providers,
|
||||
consensus_data_provider: digest_provider,
|
||||
mut sender,
|
||||
}: SealBlockParams<'_, B, BI, SC, C, E, P, CIDP>,
|
||||
}: SealBlockParams<'_, B, BI, SC, C, E, TP, CIDP>,
|
||||
) where
|
||||
B: BlockT,
|
||||
BI: BlockImport<B, Error = sp_consensus::Error, Transaction = sp_api::TransactionFor<C, B>>
|
||||
@@ -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>,
|
||||
TP: 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user