@@ -15,6 +15,7 @@ use bop_common::{
1515} ;
1616use reth_optimism_primitives:: transaction:: OpTransaction ;
1717use reth_primitives_traits:: InMemorySize ;
18+ use rustc_hash:: FxHashMap ;
1819
1920use crate :: transaction:: pending:: PendingOrders ;
2021
@@ -67,14 +68,20 @@ impl TxPool {
6768 return false ;
6869 }
6970
71+ let mut nonce_diffs = FxHashMap :: default ( ) ;
72+
7073 // Simple transaction validation closure
71- let validate_tx = |tx : & Transaction | {
72- let state_nonce = db. get_nonce ( tx. sender ( ) ) . expect ( "failed to get nonce" ) ;
74+ let validate_tx = |tx : & Transaction , diffs : & mut FxHashMap < Address , u64 > | {
75+ let mut expected_nonce = db. get_nonce ( tx. sender ( ) ) . expect ( "failed to get nonce" ) ;
76+ // Add the nonce diff from txs already validated in this bundle
77+ if let Some ( diff) = diffs. get ( tx. sender_ref ( ) ) {
78+ expected_nonce += diff;
79+ }
80+
7381 let nonce = tx. nonce ( ) ;
7482
7583 // Only accept transactions with the correct nonce
76- // TODO: We might want a bundle queueing mechanism.
77- if nonce != state_nonce || !tx. valid_for_block ( base_fee) {
84+ if nonce != expected_nonce || !tx. valid_for_block ( base_fee) {
7885 return false ;
7986 }
8087
@@ -85,11 +92,13 @@ impl TxPool {
8592 return false ;
8693 }
8794
95+ diffs. entry ( tx. sender ( ) ) . and_modify ( |diff| * diff += 1 ) . or_insert ( 1 ) ;
96+
8897 true
8998 } ;
9099
91100 // Validate all transactions in the bundle
92- if !bundle. transactions . iter ( ) . all ( validate_tx) {
101+ if !bundle. transactions . iter ( ) . all ( |tx| validate_tx ( tx , & mut nonce_diffs ) ) {
93102 return false ;
94103 }
95104
0 commit comments