diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ce0b33b7d..a8280aa2f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ * (store) [#1526](https://github.com/crypto-org-chain/cronos/pull/1526) Cache index/filters in rocksdb application.db to reduce ram usage. * (store)[#1529](https://github.com/crypto-org-chain/cronos/pull/1529) Enable pinL0FilterAndIndexBlocksInCache. * (store)[#1547](https://github.com/crypto-org-chain/cronos/pull/1547) Disable memiavl cache if block-stm is enabled. +* (app) [#1563](https://github.com/crypto-org-chain/cronos/pull/1563) Only replace tx if new priority is larger. ### Bug Fixes diff --git a/app/app.go b/app/app.go index 7da2128af5..7e503881e2 100644 --- a/app/app.go +++ b/app/app.go @@ -375,6 +375,10 @@ func New( TxPriority: mempool.NewDefaultTxPriority(), SignerExtractor: evmapp.NewEthSignerExtractionAdapter(mempool.NewDefaultSignerExtractionAdapter()), MaxTx: maxTxs, + TxReplacement: func(op, np int64, oTx, nTx sdk.Tx) bool { + // tx is only replaced if new priority is higher than old priority + return np > op + }, }) handler := baseapp.NewDefaultProposalHandler(mempool, app) diff --git a/integration_tests/test_mempool.py b/integration_tests/test_mempool.py index bdd921cab1..f70c663e49 100644 --- a/integration_tests/test_mempool.py +++ b/integration_tests/test_mempool.py @@ -80,3 +80,37 @@ def test_blocked_address(cronos_mempool): rsp = cli.transfer("signer1", cli.address("validator"), "1basecro") assert rsp["code"] != 0 assert "signer is blocked" in rsp["raw_log"] + + +@pytest.mark.flaky(max_runs=5) +def test_tx_replacement(cronos_mempool): + w3: Web3 = cronos_mempool.w3 + account = "community" + nonce = w3.eth.get_transaction_count(ADDRS[account]) + gas_price = w3.eth.gas_price + reduction = 1000000 + # the second tx should replace the first tx with higher priority, + # but the third one shouldn't replace the second one. + prices = [ + gas_price, + gas_price + 2 * reduction, + gas_price + reduction, + ] + txs = [ + sign_transaction( + w3, + { + "to": ADDRS[account], + "value": 1, + "gas": 21000, + "gasPrice": price, + "nonce": nonce, + }, + KEYS[account], + ) + for price in prices + ] + + txhashes = [w3.eth.send_raw_transaction(tx.rawTransaction) for tx in txs] + receipt = w3.eth.wait_for_transaction_receipt(txhashes[1]) + assert receipt.status == 1