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: pending tx comes after get mined #1450

Merged
merged 1 commit into from
Jun 7, 2024
Merged
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 @@ -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*

Expand Down
18 changes: 18 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 34 additions & 1 deletion integration_tests/test_e2ee.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -93,15 +96,45 @@ 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, {})

# 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):
Expand Down
9 changes: 3 additions & 6 deletions integration_tests/test_mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,18 @@ 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}")

# 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):
Expand Down
Loading