Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: tx is not replaced by priority #1563

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need align how ethereum replace tx

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. priceBump parameter
  2. Require both FeeCap and TipCap larger than the old one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same nonce tx will fail in checkTx in the first place, might not be trivial to support this feature.

},
})
handler := baseapp.NewDefaultProposalHandler(mempool, app)

Expand Down
34 changes: 34 additions & 0 deletions integration_tests/test_mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,37 @@
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]

Check failure on line 114 in integration_tests/test_mempool.py

View workflow job for this annotation

GitHub Actions / integration_tests (slow)

test_tx_replacement ValueError: {'code': -32000, 'message': '\ngithub.com/evmos/ethermint/app/ante.CheckAndSetEthSenderNonce\n\tgithub.com/evmos/ethermint/app/ante/eth.go:298\ngithub.com/evmos/ethermint/app/ante.NewAnteHandler.newEthAnteHandler.func2\n\tgithub.com/evmos/ethermint/app/ante/handler_options.go:148\ngithub.com/evmos/ethermint/app/ante.NewAnteHandler.func1\n\tgithub.com/evmos/ethermint/app/ante/ante.go:93\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTxWithMultiStore\n\tgithub.com/cosmos/cosmos-sdk/baseapp/baseapp.go:929\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx\n\tgithub.com/cosmos/cosmos-sdk/baseapp/baseapp.go:842\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).CheckTx\n\tgithub.com/cosmos/cosmos-sdk/baseapp/abci.go:350\ngithub.com/cosmos/cosmos-sdk/server.cometABCIWrapper.CheckTx\n\tgithub.com/cosmos/cosmos-sdk/server/cmt_abci.go:28\ngithub.com/cometbft/cometbft/abci/client.(*localClient).CheckTxAsync\n\tgithub.com/cometbft/cometbft/abci/client/local_client.go:51\ngithub.com/cometbft/cometbft/proxy.(*appConnMempool).CheckTxAsync\n\tgithub.com/cometbft/cometbft/proxy/app_conn.go:147\ngithub.com/cometbft/cometbft/mempool.(*CListMempool).CheckTx\n\tgithub.com/cometbft/cometbft/mempool/clist_mempool.go:270\ngithub.com/cometbft/cometbft/rpc/core.(*Environment).BroadcastTxSync\n\tgithub.com/cometbft/cometbft/rpc/core/mempool.go:35\ngithub.com/cometbft/cometbft/rpc/client/local.(*Local).BroadcastTxSync\n\tgithub.com/cometbft/cometbft/rpc/client/local/local.go:98\ngithub.com/cosmos/cosmos-sdk/client.Context.BroadcastTxSync\n\tgithub.com/cosmos/cosmos-sdk/client/broadcast.go:94\ngithub.com/cosmos/cosmos-sdk/client.Context.BroadcastTx\n\tgithub.com/cosmos/cosmos-sdk/client/broadcast.go:26\ngithub.com/evmos/ethermint/rpc/backend.(*Backend).SendRawTransaction\n\tgithub.com/evmos/ethermint/rpc/backend/call_tx.go:167\ngithub.com/evmos/ethermint/rpc/namespaces/ethereum/eth.(*PublicAPI).SendRawTransaction\n\tgithub.com/evmos/ethermint/rpc/namespaces/ethereum/eth/api.go:232\nreflect.Value.call\n\treflect/value.go:596\nreflect.Value.Call\n\treflect/value.go:380\ngithub.com/ethereum/go-ethereum/rpc.(*callback).call\n\tgithub.com/ethereum/go-ethereum/rpc/service.go:205\ngithub.com/ethereum/go-ethereum/rpc.(*handler).runMethod\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:513\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleCall\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:459\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleCallMsg\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:420\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleMsg.func1\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:256\ngithub.com/ethereum/go-ethereum/rpc.(*handler).startCallProc.func1\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:348\ninvalid nonce; got 0, expected 1: invalid sequence: invalid sequence'}

Check failure on line 114 in integration_tests/test_mempool.py

View workflow job for this annotation

GitHub Actions / integration_tests (slow)

test_tx_replacement ValueError: {'code': -32000, 'message': '\ngithub.com/evmos/ethermint/app/ante.CheckAndSetEthSenderNonce\n\tgithub.com/evmos/ethermint/app/ante/eth.go:298\ngithub.com/evmos/ethermint/app/ante.NewAnteHandler.newEthAnteHandler.func2\n\tgithub.com/evmos/ethermint/app/ante/handler_options.go:148\ngithub.com/evmos/ethermint/app/ante.NewAnteHandler.func1\n\tgithub.com/evmos/ethermint/app/ante/ante.go:93\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTxWithMultiStore\n\tgithub.com/cosmos/cosmos-sdk/baseapp/baseapp.go:929\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx\n\tgithub.com/cosmos/cosmos-sdk/baseapp/baseapp.go:842\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).CheckTx\n\tgithub.com/cosmos/cosmos-sdk/baseapp/abci.go:350\ngithub.com/cosmos/cosmos-sdk/server.cometABCIWrapper.CheckTx\n\tgithub.com/cosmos/cosmos-sdk/server/cmt_abci.go:28\ngithub.com/cometbft/cometbft/abci/client.(*localClient).CheckTxAsync\n\tgithub.com/cometbft/cometbft/abci/client/local_client.go:51\ngithub.com/cometbft/cometbft/proxy.(*appConnMempool).CheckTxAsync\n\tgithub.com/cometbft/cometbft/proxy/app_conn.go:147\ngithub.com/cometbft/cometbft/mempool.(*CListMempool).CheckTx\n\tgithub.com/cometbft/cometbft/mempool/clist_mempool.go:270\ngithub.com/cometbft/cometbft/rpc/core.(*Environment).BroadcastTxSync\n\tgithub.com/cometbft/cometbft/rpc/core/mempool.go:35\ngithub.com/cometbft/cometbft/rpc/client/local.(*Local).BroadcastTxSync\n\tgithub.com/cometbft/cometbft/rpc/client/local/local.go:98\ngithub.com/cosmos/cosmos-sdk/client.Context.BroadcastTxSync\n\tgithub.com/cosmos/cosmos-sdk/client/broadcast.go:94\ngithub.com/cosmos/cosmos-sdk/client.Context.BroadcastTx\n\tgithub.com/cosmos/cosmos-sdk/client/broadcast.go:26\ngithub.com/evmos/ethermint/rpc/backend.(*Backend).SendRawTransaction\n\tgithub.com/evmos/ethermint/rpc/backend/call_tx.go:167\ngithub.com/evmos/ethermint/rpc/namespaces/ethereum/eth.(*PublicAPI).SendRawTransaction\n\tgithub.com/evmos/ethermint/rpc/namespaces/ethereum/eth/api.go:232\nreflect.Value.call\n\treflect/value.go:596\nreflect.Value.Call\n\treflect/value.go:380\ngithub.com/ethereum/go-ethereum/rpc.(*callback).call\n\tgithub.com/ethereum/go-ethereum/rpc/service.go:205\ngithub.com/ethereum/go-ethereum/rpc.(*handler).runMethod\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:513\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleCall\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:459\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleCallMsg\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:420\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleMsg.func1\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:256\ngithub.com/ethereum/go-ethereum/rpc.(*handler).startCallProc.func1\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:348\ninvalid nonce; got 0, expected 1: invalid sequence: invalid sequence'}

Check failure on line 114 in integration_tests/test_mempool.py

View workflow job for this annotation

GitHub Actions / integration_tests (slow)

test_tx_replacement ValueError: {'code': -32000, 'message': '\ngithub.com/evmos/ethermint/app/ante.CheckAndSetEthSenderNonce\n\tgithub.com/evmos/ethermint/app/ante/eth.go:298\ngithub.com/evmos/ethermint/app/ante.NewAnteHandler.newEthAnteHandler.func2\n\tgithub.com/evmos/ethermint/app/ante/handler_options.go:148\ngithub.com/evmos/ethermint/app/ante.NewAnteHandler.func1\n\tgithub.com/evmos/ethermint/app/ante/ante.go:93\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTxWithMultiStore\n\tgithub.com/cosmos/cosmos-sdk/baseapp/baseapp.go:929\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx\n\tgithub.com/cosmos/cosmos-sdk/baseapp/baseapp.go:842\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).CheckTx\n\tgithub.com/cosmos/cosmos-sdk/baseapp/abci.go:350\ngithub.com/cosmos/cosmos-sdk/server.cometABCIWrapper.CheckTx\n\tgithub.com/cosmos/cosmos-sdk/server/cmt_abci.go:28\ngithub.com/cometbft/cometbft/abci/client.(*localClient).CheckTxAsync\n\tgithub.com/cometbft/cometbft/abci/client/local_client.go:51\ngithub.com/cometbft/cometbft/proxy.(*appConnMempool).CheckTxAsync\n\tgithub.com/cometbft/cometbft/proxy/app_conn.go:147\ngithub.com/cometbft/cometbft/mempool.(*CListMempool).CheckTx\n\tgithub.com/cometbft/cometbft/mempool/clist_mempool.go:270\ngithub.com/cometbft/cometbft/rpc/core.(*Environment).BroadcastTxSync\n\tgithub.com/cometbft/cometbft/rpc/core/mempool.go:35\ngithub.com/cometbft/cometbft/rpc/client/local.(*Local).BroadcastTxSync\n\tgithub.com/cometbft/cometbft/rpc/client/local/local.go:98\ngithub.com/cosmos/cosmos-sdk/client.Context.BroadcastTxSync\n\tgithub.com/cosmos/cosmos-sdk/client/broadcast.go:94\ngithub.com/cosmos/cosmos-sdk/client.Context.BroadcastTx\n\tgithub.com/cosmos/cosmos-sdk/client/broadcast.go:26\ngithub.com/evmos/ethermint/rpc/backend.(*Backend).SendRawTransaction\n\tgithub.com/evmos/ethermint/rpc/backend/call_tx.go:167\ngithub.com/evmos/ethermint/rpc/namespaces/ethereum/eth.(*PublicAPI).SendRawTransaction\n\tgithub.com/evmos/ethermint/rpc/namespaces/ethereum/eth/api.go:232\nreflect.Value.call\n\treflect/value.go:596\nreflect.Value.Call\n\treflect/value.go:380\ngithub.com/ethereum/go-ethereum/rpc.(*callback).call\n\tgithub.com/ethereum/go-ethereum/rpc/service.go:205\ngithub.com/ethereum/go-ethereum/rpc.(*handler).runMethod\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:513\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleCall\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:459\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleCallMsg\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:420\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleMsg.func1\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:256\ngithub.com/ethereum/go-ethereum/rpc.(*handler).startCallProc.func1\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:348\ninvalid nonce; got 0, expected 1: invalid sequence: invalid sequence'}

Check failure on line 114 in integration_tests/test_mempool.py

View workflow job for this annotation

GitHub Actions / integration_tests (slow)

test_tx_replacement ValueError: {'code': -32000, 'message': '\ngithub.com/evmos/ethermint/app/ante.CheckAndSetEthSenderNonce\n\tgithub.com/evmos/ethermint/app/ante/eth.go:298\ngithub.com/evmos/ethermint/app/ante.NewAnteHandler.newEthAnteHandler.func2\n\tgithub.com/evmos/ethermint/app/ante/handler_options.go:148\ngithub.com/evmos/ethermint/app/ante.NewAnteHandler.func1\n\tgithub.com/evmos/ethermint/app/ante/ante.go:93\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTxWithMultiStore\n\tgithub.com/cosmos/cosmos-sdk/baseapp/baseapp.go:929\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx\n\tgithub.com/cosmos/cosmos-sdk/baseapp/baseapp.go:842\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).CheckTx\n\tgithub.com/cosmos/cosmos-sdk/baseapp/abci.go:350\ngithub.com/cosmos/cosmos-sdk/server.cometABCIWrapper.CheckTx\n\tgithub.com/cosmos/cosmos-sdk/server/cmt_abci.go:28\ngithub.com/cometbft/cometbft/abci/client.(*localClient).CheckTxAsync\n\tgithub.com/cometbft/cometbft/abci/client/local_client.go:51\ngithub.com/cometbft/cometbft/proxy.(*appConnMempool).CheckTxAsync\n\tgithub.com/cometbft/cometbft/proxy/app_conn.go:147\ngithub.com/cometbft/cometbft/mempool.(*CListMempool).CheckTx\n\tgithub.com/cometbft/cometbft/mempool/clist_mempool.go:270\ngithub.com/cometbft/cometbft/rpc/core.(*Environment).BroadcastTxSync\n\tgithub.com/cometbft/cometbft/rpc/core/mempool.go:35\ngithub.com/cometbft/cometbft/rpc/client/local.(*Local).BroadcastTxSync\n\tgithub.com/cometbft/cometbft/rpc/client/local/local.go:98\ngithub.com/cosmos/cosmos-sdk/client.Context.BroadcastTxSync\n\tgithub.com/cosmos/cosmos-sdk/client/broadcast.go:94\ngithub.com/cosmos/cosmos-sdk/client.Context.BroadcastTx\n\tgithub.com/cosmos/cosmos-sdk/client/broadcast.go:26\ngithub.com/evmos/ethermint/rpc/backend.(*Backend).SendRawTransaction\n\tgithub.com/evmos/ethermint/rpc/backend/call_tx.go:167\ngithub.com/evmos/ethermint/rpc/namespaces/ethereum/eth.(*PublicAPI).SendRawTransaction\n\tgithub.com/evmos/ethermint/rpc/namespaces/ethereum/eth/api.go:232\nreflect.Value.call\n\treflect/value.go:596\nreflect.Value.Call\n\treflect/value.go:380\ngithub.com/ethereum/go-ethereum/rpc.(*callback).call\n\tgithub.com/ethereum/go-ethereum/rpc/service.go:205\ngithub.com/ethereum/go-ethereum/rpc.(*handler).runMethod\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:513\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleCall\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:459\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleCallMsg\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:420\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleMsg.func1\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:256\ngithub.com/ethereum/go-ethereum/rpc.(*handler).startCallProc.func1\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:348\ninvalid nonce; got 0, expected 1: invalid sequence: invalid sequence'}

Check failure on line 114 in integration_tests/test_mempool.py

View workflow job for this annotation

GitHub Actions / integration_tests (slow)

test_tx_replacement ValueError: {'code': -32000, 'message': '\ngithub.com/evmos/ethermint/app/ante.CheckAndSetEthSenderNonce\n\tgithub.com/evmos/ethermint/app/ante/eth.go:298\ngithub.com/evmos/ethermint/app/ante.NewAnteHandler.newEthAnteHandler.func2\n\tgithub.com/evmos/ethermint/app/ante/handler_options.go:148\ngithub.com/evmos/ethermint/app/ante.NewAnteHandler.func1\n\tgithub.com/evmos/ethermint/app/ante/ante.go:93\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTxWithMultiStore\n\tgithub.com/cosmos/cosmos-sdk/baseapp/baseapp.go:929\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx\n\tgithub.com/cosmos/cosmos-sdk/baseapp/baseapp.go:842\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).CheckTx\n\tgithub.com/cosmos/cosmos-sdk/baseapp/abci.go:350\ngithub.com/cosmos/cosmos-sdk/server.cometABCIWrapper.CheckTx\n\tgithub.com/cosmos/cosmos-sdk/server/cmt_abci.go:28\ngithub.com/cometbft/cometbft/abci/client.(*localClient).CheckTxAsync\n\tgithub.com/cometbft/cometbft/abci/client/local_client.go:51\ngithub.com/cometbft/cometbft/proxy.(*appConnMempool).CheckTxAsync\n\tgithub.com/cometbft/cometbft/proxy/app_conn.go:147\ngithub.com/cometbft/cometbft/mempool.(*CListMempool).CheckTx\n\tgithub.com/cometbft/cometbft/mempool/clist_mempool.go:270\ngithub.com/cometbft/cometbft/rpc/core.(*Environment).BroadcastTxSync\n\tgithub.com/cometbft/cometbft/rpc/core/mempool.go:35\ngithub.com/cometbft/cometbft/rpc/client/local.(*Local).BroadcastTxSync\n\tgithub.com/cometbft/cometbft/rpc/client/local/local.go:98\ngithub.com/cosmos/cosmos-sdk/client.Context.BroadcastTxSync\n\tgithub.com/cosmos/cosmos-sdk/client/broadcast.go:94\ngithub.com/cosmos/cosmos-sdk/client.Context.BroadcastTx\n\tgithub.com/cosmos/cosmos-sdk/client/broadcast.go:26\ngithub.com/evmos/ethermint/rpc/backend.(*Backend).SendRawTransaction\n\tgithub.com/evmos/ethermint/rpc/backend/call_tx.go:167\ngithub.com/evmos/ethermint/rpc/namespaces/ethereum/eth.(*PublicAPI).SendRawTransaction\n\tgithub.com/evmos/ethermint/rpc/namespaces/ethereum/eth/api.go:232\nreflect.Value.call\n\treflect/value.go:596\nreflect.Value.Call\n\treflect/value.go:380\ngithub.com/ethereum/go-ethereum/rpc.(*callback).call\n\tgithub.com/ethereum/go-ethereum/rpc/service.go:205\ngithub.com/ethereum/go-ethereum/rpc.(*handler).runMethod\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:513\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleCall\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:459\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleCallMsg\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:420\ngithub.com/ethereum/go-ethereum/rpc.(*handler).handleMsg.func1\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:256\ngithub.com/ethereum/go-ethereum/rpc.(*handler).startCallProc.func1\n\tgithub.com/ethereum/go-ethereum/rpc/handler.go:348\ninvalid nonce; got 0, expected 1: invalid sequence: invalid sequence'}
receipt = w3.eth.wait_for_transaction_receipt(txhashes[1])
assert receipt.status == 1
Loading