diff --git a/app/app.go b/app/app.go index d67979f2a1..14987af30f 100644 --- a/app/app.go +++ b/app/app.go @@ -121,6 +121,8 @@ import ( ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v8/modules/core" + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" @@ -1085,8 +1087,12 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(slashingtypes.ModuleName) paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint: staticcheck paramsKeeper.Subspace(crisistypes.ModuleName) - paramsKeeper.Subspace(ibcexported.ModuleName) // TODO(dudong2): withkeytable paramsKeeper.Subspace(ibctransfertypes.ModuleName) + + keyTable := ibcclienttypes.ParamKeyTable() + keyTable.RegisterParamSet(&ibcconnectiontypes.Params{}) + paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable) + // ethermint subspaces paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable()) //nolint:staticcheck paramsKeeper.Subspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable()) diff --git a/app/upgrades.go b/app/upgrades.go index 95f6ddec2c..520c738824 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -40,7 +40,7 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" - clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" + ibcclientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper" "github.com/cosmos/ibc-go/v8/modules/core/exported" ibctmmigrations "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint/migrations" evmtypes "github.com/evmos/ethermint/x/evm/types" @@ -49,7 +49,7 @@ import ( func (app *EthermintApp) RegisterUpgradeHandlers( cdc codec.BinaryCodec, - clientKeeper clientkeeper.Keeper, + ibcClientKeeper ibcclientkeeper.Keeper, consensusParamsKeeper consensusparamskeeper.Keeper, paramsKeeper paramskeeper.Keeper, ) { @@ -100,20 +100,15 @@ func (app *EthermintApp) RegisterUpgradeHandlers( // ibc v7 // OPTIONAL: prune expired tendermint consensus states to save storage space - if _, err := ibctmmigrations.PruneExpiredConsensusStates(sdkCtx, cdc, clientKeeper); err != nil { - return fromVM, err - } - - legacyBaseAppSubspace := paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) - if err := baseapp.MigrateParams(sdkCtx, legacyBaseAppSubspace, &consensusParamsKeeper.ParamsStore); err != nil { + if _, err := ibctmmigrations.PruneExpiredConsensusStates(sdkCtx, cdc, ibcClientKeeper); err != nil { return fromVM, err } // ibc v7.1 // explicitly update the IBC 02-client params, adding the localhost client type - params := clientKeeper.GetParams(sdkCtx) + params := ibcClientKeeper.GetParams(sdkCtx) params.AllowedClients = append(params.AllowedClients, exported.Localhost) - clientKeeper.SetParams(sdkCtx, params) + ibcClientKeeper.SetParams(sdkCtx, params) // cosmos-sdk v047 // Migrate Tendermint consensus parameters from x/params module to a dedicated x/consensus module. diff --git a/tests/integration_tests/configs/cosmovisor.jsonnet b/tests/integration_tests/configs/cosmovisor.jsonnet index dc3cb1a4a2..6d72849146 100644 --- a/tests/integration_tests/configs/cosmovisor.jsonnet +++ b/tests/integration_tests/configs/cosmovisor.jsonnet @@ -6,6 +6,12 @@ config { 'minimum-gas-prices': '100000000000aphoton', }, genesis+: { + consensus_params+: { + block+: { + bax_bytes: '1048576', + max_gas: '81500000', + }, + }, app_state+: { feemarket+: { params+: { diff --git a/tests/integration_tests/test_upgrade.py b/tests/integration_tests/test_upgrade.py index a2118efb97..14075fe1d0 100644 --- a/tests/integration_tests/test_upgrade.py +++ b/tests/integration_tests/test_upgrade.py @@ -2,6 +2,7 @@ import json import re import subprocess +import time from pathlib import Path import pytest @@ -17,7 +18,8 @@ parse_events, send_transaction, wait_for_block, - wait_for_block_time, + wait_for_new_blocks_legacy, + wait_for_block_time_legacy, wait_for_port, ) @@ -53,9 +55,9 @@ def post_init(path, base_port, config): i = m.group(1) ini[section].update( { - "command": f"cosmovisor start --home %(here)s/node{i}", + "command": f"cosmovisor run start --home %(here)s/node{i}", "environment": ( - f"DAEMON_NAME=ethermintd,DAEMON_HOME=%(here)s/node{i}" + f"DAEMON_NAME=ethermintd,DAEMON_HOME=%(here)s/node{i},DAEMON_RESTART_AFTER_UPGRADE=false" ), } ) @@ -119,7 +121,10 @@ def test_cosmovisor_upgrade(custom_ethermint: Ethermint): assert rsp["code"] == 0, rsp["raw_log"] # get proposal_id - ev = parse_events(rsp["logs"])["submit_proposal"] + wait_for_new_blocks_legacy(cli, 1, sleep=0.1) + logs = cli.query_tx("hash", rsp["txhash"])["logs"] + + ev = parse_events(logs)["submit_proposal"] proposal_id = ev["proposal_id"] rsp = cli.gov_vote("validator", proposal_id, "yes") @@ -128,7 +133,7 @@ def test_cosmovisor_upgrade(custom_ethermint: Ethermint): # assert rsp["code"] == 0, rsp["raw_log"] proposal = cli.query_proposal(proposal_id) - wait_for_block_time(cli, isoparse(proposal["voting_end_time"])) + wait_for_block_time_legacy(cli, isoparse(proposal["voting_end_time"])) proposal = cli.query_proposal(proposal_id) assert proposal["status"] == "PROPOSAL_STATUS_PASSED", proposal @@ -137,46 +142,80 @@ def test_cosmovisor_upgrade(custom_ethermint: Ethermint): Path(custom_ethermint.chain_binary).parent.parent.parent / f"{plan_name}/bin/ethermintd" ) - cli = custom_ethermint.cosmos_cli() - - # block should pass the target height - wait_for_block(cli, target_height + 1, timeout=480) - wait_for_port(ports.rpc_port(custom_ethermint.base_port(0))) - # test migrate keystore - cli.migrate_keystore() - - # check basic tx works after upgrade - wait_for_port(ports.evmrpc_port(custom_ethermint.base_port(0))) + # wait until cosmovosor finished + proc = [] + for i in range(2): + while True: + try: + c = custom_ethermint.cosmos_cli(i) + c.status() + except: + break + finally: + time.sleep(5) + + # start ethermint + for i in range(2): + with (custom_ethermint.base_dir / f"node{i}.log").open("a") as logfile: + p = subprocess.Popen( + [ + custom_ethermint.chain_binary, + "start", + "--home", + custom_ethermint.base_dir / f"node{i}", + ], + stdout=logfile, + stderr=subprocess.STDOUT, + ) + proc.append(p) + cli = custom_ethermint.cosmos_cli() - receipt = send_transaction( - w3, - { - "to": ADDRS["community"], - "value": 1000, - "maxFeePerGas": 1000000000000, - "maxPriorityFeePerGas": 10000, - }, - ) - assert receipt.status == 1 + try: + # block should pass the target height + wait_for_block(cli, target_height + 1, timeout=20) + wait_for_port(ports.rpc_port(custom_ethermint.base_port(0))) + + # test migrate keystore + cli.migrate_keystore() + + # check basic tx works after upgrade + wait_for_port(ports.evmrpc_port(custom_ethermint.base_port(0))) + + receipt = send_transaction( + w3, + { + "to": ADDRS["community"], + "value": 1000, + "maxFeePerGas": 1000000000000, + "maxPriorityFeePerGas": 10000, + }, + ) + assert receipt.status == 1 - # check json-rpc query on older blocks works - assert old_balance == w3.eth.get_balance( - ADDRS["validator"], block_identifier=old_height - ) - assert old_base_fee == w3.eth.get_block(old_height).baseFeePerGas - - # check eth_call on older blocks works - assert old_erc20_balance == contract.caller( - block_identifier=target_height - 2 - ).balanceOf(ADDRS["validator"]) - p = json.loads( - cli.raw( - "query", - "ibc", - "client", - "params", - home=cli.data_dir, + # check json-rpc query on older blocks works + assert old_balance == w3.eth.get_balance( + ADDRS["validator"], block_identifier=old_height ) - ) - assert p == {"allowed_clients": ["06-solomachine", "07-tendermint", "09-localhost"]} + assert old_base_fee == w3.eth.get_block(old_height).baseFeePerGas + + # check eth_call on older blocks works + assert old_erc20_balance == contract.caller( + block_identifier=target_height - 2 + ).balanceOf(ADDRS["validator"]) + p = json.loads( + cli.raw( + "query", + "ibc", + "client", + "params", + home=cli.data_dir, + node=cli.node_rpc, + output="json", + ) + ) + assert p == {"allowed_clients": ["06-solomachine", "07-tendermint", "09-localhost"]} + finally: + for p in proc: + p.terminate() + p.wait() \ No newline at end of file diff --git a/tests/integration_tests/utils.py b/tests/integration_tests/utils.py index cec66a7f00..1c0ae46f15 100644 --- a/tests/integration_tests/utils.py +++ b/tests/integration_tests/utils.py @@ -83,6 +83,14 @@ def wait_for_new_blocks(cli, n, sleep=0.5): return cur_height +def wait_for_new_blocks_legacy(cli, n, sleep=0.5): + cur_height = begin_height = int((cli.status())["SyncInfo"]["latest_block_height"]) + while cur_height - begin_height < n: + time.sleep(sleep) + cur_height = int((cli.status())["SyncInfo"]["latest_block_height"]) + return cur_height + + def wait_for_block(cli, height, timeout=240): for _ in range(timeout * 2): try: @@ -124,6 +132,16 @@ def wait_for_block_time(cli, t): time.sleep(0.5) +def wait_for_block_time_legacy(cli, t): + print("wait for block time", t) + while True: + now = isoparse((cli.status())["SyncInfo"]["latest_block_time"]) + print("block time now: ", now) + if now >= t: + break + time.sleep(0.5) + + def deploy_contract(w3, jsonfile, args=(), key=KEYS["validator"]): """ deploy contract and return the deployed contract instance