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

patch github-ci #8

Closed
wants to merge 9 commits into from
Closed
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
10 changes: 8 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -746,7 +748,7 @@ func NewEthermintApp(

// RegisterUpgradeHandlers is used for registering any on-chain upgrades.
// Make sure it's called after `app.mm` and `app.configurator` are set.
app.RegisterUpgradeHandlers(app.appCodec, app.IBCKeeper.ClientKeeper, app.ConsensusParamsKeeper, app.ParamsKeeper)
app.RegisterUpgradeHandlers(app.appCodec, app.IBCKeeper.ClientKeeper, app.ConsensusParamsKeeper)

autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.ModuleManager.Modules))

Expand Down Expand Up @@ -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())
Expand Down
19 changes: 6 additions & 13 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
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"
Expand All @@ -49,9 +48,8 @@ import (

func (app *EthermintApp) RegisterUpgradeHandlers(
cdc codec.BinaryCodec,
clientKeeper clientkeeper.Keeper,
ibcClientKeeper ibcclientkeeper.Keeper,
consensusParamsKeeper consensusparamskeeper.Keeper,
paramsKeeper paramskeeper.Keeper,
) {
planName := "integration-test-upgrade"
// Set param key table for params module migration
Expand Down Expand Up @@ -91,7 +89,7 @@ func (app *EthermintApp) RegisterUpgradeHandlers(
baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
app.UpgradeKeeper.SetUpgradeHandler(
planName,
func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

if fromVM, err := app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM); err != nil {
Expand All @@ -100,20 +98,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.
Expand Down
2 changes: 1 addition & 1 deletion cmd/ethermintd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
initRootCmd(tempApp, encodingConfig, rootCmd, encodingConfig.TxConfig, tempApp.BasicModuleManager)

autoCliOpts := tempApp.AutoCliOpts()
initClientCtx, _ = config.ReadFromClientConfig(initClientCtx)
initClientCtx, _ = config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx)
autoCliOpts.Keyring, _ = keyring.NewAutoCLIKeyring(initClientCtx.Keyring)
autoCliOpts.ClientCtx = initClientCtx

Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ schema = 3
version = "v1.0.0"
hash = "sha256-xOeHJWUj6fTc2EUGiE4dgfY2WkvrqTg/FWewoUvQcvg="
[mod."github.com/cosmos/ibc-go/v8"]
version = "v8.0.0"
hash = "sha256-RBj66/3xB8KTD9wbryv/tpRYYdKIDCJ/4u6u6s1Eeuo="
version = "v8.2.1"
hash = "sha256-FYMkZG3dYTXkqoSSyJSSe5NDd9K+3KlMWKfQKahXz3s="
[mod."github.com/cosmos/ics23/go"]
version = "v0.10.0"
hash = "sha256-KYEv727BO/ht63JO02xiKFGFAddg41Ve9l2vSSZZBq0="
Expand Down
7 changes: 3 additions & 4 deletions rpc/websockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ func (s *websocketsServer) Start() {

go func() {
var err error
/* #nosec G114 -- http functions have no support for timeouts */
if s.certFile == "" || s.keyFile == "" {
err = http.ListenAndServe(s.wsAddr, ws)
err = http.ListenAndServe(s.wsAddr, ws) // #nosec G114
} else {
err = http.ListenAndServeTLS(s.wsAddr, s.certFile, s.keyFile, ws)
err = http.ListenAndServeTLS(s.wsAddr, s.certFile, s.keyFile, ws) // #nosec G114
}

if err != nil {
Expand All @@ -127,7 +126,7 @@ func (s *websocketsServer) Start() {

func (s *websocketsServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
upgrader := websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
CheckOrigin: func(_ *http.Request) bool {
return true
},
}
Expand Down
2 changes: 1 addition & 1 deletion server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled.
cmd.Flags().Uint32(server.FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep")

// support old flags name for backwards compatibility
cmd.Flags().SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {
cmd.Flags().SetNormalizeFunc(func(_ *pflag.FlagSet, name string) pflag.NormalizedName {
if name == "with-tendermint" {
name = srvflags.WithComet
}
Expand Down
6 changes: 6 additions & 0 deletions tests/integration_tests/configs/cosmovisor.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ config {
'minimum-gas-prices': '100000000000aphoton',
},
genesis+: {
consensus_params+: {
block+: {
bax_bytes: '1048576',
max_gas: '81500000',
},
},
app_state+: {
feemarket+: {
params+: {
Expand Down
138 changes: 94 additions & 44 deletions tests/integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import re
import subprocess
import time
from pathlib import Path

import pytest
Expand All @@ -17,7 +18,8 @@
parse_events,
send_transaction,
wait_for_block,
wait_for_block_time,
wait_for_block_time_legacy,
wait_for_new_blocks_legacy,
wait_for_port,
)

Expand Down Expand Up @@ -53,9 +55,11 @@ 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,"
f"DAEMON_HOME=%(here)s/node{i},"
"DAEMON_RESTART_AFTER_UPGRADE=false"
),
}
)
Expand Down Expand Up @@ -119,7 +123,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")
Expand All @@ -128,7 +135,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

Expand All @@ -137,46 +144,89 @@ 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 Exception:
break
finally:
time.sleep(5)

# wait graceful shutdown for ethermint node
time.sleep(60)

# 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()
18 changes: 18 additions & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Loading