From 741fcca9b6e95e831a0a4a62b901558446c0d944 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Tue, 28 May 2024 08:38:57 +0200 Subject: [PATCH] Workaround for disallowed transaction superseding (#2181) * Workaround for disallowed transaction superseding The transaction spammer from Kurtosis keeps spamming transactions with the same nonce because report 'pending' account nocne based on 'latest' rather than actually considering the mempool. To avoid errors from rejecting those, disable the required gas price bump when replacing a transaction with a new nonce. * Lint * Skip superseding negative test --- nimbus/core/tx_pool/tx_tasks/tx_add.nim | 16 ++++++++++++---- tests/test_txpool.nim | 11 ++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/nimbus/core/tx_pool/tx_tasks/tx_add.nim b/nimbus/core/tx_pool/tx_tasks/tx_add.nim index 01e95f087..b37fb814d 100644 --- a/nimbus/core/tx_pool/tx_tasks/tx_add.nim +++ b/nimbus/core/tx_pool/tx_tasks/tx_add.nim @@ -77,10 +77,18 @@ proc supersede(xp: TxPoolRef; item: TxItemRef): Result[void,TxInfo] return err(txInfoErrUnspecified) current = rc.value.data - # verify whether replacing is allowed, at all - let bumpPrice = (current.tx.gasPrice * xp.priceBump.GasInt + 99) div 100 - if item.tx.gasPrice < current.tx.gasPrice + bumpPrice: - return err(txInfoErrReplaceUnderpriced) + # TODO: To unblock `kurtosis-tech/ethereum-package` based testing, + # we have to accept superseding transactions temporarily until `rpc_utils.nim` + # supports the 'pending' tag by incorporating pending transactions from the + # mempool when returning the current account nonce. Until that is fixed, + # we keep telling the transaction spammer that their nonce has not changed, + # and it keeps spamming transactions with the same nonce repeatedly. + # Note: When this is fixed, update `tests/test_txpool.nim` and + # re-enable the "Superseding txs with sender and nonce variants" test case. + if false: + let bumpPrice = (current.tx.gasPrice * xp.priceBump.GasInt + 99) div 100 + if item.tx.gasPrice < current.tx.gasPrice + bumpPrice: + return err(txInfoErrReplaceUnderpriced) # make space, delete item if not xp.txDB.dispose(current, txInfoSenderNonceSuperseded): diff --git a/tests/test_txpool.nim b/tests/test_txpool.nim index 0e201c01b..a34a7d10b 100644 --- a/tests/test_txpool.nim +++ b/tests/test_txpool.nim @@ -301,11 +301,12 @@ proc runTxPoolTests(noisy = true) = check xq.nItems.total == testTxs.len check xq.nItems.disposed == testTxs.len - # last update item was underpriced, so it must not have been - # replaced - var altLst = testTxs.toSeq.mapIt("alt " & it[0].info) - altLst[^1] = testTxs[^1][0].info - check altLst.sorted == xq.toItems.toSeq.mapIt(it.info).sorted + if false: # Temporarily disabled, see `supersede` in `tx_add.nim` + # last update item was underpriced, so it must not have been + # replaced + var altLst = testTxs.toSeq.mapIt("alt " & it[0].info) + altLst[^1] = testTxs[^1][0].info + check altLst.sorted == xq.toItems.toSeq.mapIt(it.info).sorted test &"Deleting tx => also delete higher nonces":