From 3c383bfbb78e675e2761d8f711b0d9a1b2f926e7 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Tue, 17 Oct 2023 10:36:55 -0400 Subject: [PATCH] fix: order transactions by nonce before inserting into txpool (#4989) Co-authored-by: Matthias Seitz --- crates/net/network/src/transactions.rs | 5 +++-- crates/payload/basic/src/lib.rs | 1 + crates/primitives/src/transaction/pooled.rs | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/net/network/src/transactions.rs b/crates/net/network/src/transactions.rs index 32d9e5d09..cfeebebfe 100644 --- a/crates/net/network/src/transactions.rs +++ b/crates/net/network/src/transactions.rs @@ -541,7 +541,8 @@ where .0 .into_iter() .map(PooledTransactionsElement::try_from_broadcast) - .filter_map(Result::ok); + .filter_map(Result::ok) + .collect(); self.import_transactions(peer_id, non_blob_txs, TransactionSource::Broadcast); @@ -644,7 +645,7 @@ where fn import_transactions( &mut self, peer_id: PeerId, - transactions: impl IntoIterator, + transactions: Vec, source: TransactionSource, ) { // If the node is pipeline syncing, ignore transactions diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index 94c80a09e..ff2db5d88 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -734,6 +734,7 @@ where // we can't fit this _blob_ transaction into the block, so we mark it as invalid, // which removes its dependent transactions from the iterator. This is similar to // the gas limit condition for regular transactions above. + trace!(target: "payload_builder", tx=?tx.hash, ?sum_blob_gas_used, ?tx_blob_gas, "skipping blob transaction because it would exceed the max data gas per block"); best_txs.mark_invalid(&pool_tx); continue } diff --git a/crates/primitives/src/transaction/pooled.rs b/crates/primitives/src/transaction/pooled.rs index 22b59637b..4f207968d 100644 --- a/crates/primitives/src/transaction/pooled.rs +++ b/crates/primitives/src/transaction/pooled.rs @@ -88,6 +88,16 @@ impl PooledTransactionsElement { } } + /// Returns the transaction nonce. + pub fn nonce(&self) -> u64 { + match self { + Self::Legacy { transaction, .. } => transaction.nonce, + Self::Eip2930 { transaction, .. } => transaction.nonce, + Self::Eip1559 { transaction, .. } => transaction.nonce, + Self::BlobTransaction(blob_tx) => blob_tx.transaction.nonce, + } + } + /// Recover signer from signature and hash. /// /// Returns `None` if the transaction's signature is invalid, see also [Self::recover_signer].