diff --git a/crates/mempool/src/mempool.rs b/crates/mempool/src/mempool.rs index bd3e329c43..64d38f0c86 100644 --- a/crates/mempool/src/mempool.rs +++ b/crates/mempool/src/mempool.rs @@ -93,6 +93,8 @@ impl Mempool { let next_nonce = nonce.try_increment().map_err(|_| MempoolError::FeltOutOfRange)?; // Align the queue with the committed nonces. + + // Remove transactions with lower nonces from the queue and the pool. if self .tx_queue .get_nonce(address) @@ -100,14 +102,13 @@ impl Mempool { { self.tx_queue.remove(address); } + self.tx_pool.remove_up_to_nonce(address, next_nonce); if self.tx_queue.get_nonce(address).is_none() { if let Some(tx) = self.tx_pool.get_by_address_and_nonce(address, next_nonce) { self.tx_queue.insert(*tx); } } - - self.tx_pool.remove_up_to_nonce(address, next_nonce); } // Rewind nonces of addresses that were not included in block. @@ -126,6 +127,9 @@ impl Mempool { let MempoolInput { tx, account: Account { sender_address, state: AccountState { nonce } } } = input; + self.tx_pool.insert((&tx).into())?; + + // Remove transactions with lower nonces from the queue and the pool. // Note: != is actually equivalent to > here, as lower nonces are rejected in validation. if self.tx_queue.get_nonce(sender_address).is_some_and(|queued_nonce| queued_nonce != nonce) { @@ -133,8 +137,6 @@ impl Mempool { } self.tx_pool.remove_up_to_nonce(sender_address, nonce); - self.tx_pool.insert((&tx).into())?; - // Maybe close nonce gap. if self.tx_queue.get_nonce(sender_address).is_none() { if let Some(tx_reference) = self.tx_pool.get_by_address_and_nonce(sender_address, nonce)