From 9263aff2162758f81d0aed330c1282ffdf413f64 Mon Sep 17 00:00:00 2001 From: Aleksandar Brayanov Date: Mon, 2 Dec 2024 15:56:01 +0000 Subject: [PATCH] feat: added as_any implementation to FullClientTransactionPool --- .../client/transaction-pool/src/builder.rs | 34 +++++++++++-------- substrate/client/transaction-pool/src/lib.rs | 2 +- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/substrate/client/transaction-pool/src/builder.rs b/substrate/client/transaction-pool/src/builder.rs index e1fddcdd8952..42f7506cd989 100644 --- a/substrate/client/transaction-pool/src/builder.rs +++ b/substrate/client/transaction-pool/src/builder.rs @@ -110,19 +110,19 @@ impl TransactionPoolOptions { /// This trait defines the requirements for a full client transaction pool, ensuring /// that it can handle transactions submission and maintenance. pub trait FullClientTransactionPool: - MaintainedTransactionPool< - Block = Block, - Hash = ExtrinsicHash>, - InPoolTransaction = Transaction< - ExtrinsicHash>, - ExtrinsicFor>, - >, - Error = as ChainApi>::Error, - > + LocalTransactionPool< - Block = Block, - Hash = ExtrinsicHash>, - Error = as ChainApi>::Error, - > +MaintainedTransactionPool< + Block = Block, + Hash = ExtrinsicHash>, + InPoolTransaction=Transaction< + ExtrinsicHash>, + ExtrinsicFor>, + >, + Error = as ChainApi>::Error, +> + LocalTransactionPool< + Block = Block, + Hash = ExtrinsicHash>, + Error = as ChainApi>::Error, +> + std::any::Any where Block: BlockT, Client: sp_api::ProvideRuntimeApi @@ -133,6 +133,9 @@ where + 'static, Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue, { + /// Return the inner pool as a `&dyn Any`, can be used to downcast to the concrete pool + /// type and use methods that only exist in that pool implementation. + fn as_any(&self) -> &dyn std::any::Any; } impl FullClientTransactionPool for P @@ -157,8 +160,11 @@ where Block = Block, Hash = ExtrinsicHash>, Error = as ChainApi>::Error, - >, + >+ 'static, { + fn as_any(&self) -> &dyn std::any::Any { + self as &dyn std::any::Any + } } /// The public type alias for the actual type providing the implementation of diff --git a/substrate/client/transaction-pool/src/lib.rs b/substrate/client/transaction-pool/src/lib.rs index 888d25d3a0d2..a6c66cbd0ced 100644 --- a/substrate/client/transaction-pool/src/lib.rs +++ b/substrate/client/transaction-pool/src/lib.rs @@ -33,7 +33,7 @@ use common::{api, enactment_state}; use std::{future::Future, pin::Pin, sync::Arc}; pub use api::FullChainApi; -pub use builder::{Builder, TransactionPoolHandle, TransactionPoolOptions, TransactionPoolType}; +pub use builder::{Builder, TransactionPoolHandle, TransactionPoolOptions, TransactionPoolType, FullClientTransactionPool}; pub use common::notification_future; pub use fork_aware_txpool::{ForkAwareTxPool, ForkAwareTxPoolTask}; pub use graph::{base_pool::Limit as PoolLimit, ChainApi, Options, Pool};