Skip to content

Commit

Permalink
fix: order transactions by nonce before inserting into txpool (paradi…
Browse files Browse the repository at this point in the history
…gmxyz#4989)

Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
Rjected and mattsse authored Oct 17, 2023
1 parent 1483175 commit 3c383bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/net/network/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -644,7 +645,7 @@ where
fn import_transactions(
&mut self,
peer_id: PeerId,
transactions: impl IntoIterator<Item = PooledTransactionsElement>,
transactions: Vec<PooledTransactionsElement>,
source: TransactionSource,
) {
// If the node is pipeline syncing, ignore transactions
Expand Down
1 change: 1 addition & 0 deletions crates/payload/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions crates/primitives/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down

0 comments on commit 3c383bf

Please sign in to comment.