diff --git a/CHANGELOG.md b/CHANGELOG.md index 485a484697..df7636ba7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * (rpc) [#1444](https://github.com/crypto-org-chain/cronos/pull/1444) Avoid nil pointer error when query blocks before feemarket module gets enabled. * [#1439](https://github.com/crypto-org-chain/cronos/pull/1439) Add back default prepare proposal logic. +* [#1466](https://github.com/crypto-org-chain/cronos/pull/1466) Fix handling of pending transactions related APIs. *May 3, 2024* diff --git a/app/app.go b/app/app.go index d8c31380f3..7447c0ba95 100644 --- a/app/app.go +++ b/app/app.go @@ -126,6 +126,7 @@ import ( icaauthtypes "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" clientflags "github.com/cosmos/cosmos-sdk/client/flags" + evmapp "github.com/evmos/ethermint/app" evmante "github.com/evmos/ethermint/app/ante" srvflags "github.com/evmos/ethermint/server/flags" ethermint "github.com/evmos/ethermint/types" @@ -330,6 +331,8 @@ type App struct { invCheckPeriod uint + pendingTxListeners []evmapp.PendingTxListener + // keys to access the substores keys map[string]*storetypes.KVStoreKey tkeys map[string]*storetypes.TransientStoreKey @@ -1212,6 +1215,21 @@ func (app *App) RegisterTendermintService(clientCtx client.Context) { ) } +// RegisterPendingTxListener is used by json-rpc server to listen to pending transactions in CheckTx. +func (app *App) RegisterPendingTxListener(listener evmapp.PendingTxListener) { + app.pendingTxListeners = append(app.pendingTxListeners, listener) +} + +func (app *App) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { + res := app.BaseApp.CheckTx(req) + if res.Code == 0 && req.Type == abci.CheckTxType_New { + for _, listener := range app.pendingTxListeners { + listener(req.Tx) + } + } + return res +} + func (app *App) RegisterNodeService(clientCtx client.Context) { node.RegisterNodeService(clientCtx, app.GRPCQueryRouter()) } diff --git a/go.mod b/go.mod index 91fc238f8d..1b32c7bbbd 100644 --- a/go.mod +++ b/go.mod @@ -250,7 +250,7 @@ replace ( // TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134 github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231207063621-43cf32d91c3e - github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20240502043119-814fcacedf60 + github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20240607015522-b82677bb231c // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0 diff --git a/go.sum b/go.sum index 970a5f0ce5..aad5950edf 100644 --- a/go.sum +++ b/go.sum @@ -491,8 +491,8 @@ github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63 h1:R1 github.com/crypto-org-chain/cometbft-db v0.0.0-20231011055109-57922ac52a63/go.mod h1:rocwIfnS+kA060x64gkSIRvWB9StSppIkJuo5MWzL24= github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20240517084251-5ba20d99ec23 h1:pmpedXv3cd18uDwv62mfevmEVa0KCMgR/hlsTRU9p8g= github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20240517084251-5ba20d99ec23/go.mod h1:vdMQLvLSGh56GqAAQP/w2R389j+g+hHOIwKcUNt9yAc= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240502043119-814fcacedf60 h1:wyqbGGnU3FzSWbu72wrg0RJ1lD25EpYBnVrYTUH9lqk= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240502043119-814fcacedf60/go.mod h1:zJYmx1D+tDggzvXmdJ0/I62TeIykdCMfJBjBxOcniAU= +github.com/crypto-org-chain/ethermint v0.6.1-0.20240607015522-b82677bb231c h1:e4xx2GLWubmY2q+rNOoWHXF+TSGswndENtPiXrO/DqM= +github.com/crypto-org-chain/ethermint v0.6.1-0.20240607015522-b82677bb231c/go.mod h1:zJYmx1D+tDggzvXmdJ0/I62TeIykdCMfJBjBxOcniAU= github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231207063621-43cf32d91c3e h1:vnyepPQ/m25+19xcTuBUdRxmltZ/EjVWNqEjhg7Ummk= github.com/crypto-org-chain/go-ethereum v1.10.20-0.20231207063621-43cf32d91c3e/go.mod h1:+a8pUj1tOyJ2RinsNQD4326YS+leSoKGiG/uVVb0x6Y= github.com/crypto-org-chain/gravity-bridge/module/v2 v2.0.1-0.20230825054824-75403cd90c6e h1:rSTc35OBjjCBx47rHPWBCIHNGPbMnEj8f7fNcK2TjVI= diff --git a/gomod2nix.toml b/gomod2nix.toml index 4efa19516f..8ad7dd0fc7 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -219,8 +219,8 @@ schema = 3 hash = "sha256-lDIqRLUrXYCb9mmFBY/+WW+ee69+IkxOgqjHVyo4ij0=" replaced = "github.com/crypto-org-chain/go-ethereum" [mod."github.com/evmos/ethermint"] - version = "v0.6.1-0.20240502043119-814fcacedf60" - hash = "sha256-dPO5F/J8XKGLUHiPTpSLBiZcYn42CNzRQ6Ntqcuc8kY=" + version = "v0.6.1-0.20240607015522-b82677bb231c" + hash = "sha256-oqCaXw7pQb8yKh2NUAKv+R+Ogc6+VLE156Jb+nQrK2g=" replaced = "github.com/crypto-org-chain/ethermint" [mod."github.com/felixge/httpsnoop"] version = "v1.0.4" diff --git a/integration_tests/test_e2ee.py b/integration_tests/test_e2ee.py index 6abc44e61e..5d1bca97fa 100644 --- a/integration_tests/test_e2ee.py +++ b/integration_tests/test_e2ee.py @@ -1,9 +1,12 @@ import json import pytest +from eth_utils import to_checksum_address +from hexbytes import HexBytes +from pystarport import ports from .network import Cronos -from .utils import wait_for_new_blocks +from .utils import ADDRS, bech32_to_eth, wait_for_new_blocks, wait_for_port def test_register(cronos: Cronos): @@ -93,8 +96,37 @@ def test_block_list(cronos): with pytest.raises(AssertionError) as exc: cli.event_query_tx_for(txhash) assert "timed out waiting" in str(exc.value) + nonce = int(cli.query_account(user)["base_account"]["sequence"]) + + # clear blocklist + encrypt_to_validators(cli, {}) + + # the blocked tx should be unblocked now + wait_for_new_blocks(cli, 1) + assert nonce + 1 == int(cli.query_account(user)["base_account"]["sequence"]) + +def test_block_list_evm(cronos): + gen_validator_identity(cronos) + cli = cronos.cosmos_cli() + user = cli.address("signer2") + # set blocklist + encrypt_to_validators(cli, {"addresses": [user]}) + tx = { + "from": to_checksum_address(bech32_to_eth(user)), + "to": ADDRS["community"], + "value": 1, + } + base_port = cronos.base_port(0) + wait_for_port(ports.evmrpc_ws_port(base_port)) + w3 = cronos.w3 + flt = w3.eth.filter("pending") + assert flt.get_new_entries() == [] + + txhash = w3.eth.send_transaction(tx).hex() nonce = int(cli.query_account(user)["base_account"]["sequence"]) + # check tx in mempool + assert HexBytes(txhash) in w3.eth.get_filter_changes(flt.filter_id) # clear blocklist encrypt_to_validators(cli, {}) @@ -102,6 +134,7 @@ def test_block_list(cronos): # the blocked tx should be unblocked now wait_for_new_blocks(cli, 1) assert nonce + 1 == int(cli.query_account(user)["base_account"]["sequence"]) + assert w3.eth.get_filter_changes(flt.filter_id) == [] def test_invalid_block_list(cronos): diff --git a/integration_tests/test_mempool.py b/integration_tests/test_mempool.py index b565edf1a0..bdd921cab1 100644 --- a/integration_tests/test_mempool.py +++ b/integration_tests/test_mempool.py @@ -61,7 +61,7 @@ def test_mempool(cronos_mempool): print(f"all send tx hash: {sended_hash_set} at {block_num_0}") all_pending = w3.eth.get_filter_changes(filter.filter_id) - assert len(all_pending) == 0 + assert len(all_pending) == 4 block_num_1 = w3.eth.get_block_number() print(f"block_num_1 {block_num_1}") @@ -69,13 +69,10 @@ def test_mempool(cronos_mempool): # check after max 10 blocks for i in range(10): all_pending = w3.eth.get_filter_changes(filter.filter_id) - print(f"all pending tx hash at block {i+block_num_1}: {all_pending}") - for h in all_pending: - sended_hash_set.discard(h) - if len(sended_hash_set) == 0: + if len(all_pending) == 0: break wait_for_new_blocks(cli, 1, sleep=0.1) - assert len(sended_hash_set) == 0 + assert len(all_pending) == 0 def test_blocked_address(cronos_mempool):