From 92b04f498ab027d867c6aaefa1a30a43ae3b033f Mon Sep 17 00:00:00 2001 From: magecnion Date: Thu, 12 Dec 2024 11:36:15 +0100 Subject: [PATCH] Add custom tx pool that skip `remove_invalid` when producing block (#910) * add custom tx pool that skip report_invalid * cargo fmt * add explanatory comment * cargo fmt --- node/src/custom_tx_pool.rs | 100 +++++++++++++++++++++++++++++++++++++ node/src/main.rs | 2 +- node/src/service.rs | 7 ++- zombienet/native.toml | 5 +- 4 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 node/src/custom_tx_pool.rs diff --git a/node/src/custom_tx_pool.rs b/node/src/custom_tx_pool.rs new file mode 100644 index 000000000..40d51b0ac --- /dev/null +++ b/node/src/custom_tx_pool.rs @@ -0,0 +1,100 @@ +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/src/main.rs b/node/src/main.rs index 6ebd867fe..1ebb1a7e7 100644 --- a/node/src/main.rs +++ b/node/src/main.rs @@ -23,9 +23,9 @@ mod chain_spec; mod service; mod cli; mod command; +mod custom_tx_pool; mod eth; mod rpc; - fn main() -> sc_cli::Result<()> { command::run() } diff --git a/node/src/service.rs b/node/src/service.rs index f4caee075..12f04f1a7 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -571,10 +571,15 @@ fn start_consensus( // NOTE: because we use Aura here explicitly, we can use `CollatorSybilResistance::Resistant` // when starting the network. + // TODO: Remove the custom tx pool when paritytech/polkadot-sdk#4639 is included in a stable + // release. This is a temporary workaround taken from here: https://github.com/frequency-chain/frequency/pull/2196. + let custom_transaction_pool = + std::sync::Arc::new(crate::custom_tx_pool::CustomPool::new(transaction_pool)); + let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( task_manager.spawn_handle(), client.clone(), - transaction_pool, + custom_transaction_pool, prometheus_registry, telemetry.clone(), ); diff --git a/zombienet/native.toml b/zombienet/native.toml index 4d03ed980..33d69ea35 100644 --- a/zombienet/native.toml +++ b/zombienet/native.toml @@ -27,16 +27,17 @@ force_decorator = "generic-evm" ws_port = 9999 command = "{{ZOMBIENET_LAOS_COMMAND}}" validator = true + args = ["--log=xcm=trace,aura=trace,txpool=trace,basic-authorship=trace"] [[parachains.collators]] name = "laos1" command = "{{ZOMBIENET_LAOS_COMMAND}}" validator = true - args = ["--log=xcm=trace"] + args = ["--log=xcm=trace,aura=trace,txpool=trace,basic-authorship=trace"] [[parachains.collators]] name = "laos2" command = "{{ZOMBIENET_LAOS_COMMAND}}" validator = true - args = ["--log=xcm=trace"] + args = ["--log=xcm=trace,aura=trace,txpool=trace,basic-authorship=trace"]