diff --git a/node/service/src/custom_tx_pool.rs b/node/service/src/custom_tx_pool.rs new file mode 100644 index 0000000000..81126e8ee0 --- /dev/null +++ b/node/service/src/custom_tx_pool.rs @@ -0,0 +1,101 @@ +use futures::Future; +use sc_transaction_pool_api::{ + ImportNotificationStream, PoolFuture, PoolStatus, ReadyTransactions, TransactionFor, + TransactionPool, TransactionSource, TransactionStatusStreamFor, TxHash, +}; +use sp_runtime::traits::{Block as BlockT, NumberFor}; +use std::{collections::HashMap, pin::Pin, sync::Arc}; + +pub struct CustomPool { + inner_pool: Arc, +} + +impl CustomPool { + pub fn new(inner_pool: Arc) -> Self { + Self { inner_pool } + } +} + +impl TransactionPool for CustomPool +where + I: TransactionPool, +{ + type Block = I::Block; + type Hash = I::Hash; + type InPoolTransaction = I::InPoolTransaction; + type Error = I::Error; + + fn submit_at( + &self, + at: ::Hash, + source: TransactionSource, + xts: Vec>, + ) -> PoolFuture, Self::Error>>, Self::Error> { + self.inner_pool.submit_at(at, source, xts) + } + + fn submit_one( + &self, + at: ::Hash, + source: TransactionSource, + xt: TransactionFor, + ) -> PoolFuture, Self::Error> { + self.inner_pool.submit_one(at, source, xt) + } + + fn submit_and_watch( + &self, + at: ::Hash, + source: TransactionSource, + xt: TransactionFor, + ) -> PoolFuture>>, Self::Error> { + self.inner_pool.submit_and_watch(at, source, xt) + } + + fn remove_invalid(&self, _: &[TxHash]) -> Vec> { + // Don't do anything on purpose. + Vec::new() + } + + fn status(&self) -> PoolStatus { + self.inner_pool.status() + } + + fn import_notification_stream(&self) -> ImportNotificationStream> { + self.inner_pool.import_notification_stream() + } + + fn hash_of(&self, xt: &TransactionFor) -> TxHash { + self.inner_pool.hash_of(xt) + } + + fn on_broadcasted(&self, propagations: HashMap, Vec>) { + self.inner_pool.on_broadcasted(propagations) + } + + fn ready_transaction(&self, hash: &TxHash) -> Option> { + self.inner_pool.ready_transaction(hash) + } + + fn ready_at( + &self, + at: NumberFor, + ) -> Pin< + Box< + dyn Future< + Output = Box> + Send>, + > + Send, + >, + > { + self.inner_pool.ready_at(at) + } + + fn ready(&self) -> Box> + Send> { + self.inner_pool.ready() + } + + fn futures(&self) -> Vec { + self.inner_pool.futures() + } +} + diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index d67b9e9b56..0fa7034060 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -8,5 +8,6 @@ pub mod block_sealing; pub mod chain_spec; pub mod common; +mod custom_tx_pool; pub mod rpc; pub mod service; diff --git a/node/service/src/service.rs b/node/service/src/service.rs index af8830cfd2..48d170bc8b 100644 --- a/node/service/src/service.rs +++ b/node/service/src/service.rs @@ -437,7 +437,7 @@ fn start_consensus( let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( task_manager.spawn_handle(), client.clone(), - transaction_pool, + std::sync::Arc::new(crate::custom_tx_pool::CustomPool::new(transaction_pool)), prometheus_registry, telemetry.clone(), );