mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: always accept transactions with current nonce (#11931)
This commit is contained in:
@ -1421,11 +1421,15 @@ impl<T: PoolTransaction> AllTransactions<T> {
|
||||
fn ensure_valid(
|
||||
&self,
|
||||
transaction: ValidPoolTransaction<T>,
|
||||
on_chain_nonce: u64,
|
||||
) -> Result<ValidPoolTransaction<T>, InsertErr<T>> {
|
||||
if !self.local_transactions_config.is_local(transaction.origin, transaction.sender()) {
|
||||
let current_txs =
|
||||
self.tx_counter.get(&transaction.sender_id()).copied().unwrap_or_default();
|
||||
if current_txs >= self.max_account_slots {
|
||||
|
||||
// Reject transactions if sender's capacity is exceeded.
|
||||
// If transaction's nonce matches on-chain nonce always let it through
|
||||
if current_txs >= self.max_account_slots && transaction.nonce() > on_chain_nonce {
|
||||
return Err(InsertErr::ExceededSenderTransactionsCapacity {
|
||||
transaction: Arc::new(transaction),
|
||||
})
|
||||
@ -1592,7 +1596,7 @@ impl<T: PoolTransaction> AllTransactions<T> {
|
||||
) -> InsertResult<T> {
|
||||
assert!(on_chain_nonce <= transaction.nonce(), "Invalid transaction");
|
||||
|
||||
let mut transaction = self.ensure_valid(transaction)?;
|
||||
let mut transaction = self.ensure_valid(transaction, on_chain_nonce)?;
|
||||
|
||||
let inserted_tx_id = *transaction.id();
|
||||
let mut state = TxState::default();
|
||||
@ -2631,6 +2635,7 @@ mod tests {
|
||||
let mut pool = AllTransactions::default();
|
||||
|
||||
let mut tx = MockTransaction::eip1559();
|
||||
let unblocked_tx = tx.clone();
|
||||
for _ in 0..pool.max_account_slots {
|
||||
tx = tx.next();
|
||||
pool.insert_tx(f.validated(tx.clone()), on_chain_balance, on_chain_nonce).unwrap();
|
||||
@ -2644,6 +2649,10 @@ mod tests {
|
||||
let err =
|
||||
pool.insert_tx(f.validated(tx.next()), on_chain_balance, on_chain_nonce).unwrap_err();
|
||||
assert!(matches!(err, InsertErr::ExceededSenderTransactionsCapacity { .. }));
|
||||
|
||||
assert!(pool
|
||||
.insert_tx(f.validated(unblocked_tx), on_chain_balance, on_chain_nonce)
|
||||
.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user