From 6430731fff06bfde15318667240d5738505fd6f8 Mon Sep 17 00:00:00 2001 From: "Supernovahs.eth" <91280922+supernovahs@users.noreply.github.com> Date: Thu, 11 Jan 2024 13:42:32 +0530 Subject: [PATCH] feat: Exclude private txs for pending block (#6015) Co-authored-by: Matthias Seitz --- crates/rpc/rpc/src/eth/api/pending_block.rs | 8 ++++++++ crates/transaction-pool/src/traits.rs | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/rpc/rpc/src/eth/api/pending_block.rs b/crates/rpc/rpc/src/eth/api/pending_block.rs index 32c2fdc25..8ab260dc6 100644 --- a/crates/rpc/rpc/src/eth/api/pending_block.rs +++ b/crates/rpc/rpc/src/eth/api/pending_block.rs @@ -101,6 +101,14 @@ impl PendingBlockEnv { continue } + if pool_tx.origin.is_private() { + // we don't want to leak any state changes made by private transactions, so we mark + // them as invalid here which removes all dependent transactions from the iterator + // before we can continue + best_txs.mark_invalid(&pool_tx); + continue; + } + // convert tx to a signed transaction let tx = pool_tx.to_recovered_transaction(); diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 70875cd0f..1eef5ac85 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -523,9 +523,18 @@ pub enum TransactionOrigin { impl TransactionOrigin { /// Whether the transaction originates from a local source. - pub fn is_local(&self) -> bool { + pub const fn is_local(&self) -> bool { matches!(self, TransactionOrigin::Local) } + + /// Whether the transaction originates from an external source. + pub const fn is_external(&self) -> bool { + matches!(self, TransactionOrigin::External) + } + /// Whether the transaction originates from a private source. + pub const fn is_private(&self) -> bool { + matches!(self, TransactionOrigin::Private) + } } /// Represents changes after a new canonical block or range of canonical blocks was added to the