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: feeibc, evm, feemarket and gravity gensis migrate is broken #1125

Merged
merged 8 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -34,6 +34,7 @@
- [#1088](https://github.com/crypto-org-chain/cronos/pull/1088) memiavl fix empty value in write-ahead-log replaying.
- [#1102](https://github.com/crypto-org-chain/cronos/pull/1102) avoid duplicate cache events emitted from ibc and gravity hook.
- [#1123](https://github.com/crypto-org-chain/cronos/pull/1123) Fix memiavl snapshot switching
- [#1125](https://github.com/crypto-org-chain/cronos/pull/1125) Fix gensis migrate for feeibc, evm, feemarket and gravity.
mmsqe marked this conversation as resolved.
Show resolved Hide resolved

### Features

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-rc.0
github.com/armon/go-metrics v0.4.1
github.com/cosmos/cosmos-sdk v0.46.14
github.com/cosmos/cosmos-sdk v0.46.15-0.20230807104542-537257060180
github.com/cosmos/gogoproto v1.4.8
github.com/cosmos/ibc-go/v6 v6.2.0
github.com/crypto-org-chain/cronos/store v0.0.2
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,10 @@ github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk=
github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis=
github.com/cosmos/cosmos-proto v1.0.0-beta.1 h1:iDL5qh++NoXxG8hSy93FdYJut4XfgbShIocllGaXx/0=
github.com/cosmos/cosmos-proto v1.0.0-beta.1/go.mod h1:8k2GNZghi5sDRFw/scPL8gMSowT1vDA+5ouxL8GjaUE=
github.com/cosmos/cosmos-sdk v0.46.14 h1:xlrUaMZT6QACdtWputs+ZxbAMWGYktWK+zlc8J4tKoE=
github.com/cosmos/cosmos-sdk v0.46.14/go.mod h1:9MRixWsgoJ2UmVsCRRePtENFPP3cM+gTC5azEpxgllo=
github.com/cosmos/cosmos-sdk v0.46.15-0.20230807090309-16d52690792e h1:vxDKg/iXN/qJHt/iqdCzGdTOU7lhn+1LEdloLSrZKFo=
github.com/cosmos/cosmos-sdk v0.46.15-0.20230807090309-16d52690792e/go.mod h1:9MRixWsgoJ2UmVsCRRePtENFPP3cM+gTC5azEpxgllo=
github.com/cosmos/cosmos-sdk v0.46.15-0.20230807104542-537257060180 h1:JgSAZEKce5UOGOykTVEcgJcUAL5kvpV0+RMfDnOna78=
github.com/cosmos/cosmos-sdk v0.46.15-0.20230807104542-537257060180/go.mod h1:9MRixWsgoJ2UmVsCRRePtENFPP3cM+gTC5azEpxgllo=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ schema = 3
version = "v1.0.0-beta.1"
hash = "sha256-oATkuj+fM5eBn+ywO+w/tL0AFSIEkx0J3Yz+VhVe0QA="
[mod."github.com/cosmos/cosmos-sdk"]
version = "v0.46.14"
hash = "sha256-+NuFpghAkWRgitbS9ufKuobxKnjLIfTjrkTB1KMDrRw="
version = "v0.46.15-0.20230807104542-537257060180"
hash = "sha256-CKO0tUaz+ewDovdRuWvI40xYil7jAnsS823O4nZn6rA="
[mod."github.com/cosmos/go-bip39"]
version = "v1.0.0"
hash = "sha256-Qm2aC2vaS8tjtMUbHmlBSagOSqbduEEDwc51qvQaBmA="
Expand Down
18 changes: 16 additions & 2 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,22 @@ def init(cls, moniker, data_dir, node_rpc, cmd, chain_id):
)
return cls(data_dir, node_rpc, cmd)

def validate_genesis(self):
return self.raw("validate-genesis", home=self.data_dir)
def migrate_sdk_genesis(self, version, path):
return json.loads(self.raw("migrate", version, path))

def migrate_cronos_genesis(self, version, path):
return json.loads(
self.raw(
"tx",
"cronos",
"migrate",
version,
path,
)
)

def validate_genesis(self, path):
return self.raw("validate-genesis", path)

def add_genesis_account(self, addr, coins, **kwargs):
return self.raw(
Expand Down
28 changes: 27 additions & 1 deletion integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,24 @@ def custom_cronos(tmp_path_factory):
)


def test_cosmovisor_upgrade(custom_cronos: Cronos):
def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory):
"""
- propose an upgrade and pass it
- wait for it to happen
- it should work transparently
"""
cli = custom_cronos.cosmos_cli()
# export genesis from cronos v0.8.x
custom_cronos.supervisorctl("stop", "all")
migrate = tmp_path_factory.mktemp("migrate")
file_path0 = Path(migrate / "v0.8.json")
with open(file_path0, "w") as fp:
json.dump(json.loads(cli.export()), fp)
fp.flush()

custom_cronos.supervisorctl("start", "cronos_777-1-node0", "cronos_777-1-node1")
wait_for_port(ports.evmrpc_port(custom_cronos.base_port(0)))

height = cli.block_height()
target_height = height + 15
print("upgrade height", target_height)
Expand Down Expand Up @@ -178,3 +189,18 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos):
"observe_ethereum_height_period": "50",
}
}

# migrate to sdk v0.46
custom_cronos.supervisorctl("stop", "all")
sdk_version = "v0.46"
file_path1 = Path(migrate / f"{sdk_version}.json")
with open(file_path1, "w") as fp:
json.dump(cli.migrate_sdk_genesis(sdk_version, str(file_path0)), fp)
fp.flush()
# migrate to cronos v1.0.x
cronos_version = "v1.0"
file_path2 = Path(migrate / f"{cronos_version}.json")
with open(file_path2, "w") as fp:
json.dump(cli.migrate_cronos_genesis(cronos_version, str(file_path1)), fp)
fp.flush()
print(cli.validate_genesis(str(file_path2)))
2 changes: 1 addition & 1 deletion memiavl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ require (
github.com/zbiljic/go-filelock v0.0.0-20170914061330-1dbf7103ab7d
golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0
golang.org/x/sync v0.1.0
golang.org/x/sys v0.7.0
)

require (
Expand Down Expand Up @@ -69,6 +68,7 @@ require (
go.etcd.io/bbolt v1.3.6 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/grpc v1.54.0 // indirect
Expand Down
93 changes: 92 additions & 1 deletion x/cronos/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
Expand All @@ -19,8 +20,13 @@
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"

genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
ibcfeetypes "github.com/cosmos/ibc-go/v6/modules/apps/29-fee/types"
"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
gravitytypes "github.com/peggyjv/gravity-bridge/module/v2/x/gravity/types"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"
Expand All @@ -44,6 +50,7 @@
cmd.AddCommand(CmdTurnBridge())
cmd.AddCommand(CmdUpdatePermissions())
cmd.AddCommand(EventQueryTxFor())
cmd.AddCommand(MigrateGenesisCmd())

return cmd
}
Expand Down Expand Up @@ -370,3 +377,87 @@

return cmd
}

type ExportEvmGenesisState struct {
evmtypes.GenesisState
Params ExportEvmParams `json:"params"`
}

type ExportEvmParams struct {
evmtypes.Params
ExtraEIPs []string `json:"extra_eips"`
}

type ExportFeemarketGenesisState struct {
feemarkettypes.GenesisState
Params ExportFeemarketParams `json:"params"`
BlockGas uint64 `json:"block_gas,string"`
}

type ExportFeemarketParams struct {
feemarkettypes.Params
EnableHeight int64 `json:"enable_height,string"`
}

func Migrate(appState genutiltypes.AppMap, clientCtx client.Context) genutiltypes.AppMap {
// Add feeibc with default genesis.
if appState[ibcfeetypes.ModuleName] == nil {
appState[ibcfeetypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(ibcfeetypes.DefaultGenesisState())
}

Check warning on line 406 in x/cronos/client/cli/tx.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/client/cli/tx.go#L402-L406

Added lines #L402 - L406 were not covered by tests
// Add gravity with default genesis.
if appState[gravitytypes.ModuleName] == nil {
appState[gravitytypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(gravitytypes.DefaultGenesisState())
}
var evmState ExportEvmGenesisState
err := json.Unmarshal(appState[evmtypes.ModuleName], &evmState)
if err != nil {
panic(err)

Check warning on line 414 in x/cronos/client/cli/tx.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/client/cli/tx.go#L408-L414

Added lines #L408 - L414 were not covered by tests
}
data, err := json.Marshal(evmState)
if err != nil {
panic(err)

Check warning on line 418 in x/cronos/client/cli/tx.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/client/cli/tx.go#L416-L418

Added lines #L416 - L418 were not covered by tests
}
appState[evmtypes.ModuleName] = data

var feemarketState ExportFeemarketGenesisState
err = json.Unmarshal(appState[feemarkettypes.ModuleName], &feemarketState)
if err != nil {
panic(err)

Check warning on line 425 in x/cronos/client/cli/tx.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/client/cli/tx.go#L420-L425

Added lines #L420 - L425 were not covered by tests
}
feemarketState.GenesisState.BlockGas = feemarketState.BlockGas
data, err = json.Marshal(feemarketState)
if err != nil {
panic(err)

Check warning on line 430 in x/cronos/client/cli/tx.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/client/cli/tx.go#L427-L430

Added lines #L427 - L430 were not covered by tests
}
appState[feemarkettypes.ModuleName] = data
return appState

Check warning on line 433 in x/cronos/client/cli/tx.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/client/cli/tx.go#L432-L433

Added lines #L432 - L433 were not covered by tests
}

const flagGenesisTime = "genesis-time"

// migrationMap is a map of SDK versions to their respective genesis migration functions.
var migrationMap = genutiltypes.MigrationMap{
"v1.0": Migrate,
}

// MigrateGenesisCmd returns a command to execute genesis state migration.
func MigrateGenesisCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "migrate [target-version] [genesis-file]",
Short: "Migrate genesis to a specified target version",
Long: fmt.Sprintf(`Migrate the source genesis into the target version and print to STDOUT.

Example:
$ %s migrate v1.0 /path/to/genesis.json --chain-id=cronos_777-1 --genesis-time=2019-04-22T17:00:00Z
`, version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return genutilcli.MigrateHandler(cmd, args, migrationMap)
},

Check warning on line 456 in x/cronos/client/cli/tx.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/client/cli/tx.go#L455-L456

Added lines #L455 - L456 were not covered by tests
}

cmd.Flags().String(flagGenesisTime, "", "override genesis_time with this flag")
cmd.Flags().String(flags.FlagChainID, "", "override chain_id with this flag")

return cmd
}
Loading