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 and feemarket gensis migrate is broken #1124

Merged
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 @@ -20,6 +20,7 @@
- [#1058](https://github.com/crypto-org-chain/cronos/pull/1058) Fix decode log for multi topics in websocket subscribe ([ethermint commit](https://github.com/crypto-org-chain/ethermint/commit/2136ad029860c819942ad1836dd3f42585002233)).
- [#1062](https://github.com/crypto-org-chain/cronos/pull/1062) Update cometbft `v0.34.29` with several minor bug fixes and low-severity security-fixes.
- [#1102](https://github.com/crypto-org-chain/cronos/pull/1102) avoid duplicate cache events emitted from ibc and gravity hook.
- [#1125](https://github.com/crypto-org-chain/cronos/pull/1125) Fix genesis migrate for feeibc, evm, feemarket and gravity.

*Jun 9, 2023*

Expand Down
4 changes: 2 additions & 2 deletions 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/ibc-go/v5 v5.2.1
github.com/crypto-org-chain/cronos/store v0.0.4-0.20230809065519-af389f66015a
github.com/crypto-org-chain/cronos/versiondb v0.0.0-20230809065519-af389f66015a
Expand All @@ -26,7 +26,6 @@ require (
github.com/tendermint/tendermint v0.34.29
github.com/tendermint/tm-db v0.6.7
golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0
golang.org/x/sys v0.8.0
google.golang.org/genproto v0.0.0-20230323212658-478b75c54725
google.golang.org/grpc v1.54.0
google.golang.org/protobuf v1.30.0
Expand Down Expand Up @@ -199,6 +198,7 @@ require (
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,8 @@ github.com/cosmos/cosmos-proto v1.0.0-alpha7/go.mod h1:dosO4pSAbJF8zWCzCoTWP7nNs
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.0/go.mod h1:u6Ci6+V+srijJhzctEEPYBygUz3O2YXP5ZijPnV6mt0=
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.20230807104542-537257060180 h1:JgSAZEKce5UOGOykTVEcgJcUAL5kvpV0+RMfDnOna78=
github.com/cosmos/cosmos-sdk v0.46.15-0.20230807104542-537257060180/go.mod h1:9MRixWsgoJ2UmVsCRRePtENFPP3cM+gTC5azEpxgllo=
github.com/cosmos/cosmos-sdk/db v1.0.0-beta.1/go.mod h1:JUMM2MxF9wuwzRWZJjb8BjXsn1BmPmdBd3a75pIct4I=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
Expand Down
5 changes: 2 additions & 3 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 All @@ -142,7 +142,6 @@ schema = 3
[mod."github.com/cosmos/iavl"]
version = "v0.19.6"
hash = "sha256-0Om7nXftrgVkCpRTGNTGnc2lUJsFQ9aihwgtkUkwleg="
replaced = "github.com/cosmos/iavl"
[mod."github.com/cosmos/ibc-go/v5"]
version = "v5.2.1"
hash = "sha256-zBw4oJQxhdviybdaL9n8PTFRTUpIIUbCGitVj6FD1/k="
Expand Down
18 changes: 16 additions & 2 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,22 @@ def init(self, moniker):
home=self.data_dir,
)

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 @@ -82,13 +82,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 @@ -184,3 +195,18 @@ def test_cosmovisor_upgrade(custom_cronos: Cronos):
{"from": ADDRS["validator"]}
)["gas"]
)

# 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)))
88 changes: 87 additions & 1 deletion x/cronos/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"encoding/json"
"fmt"
"strings"

Expand All @@ -15,8 +16,12 @@ import (
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
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/v5/modules/apps/29-fee/types"
"github.com/crypto-org-chain/cronos/x/cronos/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
)

// GetTxCmd returns the transaction commands for this module
Expand All @@ -34,6 +39,7 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdConvertTokens())
cmd.AddCommand(CmdSendToCryptoOrg())
cmd.AddCommand(CmdUpdateTokenMapping())
cmd.AddCommand(MigrateGenesisCmd())

return cmd
}
Expand Down Expand Up @@ -248,3 +254,83 @@ func CmdUpdateTokenMapping() *cobra.Command {

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())
}
var evmState ExportEvmGenesisState
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
err := json.Unmarshal(appState[evmtypes.ModuleName], &evmState)
if err != nil {
panic(err)
}
data, err := json.Marshal(evmState)
if err != nil {
panic(err)
}
appState[evmtypes.ModuleName] = data

var feemarketState ExportFeemarketGenesisState
err = json.Unmarshal(appState[feemarkettypes.ModuleName], &feemarketState)
if err != nil {
panic(err)
}
feemarketState.GenesisState.BlockGas = feemarketState.BlockGas
data, err = json.Marshal(feemarketState)
if err != nil {
panic(err)
}
appState[feemarkettypes.ModuleName] = data
return appState
}

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)
},
}

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

return cmd
}