Skip to content

Commit

Permalink
Problem: no parsed log from old event
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Apr 30, 2024
1 parent 4584c0a commit 18fb1ea
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 40 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## UNRELEASED

### Bug Fixes

* (rpc) [#](https://github.com/crypto-org-chain/cronos/pull/) Fix parsed logs from old events.


*April 22, 2024*

## v1.2.1
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,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.20240419022701-412115d02b10
github.com/evmos/ethermint => github.com/mmsqe/ethermint v0.6.5-0.20240430020909-98adb7dbb454
// 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 @@ -488,8 +488,6 @@ 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.20240228013111-9bd1e035ed1d h1:ihUBUAEwQYHZEqf7lXrJithNCUJTjB8q3oSQA6Nevco=
github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20240228013111-9bd1e035ed1d/go.mod h1:cmAawe8FV/52oPKbgeHLt4UpNkrNu8R5KD+kw0kxJFc=
github.com/crypto-org-chain/ethermint v0.6.1-0.20240419022701-412115d02b10 h1:6uN0+FzbTTFbGAlqdrKjcJt/geaK6zveGtm2p33tXJg=
github.com/crypto-org-chain/ethermint v0.6.1-0.20240419022701-412115d02b10/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 Expand Up @@ -1165,6 +1163,8 @@ github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjU
github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mmsqe/ethermint v0.6.5-0.20240430020909-98adb7dbb454 h1:SECKHDau/RSJjswUZtYsdWIkRy1HkFTpqsDv9ycU4CU=
github.com/mmsqe/ethermint v0.6.5-0.20240430020909-98adb7dbb454/go.mod h1:zJYmx1D+tDggzvXmdJ0/I62TeIykdCMfJBjBxOcniAU=
github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU=
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc=
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw=
Expand Down
6 changes: 3 additions & 3 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ 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.20240419022701-412115d02b10"
hash = "sha256-wuXg0oZlIHc+x9tSmxZxGNoBa521p+o/Nk4ynJHKlRU="
replaced = "github.com/crypto-org-chain/ethermint"
version = "v0.6.5-0.20240430020909-98adb7dbb454"
hash = "sha256-/o/PSThx/29+kx5Xtpdp6MI8v/dOgrc53/RqGiCOrWc="
replaced = "github.com/mmsqe/ethermint"
[mod."github.com/felixge/httpsnoop"]
version = "v1.0.2"
hash = "sha256-hj6FZQ1fDAV+1wGIViAt8XaAkWZ1I5vJzgjIJa7XRBA="
Expand Down
17 changes: 17 additions & 0 deletions integration_tests/configs/cosmovisor.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ config {
'app-config'+: {
'app-db-backend': 'rocksdb',
'minimum-gas-prices': '100000000000basetcro',
store:: super.store,
streamers:: super.streamers,
'iavl-lazy-loading':: super['iavl-lazy-loading'],
},
validators: [super.validators[0] {
'app-config':: super['app-config'],
}] + super.validators[1:],
genesis+: {
app_state+: {
bank+: {
Expand All @@ -23,10 +28,22 @@ config {
],
},
},
evm+: {
params+: {
// emulate the environment on production network
extra_eips: [
'2929',
'2200',
'1884',
'1344',
],
},
},
feemarket+: {
params+: {
no_base_fee: false,
base_fee:: super.base_fee,
initial_base_fee: super.base_fee,
},
},
gov: {
Expand Down
22 changes: 9 additions & 13 deletions integration_tests/configs/upgrade-test-package.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
let
pkgs = import ../../nix { };
fetchFlake0 = repo: rev: (pkgs.flake-compat {
src = {
outPath = builtins.fetchTarball "https://github.com/${repo}/archive/${rev}.tar.gz";
inherit rev;
shortRev = builtins.substring 0 7 rev;
};
}).defaultNix;
# v1.0.15
released0 = (fetchFlake0 "crypto-org-chain/cronos" "1f5e2618362303d91f621b47cbc1115cf4fa0195").default;
fetchFlake = repo: rev: (pkgs.flake-compat {
src = {
outPath = builtins.fetchTarball "https://github.com/${repo}/archive/${rev}.tar.gz";
inherit rev;
shortRev = builtins.substring 0 7 rev;
};
}).defaultNix;
# v1.1.1
released = (fetchFlake "crypto-org-chain/cronos" "10b8eeb9052e3c52aa59dec15f5d3aca781d1271").default;
# v0.8.0
releasedGenesis = (fetchFlake "crypto-org-chain/cronos" "2f2cc88b501b47149690fdef05afbbbe5bc116c9").default;
# v1.0.15 a85daedc6ffc
released1_1 = (fetchFlake "crypto-org-chain/cronos" "1f5e2618362303d91f621b47cbc1115cf4fa0195").default;
# v1.1.1 5b153a460e7a
released1_2 = (fetchFlake "crypto-org-chain/cronos" "10b8eeb9052e3c52aa59dec15f5d3aca781d1271").default;
current = pkgs.callPackage ../../. { };
in
pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis"; path = released0; }
{ name = "v1.1.0"; path = released; }
{ name = "genesis"; path = releasedGenesis; }
{ name = "v1.0.0"; path = released1_1; }
{ name = "v1.1.0"; path = released1_2; }
{ name = "v1.2"; path = current; }
]
40 changes: 25 additions & 15 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,15 @@ def edit_validator(
)
)

def gov_propose_legacy(self, proposer, kind, proposal, mode="block", **kwargs):
def gov_propose_legacy(
self,
proposer,
kind,
proposal,
mode="block",
method="submit-legacy-proposal",
**kwargs,
):
kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE)
kwargs.setdefault("gas", DEFAULT_GAS)
if mode:
Expand All @@ -680,11 +688,11 @@ def gov_propose_legacy(self, proposer, kind, proposal, mode="block", **kwargs):
self.raw(
"tx",
"gov",
"submit-legacy-proposal",
method,
kind,
proposal["name"],
"-y",
"--no-validate",
"--no-validate" if method == "submit-legacy-proposal" else None,
from_=proposer,
# content
title=proposal.get("title"),
Expand Down Expand Up @@ -746,19 +754,21 @@ def gov_propose_legacy(self, proposer, kind, proposal, mode="block", **kwargs):

def gov_vote(self, voter, proposal_id, option, event_query_tx=True, **kwargs):
kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE)
rsp = json.loads(
self.raw(
"tx",
"gov",
"vote",
proposal_id,
option,
"-y",
from_=voter,
home=self.data_dir,
**kwargs,
)
raw = self.raw(
"tx",
"gov",
"vote",
proposal_id,
option,
"-y",
from_=voter,
home=self.data_dir,
**kwargs,
)
# skip success log info that breaks json.loads
brace_index = raw.index(b"{")
json_part = raw[brace_index:]
rsp = json.loads(json_part)
if rsp["code"] == 0 and event_query_tx:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp
Expand Down
42 changes: 40 additions & 2 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
from .utils import (
ADDRS,
CONTRACTS,
KEYS,
approve_proposal,
deploy_contract,
edit_ini_sections,
get_consensus_params,
get_send_enable,
send_transaction,
sign_transaction,
wait_for_block,
wait_for_new_blocks,
wait_for_port,
Expand Down Expand Up @@ -109,13 +111,27 @@ def exec(c, tmp_path_factory):
"""
cli = c.cosmos_cli()
port = ports.api_port(c.base_port(0))
w3 = c.w3
erc20 = deploy_contract(
w3,
CONTRACTS["TestERC20A"],
key=KEYS["validator"],
)
tx = erc20.functions.transfer(ADDRS["community"], 10).build_transaction(
{"from": ADDRS["validator"]}
)
signed = sign_transaction(w3, tx, KEYS["validator"])
txhash0 = w3.eth.send_raw_transaction(signed.rawTransaction)
receipt0 = w3.eth.wait_for_transaction_receipt(txhash0)
block0 = hex(receipt0["blockNumber"])
logs0 = w3.eth.get_logs({"fromBlock": block0, "toBlock": block0})

send_enable = [
{"denom": "basetcro", "enabled": False},
{"denom": "stake", "enabled": True},
]
p = get_send_enable(port)
assert sorted(p, key=lambda x: x["denom"]) == send_enable

# export genesis from old version
c.supervisorctl("stop", "all")
migrate = tmp_path_factory.mktemp("migrate")
Expand All @@ -128,7 +144,7 @@ def exec(c, tmp_path_factory):
wait_for_port(ports.evmrpc_port(c.base_port(0)))
wait_for_new_blocks(cli, 1)

def do_upgrade(plan_name, target, mode=None):
def do_upgrade(plan_name, target, mode=None, method="submit-legacy-proposal"):
rsp = cli.gov_propose_legacy(
"community",
"software-upgrade",
Expand All @@ -140,6 +156,7 @@ def do_upgrade(plan_name, target, mode=None):
"deposit": "10000basetcro",
},
mode=mode,
method=method,
)
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(c, rsp)
Expand All @@ -152,6 +169,24 @@ def do_upgrade(plan_name, target, mode=None):
wait_for_block(c.cosmos_cli(), target + 2, timeout=480)
wait_for_port(ports.rpc_port(c.base_port(0)))

target_height00 = cli.block_height() + 15
print("upgrade v1.0 height", target_height00)
do_upgrade("v1.0.0", target_height00, "block", method="submit-proposal")
cli = c.cosmos_cli()

wait_for_port(ports.evmrpc_port(c.base_port(0)))

receipt = send_transaction(
c.w3,
{
"to": ADDRS["community"],
"value": 1000,
"maxFeePerGas": 10000000000000,
"maxPriorityFeePerGas": 10000,
},
)
assert receipt.status == 1

# test migrate keystore
cli.migrate_keystore()
height = cli.block_height()
Expand Down Expand Up @@ -264,6 +299,9 @@ def do_upgrade(plan_name, target, mode=None):
assert f0 == cli.query_params("feemarket", height=target_height0 - 1)["params"]
assert f1 == cli.query_params("feemarket", height=target_height1 - 1)["params"]

assert w3.eth.wait_for_transaction_receipt(txhash0)["logs"] == receipt0["logs"]
assert w3.eth.get_logs({"fromBlock": block0, "toBlock": block0}) == logs0


def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory):
exec(custom_cronos, tmp_path_factory)
6 changes: 3 additions & 3 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ def cb(attrs):
rsp = n.cosmos_cli(i).gov_vote("validator", proposal_id, "yes", event_query_tx)
assert rsp["code"] == 0, rsp["raw_log"]
wait_for_new_blocks(cli, 1)
assert (
int(cli.query_tally(proposal_id)["yes_count"]) == cli.staking_pool()
), "all validators should have voted yes"
res = cli.query_tally(proposal_id)
count = res.get("yes") or res.get("yes_count")
assert int(count) == cli.staking_pool(), "all validators should have voted yes"
print("wait for proposal to be activated")
proposal = cli.query_proposal(proposal_id)
wait_for_block_time(cli, isoparse(proposal["voting_end_time"]))
Expand Down
2 changes: 1 addition & 1 deletion x/cronos/rpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (api *CronosAPI) GetTransactionReceiptsByBlock(blockNrOrHash rpctypes.Block
return nil, err
}

logs, err := evmtypes.DecodeMsgLogsFromEvents(txResult.Data, parsedTx.MsgIndex, uint64(blockRes.Height))
logs, err := evmtypes.DecodeMsgLogsFromEvents(txResult.Data, txResult.Events, parsedTx.MsgIndex, uint64(blockRes.Height))

Check warning on line 183 in x/cronos/rpc/api.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/rpc/api.go#L183

Added line #L183 was not covered by tests
if err != nil {
api.logger.Debug("failed to parse logs", "block", resBlock.Block.Height, "txIndex", txIndex, "msgIndex", msgIndex, "error", err.Error())
}
Expand Down

0 comments on commit 18fb1ea

Please sign in to comment.