mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 05:11:09 +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:
@@ -23,17 +23,23 @@
|
||||
#![warn(unused_extern_crates)]
|
||||
|
||||
mod api;
|
||||
mod graph;
|
||||
mod revalidation;
|
||||
mod metrics;
|
||||
|
||||
pub mod error;
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod testing;
|
||||
/// Common types for testing the transaction pool
|
||||
#[cfg(feature = "test-helpers")]
|
||||
pub mod test_helpers {
|
||||
pub use super::{
|
||||
graph::{ChainApi, Pool, NumberFor, BlockHash, ExtrinsicFor},
|
||||
revalidation::RevalidationQueue,
|
||||
};
|
||||
}
|
||||
|
||||
pub use sc_transaction_graph::{ChainApi, Options, Pool};
|
||||
pub use graph::{Options, Transaction};
|
||||
pub use crate::api::{FullChainApi, LightChainApi};
|
||||
|
||||
use std::{collections::{HashMap, HashSet}, sync::Arc, pin::Pin, convert::TryInto};
|
||||
use futures::{prelude::*, future::{self, ready}, channel::oneshot};
|
||||
use parking_lot::Mutex;
|
||||
@@ -43,23 +49,23 @@ use sp_runtime::{
|
||||
traits::{Block as BlockT, NumberFor, AtLeast32Bit, Extrinsic, Zero, Header as HeaderT},
|
||||
};
|
||||
use sp_core::traits::SpawnEssentialNamed;
|
||||
use sp_transaction_pool::{
|
||||
use sc_transaction_pool_api::{
|
||||
TransactionPool, PoolStatus, ImportNotificationStream, TxHash, TransactionFor,
|
||||
TransactionStatusStreamFor, MaintainedTransactionPool, PoolFuture, ChainEvent,
|
||||
TransactionSource,
|
||||
};
|
||||
use sc_transaction_graph::{IsValidator, ExtrinsicHash};
|
||||
use graph::{IsValidator, ExtrinsicHash};
|
||||
use wasm_timer::Instant;
|
||||
|
||||
use prometheus_endpoint::Registry as PrometheusRegistry;
|
||||
use crate::metrics::MetricsLink as PrometheusMetrics;
|
||||
|
||||
type BoxedReadyIterator<Hash, Data> = Box<
|
||||
dyn Iterator<Item=Arc<sc_transaction_graph::base_pool::Transaction<Hash, Data>>> + Send
|
||||
dyn Iterator<Item=Arc<graph::base_pool::Transaction<Hash, Data>>> + Send
|
||||
>;
|
||||
|
||||
type ReadyIteratorFor<PoolApi> = BoxedReadyIterator<
|
||||
sc_transaction_graph::ExtrinsicHash<PoolApi>, sc_transaction_graph::ExtrinsicFor<PoolApi>
|
||||
graph::ExtrinsicHash<PoolApi>, graph::ExtrinsicFor<PoolApi>
|
||||
>;
|
||||
|
||||
type PolledIterator<PoolApi> = Pin<Box<dyn Future<Output=ReadyIteratorFor<PoolApi>> + Send>>;
|
||||
@@ -73,9 +79,9 @@ pub type LightPool<Block, Client, Fetcher> = BasicPool<LightChainApi<Client, Fet
|
||||
pub struct BasicPool<PoolApi, Block>
|
||||
where
|
||||
Block: BlockT,
|
||||
PoolApi: ChainApi<Block=Block>,
|
||||
PoolApi: graph::ChainApi<Block=Block>,
|
||||
{
|
||||
pool: Arc<sc_transaction_graph::Pool<PoolApi>>,
|
||||
pool: Arc<graph::Pool<PoolApi>>,
|
||||
api: Arc<PoolApi>,
|
||||
revalidation_strategy: Arc<Mutex<RevalidationStrategy<NumberFor<Block>>>>,
|
||||
revalidation_queue: Arc<revalidation::RevalidationQueue<PoolApi>>,
|
||||
@@ -134,7 +140,7 @@ impl<T, Block: BlockT> ReadyPoll<T, Block> {
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
impl<PoolApi, Block> parity_util_mem::MallocSizeOf for BasicPool<PoolApi, Block>
|
||||
where
|
||||
PoolApi: ChainApi<Block=Block>,
|
||||
PoolApi: graph::ChainApi<Block=Block>,
|
||||
Block: BlockT,
|
||||
{
|
||||
fn size_of(&self, ops: &mut parity_util_mem::MallocSizeOfOps) -> usize {
|
||||
@@ -163,14 +169,14 @@ pub enum RevalidationType {
|
||||
impl<PoolApi, Block> BasicPool<PoolApi, Block>
|
||||
where
|
||||
Block: BlockT,
|
||||
PoolApi: ChainApi<Block=Block> + 'static,
|
||||
PoolApi: graph::ChainApi<Block=Block> + 'static,
|
||||
{
|
||||
/// Create new basic transaction pool with provided api, for tests.
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "test-helpers")]
|
||||
pub fn new_test(
|
||||
pool_api: Arc<PoolApi>,
|
||||
) -> (Self, Pin<Box<dyn Future<Output=()> + Send>>, intervalier::BackSignalControl) {
|
||||
let pool = Arc::new(sc_transaction_graph::Pool::new(Default::default(), true.into(), pool_api.clone()));
|
||||
let pool = Arc::new(graph::Pool::new(Default::default(), true.into(), pool_api.clone()));
|
||||
let (revalidation_queue, background_task, notifier) =
|
||||
revalidation::RevalidationQueue::new_test(pool_api.clone(), pool.clone());
|
||||
(
|
||||
@@ -190,7 +196,7 @@ impl<PoolApi, Block> BasicPool<PoolApi, Block>
|
||||
/// Create new basic transaction pool with provided api and custom
|
||||
/// revalidation type.
|
||||
pub fn with_revalidation_type(
|
||||
options: sc_transaction_graph::Options,
|
||||
options: graph::Options,
|
||||
is_validator: IsValidator,
|
||||
pool_api: Arc<PoolApi>,
|
||||
prometheus: Option<&PrometheusRegistry>,
|
||||
@@ -198,7 +204,7 @@ impl<PoolApi, Block> BasicPool<PoolApi, Block>
|
||||
spawner: impl SpawnEssentialNamed,
|
||||
best_block_number: NumberFor<Block>,
|
||||
) -> Self {
|
||||
let pool = Arc::new(sc_transaction_graph::Pool::new(options, is_validator, pool_api.clone()));
|
||||
let pool = Arc::new(graph::Pool::new(options, is_validator, pool_api.clone()));
|
||||
let (revalidation_queue, background_task) = match revalidation_type {
|
||||
RevalidationType::Light => (
|
||||
revalidation::RevalidationQueue::new(pool_api.clone(), pool.clone()),
|
||||
@@ -233,19 +239,25 @@ impl<PoolApi, Block> BasicPool<PoolApi, Block>
|
||||
}
|
||||
|
||||
/// Gets shared reference to the underlying pool.
|
||||
pub fn pool(&self) -> &Arc<sc_transaction_graph::Pool<PoolApi>> {
|
||||
pub fn pool(&self) -> &Arc<graph::Pool<PoolApi>> {
|
||||
&self.pool
|
||||
}
|
||||
|
||||
/// Get access to the underlying api
|
||||
#[cfg(feature = "test-helpers")]
|
||||
pub fn api(&self) -> &PoolApi {
|
||||
&self.api
|
||||
}
|
||||
}
|
||||
|
||||
impl<PoolApi, Block> TransactionPool for BasicPool<PoolApi, Block>
|
||||
where
|
||||
Block: BlockT,
|
||||
PoolApi: 'static + ChainApi<Block=Block>,
|
||||
PoolApi: 'static + graph::ChainApi<Block=Block>,
|
||||
{
|
||||
type Block = PoolApi::Block;
|
||||
type Hash = sc_transaction_graph::ExtrinsicHash<PoolApi>;
|
||||
type InPoolTransaction = sc_transaction_graph::base_pool::Transaction<
|
||||
type Hash = graph::ExtrinsicHash<PoolApi>;
|
||||
type InPoolTransaction = graph::base_pool::Transaction<
|
||||
TxHash<Self>, TransactionFor<Self>
|
||||
>;
|
||||
type Error = PoolApi::Error;
|
||||
@@ -361,7 +373,7 @@ where
|
||||
{
|
||||
/// Create new basic transaction pool for a light node with the provided api.
|
||||
pub fn new_light(
|
||||
options: sc_transaction_graph::Options,
|
||||
options: graph::Options,
|
||||
prometheus: Option<&PrometheusRegistry>,
|
||||
spawner: impl SpawnEssentialNamed,
|
||||
client: Arc<Client>,
|
||||
@@ -396,7 +408,7 @@ where
|
||||
{
|
||||
/// Create new basic transaction pool for a full node with the provided api.
|
||||
pub fn new_full(
|
||||
options: sc_transaction_graph::Options,
|
||||
options: graph::Options,
|
||||
is_validator: IsValidator,
|
||||
prometheus: Option<&PrometheusRegistry>,
|
||||
spawner: impl SpawnEssentialNamed,
|
||||
@@ -420,7 +432,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block, Client> sp_transaction_pool::LocalTransactionPool
|
||||
impl<Block, Client> sc_transaction_pool_api::LocalTransactionPool
|
||||
for BasicPool<FullChainApi<Client, Block>, Block>
|
||||
where
|
||||
Block: BlockT,
|
||||
@@ -432,15 +444,15 @@ where
|
||||
Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,
|
||||
{
|
||||
type Block = Block;
|
||||
type Hash = sc_transaction_graph::ExtrinsicHash<FullChainApi<Client, Block>>;
|
||||
type Error = <FullChainApi<Client, Block> as ChainApi>::Error;
|
||||
type Hash = graph::ExtrinsicHash<FullChainApi<Client, Block>>;
|
||||
type Error = <FullChainApi<Client, Block> as graph::ChainApi>::Error;
|
||||
|
||||
fn submit_local(
|
||||
&self,
|
||||
at: &BlockId<Self::Block>,
|
||||
xt: sp_transaction_pool::LocalTransactionFor<Self>,
|
||||
xt: sc_transaction_pool_api::LocalTransactionFor<Self>,
|
||||
) -> Result<Self::Hash, Self::Error> {
|
||||
use sc_transaction_graph::ValidatedTransaction;
|
||||
use graph::{ValidatedTransaction, ChainApi};
|
||||
use sp_runtime::traits::SaturatedConversion;
|
||||
use sp_runtime::transaction_validity::TransactionValidityError;
|
||||
|
||||
@@ -558,10 +570,10 @@ impl<N: Clone + Copy + AtLeast32Bit> RevalidationStatus<N> {
|
||||
}
|
||||
|
||||
/// Prune the known txs for the given block.
|
||||
async fn prune_known_txs_for_block<Block: BlockT, Api: ChainApi<Block = Block>>(
|
||||
async fn prune_known_txs_for_block<Block: BlockT, Api: graph::ChainApi<Block = Block>>(
|
||||
block_id: BlockId<Block>,
|
||||
api: &Api,
|
||||
pool: &sc_transaction_graph::Pool<Api>,
|
||||
pool: &graph::Pool<Api>,
|
||||
) -> Vec<ExtrinsicHash<Api>> {
|
||||
let extrinsics = api.block_body(&block_id).await
|
||||
.unwrap_or_else(|e| {
|
||||
@@ -598,7 +610,7 @@ async fn prune_known_txs_for_block<Block: BlockT, Api: ChainApi<Block = Block>>(
|
||||
impl<PoolApi, Block> MaintainedTransactionPool for BasicPool<PoolApi, Block>
|
||||
where
|
||||
Block: BlockT,
|
||||
PoolApi: 'static + ChainApi<Block=Block>,
|
||||
PoolApi: 'static + graph::ChainApi<Block=Block>,
|
||||
{
|
||||
fn maintain(&self, event: ChainEvent<Self::Block>) -> Pin<Box<dyn Future<Output=()> + Send>> {
|
||||
match event {
|
||||
|
||||
Reference in New Issue
Block a user