From 07a5a23bd72915b8e8050509de3849d706e9540c Mon Sep 17 00:00:00 2001 From: Kai <7630809+Kailai-Wang@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:28:30 +0100 Subject: [PATCH] Use custom txpool to workaround the invalid tx (#3211) * init * remove delayed-best-block --- parachain/Cargo.toml | 2 +- parachain/node/src/custom_txpool.rs | 100 ++++++++++++++++++++++++++++ parachain/node/src/main.rs | 1 + parachain/node/src/service.rs | 16 ++++- parachain/zombienet/config.toml | 1 - 5 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 parachain/node/src/custom_txpool.rs diff --git a/parachain/Cargo.toml b/parachain/Cargo.toml index fb8c725e60..1f7d120a9d 100644 --- a/parachain/Cargo.toml +++ b/parachain/Cargo.toml @@ -168,11 +168,11 @@ sc-sysinfo = { git = "https://github.com/paritytech/polkadot-sdk", branch = "sta sc-telemetry = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } sc-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } sc-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } +sc-transaction-pool-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } -sc-transaction-pool-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } # wasm diff --git a/parachain/node/src/custom_txpool.rs b/parachain/node/src/custom_txpool.rs new file mode 100644 index 0000000000..40d51b0ac8 --- /dev/null +++ b/parachain/node/src/custom_txpool.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/parachain/node/src/main.rs b/parachain/node/src/main.rs index bfdba099d8..0bf81a5634 100644 --- a/parachain/node/src/main.rs +++ b/parachain/node/src/main.rs @@ -19,6 +19,7 @@ mod chain_specs; mod cli; mod command; +mod custom_txpool; mod evm_tracing_types; mod rpc; mod service; diff --git a/parachain/node/src/service.rs b/parachain/node/src/service.rs index 5ae8821156..d31c11bd24 100644 --- a/parachain/node/src/service.rs +++ b/parachain/node/src/service.rs @@ -749,11 +749,17 @@ where let select_chain = maybe_select_chain .expect("In `standalone` mode, `new_partial` will return some `select_chain`; qed"); + // TODO: use fork-aware txpool when paritytech/polkadot-sdk#4639 is included in a stable release + // presumably in stable2412 + // This is a workaround mentioned in https://github.com/paritytech/polkadot-sdk/issues/1202 + let custom_txpool = + std::sync::Arc::new(crate::custom_txpool::CustomPool::new(transaction_pool.clone())); + if role.is_authority() { let proposer_factory = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), client.clone(), - transaction_pool.clone(), + custom_txpool, None, None, ); @@ -1059,10 +1065,16 @@ where + cumulus_primitives_aura::AuraUnincludedSegmentApi + cumulus_primitives_core::CollectCollationInfo, { + // TODO: use fork-aware txpool when paritytech/polkadot-sdk#4639 is included in a stable release + // presumably in stable2412 + // This is a workaround mentioned in https://github.com/paritytech/polkadot-sdk/issues/1202 + let custom_txpool = + std::sync::Arc::new(crate::custom_txpool::CustomPool::new(transaction_pool.clone())); + let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( task_manager.spawn_handle(), client.clone(), - transaction_pool, + custom_txpool, prometheus_registry, telemetry.clone(), ); diff --git a/parachain/zombienet/config.toml b/parachain/zombienet/config.toml index cb17da902b..a7a4209aa3 100644 --- a/parachain/zombienet/config.toml +++ b/parachain/zombienet/config.toml @@ -31,7 +31,6 @@ args = [ "--force-authoring", "--enable-evm-rpc", "--state-pruning=archive", - "--delayed-best-block", "-l=parachain=debug,txpool=trace" ] ws_port = {{COLLATOR_WS_PORT}}