Skip to content

Commit

Permalink
Merge branch 'main' into branch-store
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe authored Aug 8, 2023
2 parents fc76659 + 082feca commit cdc8f69
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 10 deletions.
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 genesis migrate for feeibc, evm, feemarket and gravity.

### 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 @@ package cli

import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
Expand All @@ -19,8 +20,13 @@ import (
"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 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdTurnBridge())
cmd.AddCommand(CmdUpdatePermissions())
cmd.AddCommand(EventQueryTxFor())
cmd.AddCommand(MigrateGenesisCmd())

return cmd
}
Expand Down Expand Up @@ -370,3 +377,87 @@ func EventQueryTxFor() *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())
}
// 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)
}
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
}

0 comments on commit cdc8f69

Please sign in to comment.