From 9c2afa7b04f2289f8fe4f33285a95d4e9685b6c9 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 12 Aug 2022 18:23:43 +0800 Subject: [PATCH 1/2] Problem: inconsistent logic regarding experimental modules in genesis export/validate Solution: - Use different module managers according to --unsafe-experimental flag fix experimental flag in unit tests Update CHANGELOG.md use cmd-flags to fix integration tests pystarport merged to main --- CHANGELOG.md | 1 + app/app.go | 67 +++++++++++-------- app/genesis.go | 4 +- app/state.go | 3 +- app/test_helpers.go | 2 +- cmd/cronosd/cmd/root.go | 52 +++++++++++++- .../configs/disable_auto_deployment.jsonnet | 3 +- .../configs/genesis_token_mapping.jsonnet | 3 +- integration_tests/poetry.lock | 16 ++--- 9 files changed, 107 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c1048822c..6d265f2567 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - [cronos#502](https://github.com/crypto-org-chain/cronos/pull/502) Fix failed tx are ignored in json-rpc apis. - [cronos#556](https://github.com/crypto-org-chain/cronos/pull/556) Bump gravity bridge module version to include bugfixes (including grpc endpoint) +- [cronos#639](https://github.com/crypto-org-chain/cronos/pull/639) init and validate-genesis commands don't include experimental modules by default. ### Improvements - [cronos#418](https://github.com/crypto-org-chain/cronos/pull/418) Support logs in evm-hooks and return id for SendToEthereum events diff --git a/app/app.go b/app/app.go index bc72a8e322..010abdd49c 100644 --- a/app/app.go +++ b/app/app.go @@ -174,33 +174,8 @@ var ( // ModuleBasics defines the module BasicManager is in charge of setting up basic, // non-dependant module elements, such as codec registration // and genesis verification. - ModuleBasics = module.NewBasicManager( - auth.AppModuleBasic{}, - genutil.AppModuleBasic{}, - bank.AppModuleBasic{}, - capability.AppModuleBasic{}, - staking.AppModuleBasic{}, - mint.AppModuleBasic{}, - distr.AppModuleBasic{}, - gov.NewAppModuleBasic(getGovProposalHandlers()), - params.AppModuleBasic{}, - crisis.AppModuleBasic{}, - slashing.AppModuleBasic{}, - feegrantmodule.AppModuleBasic{}, - upgrade.AppModuleBasic{}, - evidence.AppModuleBasic{}, - authzmodule.AppModuleBasic{}, - ibc.AppModuleBasic{}, - transfer.AppModuleBasic{}, - vesting.AppModuleBasic{}, - ica.AppModuleBasic{}, - icactlmodule.AppModuleBasic{}, - evm.AppModuleBasic{}, - feemarket.AppModuleBasic{}, - gravity.AppModuleBasic{}, - // this line is used by starport scaffolding # stargate/app/moduleBasic - cronos.AppModuleBasic{}, - ) + // Contains experimental modules by default. + ModuleBasics = GenModuleBasics(true) // module account permissions maccPerms = map[string][]string{ @@ -231,6 +206,40 @@ func init() { DefaultNodeHome = filepath.Join(userHomeDir, "."+Name) } +// GenModuleBasics generate basic module manager according to experimental flag +func GenModuleBasics(experimental bool) module.BasicManager { + basicModules := []module.AppModuleBasic{ + auth.AppModuleBasic{}, + genutil.AppModuleBasic{}, + bank.AppModuleBasic{}, + capability.AppModuleBasic{}, + staking.AppModuleBasic{}, + mint.AppModuleBasic{}, + distr.AppModuleBasic{}, + gov.NewAppModuleBasic(getGovProposalHandlers()), + params.AppModuleBasic{}, + crisis.AppModuleBasic{}, + slashing.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, + authzmodule.AppModuleBasic{}, + ibc.AppModuleBasic{}, + transfer.AppModuleBasic{}, + vesting.AppModuleBasic{}, + ica.AppModuleBasic{}, + icactlmodule.AppModuleBasic{}, + evm.AppModuleBasic{}, + feemarket.AppModuleBasic{}, + // this line is used by starport scaffolding # stargate/app/moduleBasic + cronos.AppModuleBasic{}, + } + if experimental { + basicModules = append(basicModules, gravity.AppModuleBasic{}) + } + return module.NewBasicManager(basicModules...) +} + // App extends an ABCI application, but with most of its parameters exported. // They are exported for convenience in creating helper functions, as object // capabilities aren't needed for testing. @@ -293,6 +302,9 @@ type App struct { // module configurator configurator module.Configurator + + // if enable experimental gravity-bridge feature module + experimental bool } // New returns a reference to an initialized chain. @@ -346,6 +358,7 @@ func New( keys: keys, tkeys: tkeys, memKeys: memKeys, + experimental: experimental, } app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey], experimental) diff --git a/app/genesis.go b/app/genesis.go index 5bf0c1da80..e262d8445e 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -16,6 +16,6 @@ import ( type GenesisState map[string]json.RawMessage // NewDefaultGenesisState generates the default state for the application. -func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { - return ModuleBasics.DefaultGenesis(cdc) +func NewDefaultGenesisState(cdc codec.JSONCodec, experimental bool) GenesisState { + return GenModuleBasics(experimental).DefaultGenesis(cdc) } diff --git a/app/state.go b/app/state.go index 2c264c53f8..43e35453e0 100644 --- a/app/state.go +++ b/app/state.go @@ -162,7 +162,8 @@ func StateRandomizedFn( accs []simtypes.Account, genesisTimestamp time.Time, appParams simtypes.AppParams, ) (json.RawMessage, []simtypes.Account) { numAccs := int64(len(accs)) - genesisState := NewDefaultGenesisState(cdc) + // test with experimental modules by default + genesisState := NewDefaultGenesisState(cdc, true) // generate a random amount of initial stake coins and a random initial // number of bonded accounts diff --git a/app/test_helpers.go b/app/test_helpers.go index 2d0c89db1a..e52956d3fc 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -86,7 +86,7 @@ func setup(withGenesis bool, invCheckPeriod uint, experimental bool) (*App, Gene } app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, appOption) if withGenesis { - return app, NewDefaultGenesisState(encCdc.Codec) + return app, NewDefaultGenesisState(encCdc.Codec, experimental) } return app, GenesisState{} } diff --git a/cmd/cronosd/cmd/root.go b/cmd/cronosd/cmd/root.go index f3b95745a6..1efc0aa18a 100644 --- a/cmd/cronosd/cmd/root.go +++ b/cmd/cronosd/cmd/root.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/snapshots" + "github.com/cosmos/cosmos-sdk/types/module" "github.com/spf13/cast" "github.com/spf13/cobra" @@ -113,12 +114,12 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { rootCmd.AddCommand( ethermintclient.ValidateChainID( - genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome), + WrapInitCmd(app.DefaultNodeHome), ), genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), genutilcli.MigrateGenesisCmd(), - genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), - genutilcli.ValidateGenesisCmd(app.ModuleBasics), + WrapGenTxCmd(encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), + WrapValidateGenesisCmd(), AddGenesisAccountCmd(app.DefaultNodeHome), tmcli.NewCompletionCmd(rootCmd, true), ethermintclient.NewTestnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}), @@ -333,3 +334,48 @@ func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) { overwriteFlagDefaults(c, defaults) } } + +// WrapValidateGenesisCmd extends `genutilcli.ValidateGenesisCmd` to support `--unsafe-experimental` flag. +func WrapValidateGenesisCmd() *cobra.Command { + wrapCmd := genutilcli.ValidateGenesisCmd(module.NewBasicManager()) + wrapCmd.RunE = func(cmd *cobra.Command, args []string) error { + experimental, err := cmd.Flags().GetBool(cronos.ExperimentalFlag) + if err != nil { + return err + } + moduleBasics := app.GenModuleBasics(experimental) + return genutilcli.ValidateGenesisCmd(moduleBasics).RunE(cmd, args) + } + wrapCmd.Flags().Bool(cronos.ExperimentalFlag, false, "Enable experimental features") + return wrapCmd +} + +// WrapInitCmd extends `genutilcli.InitCmd` to support `--unsafe-experimental` flag. +func WrapInitCmd(home string) *cobra.Command { + wrapCmd := genutilcli.InitCmd(module.NewBasicManager(), home) + wrapCmd.RunE = func(cmd *cobra.Command, args []string) error { + experimental, err := cmd.Flags().GetBool(cronos.ExperimentalFlag) + if err != nil { + return err + } + moduleBasics := app.GenModuleBasics(experimental) + return genutilcli.InitCmd(moduleBasics, home).RunE(cmd, args) + } + wrapCmd.Flags().Bool(cronos.ExperimentalFlag, false, "Enable experimental features") + return wrapCmd +} + +// WrapGenTxCmd extends `genutilcli.GenTxCmd` to support `--unsafe-experimental` flag. +func WrapGenTxCmd(txEncCfg client.TxEncodingConfig, genBalIterator banktypes.GenesisBalancesIterator, defaultNodeHome string) *cobra.Command { + wrapCmd := genutilcli.GenTxCmd(module.NewBasicManager(), txEncCfg, genBalIterator, defaultNodeHome) + wrapCmd.RunE = func(cmd *cobra.Command, args []string) error { + experimental, err := cmd.Flags().GetBool(cronos.ExperimentalFlag) + if err != nil { + return err + } + moduleBasics := app.GenModuleBasics(experimental) + return genutilcli.GenTxCmd(moduleBasics, txEncCfg, genBalIterator, defaultNodeHome).RunE(cmd, args) + } + wrapCmd.Flags().Bool(cronos.ExperimentalFlag, false, "Enable experimental features") + return wrapCmd +} diff --git a/integration_tests/configs/disable_auto_deployment.jsonnet b/integration_tests/configs/disable_auto_deployment.jsonnet index aec7f3426d..c3c47c3388 100644 --- a/integration_tests/configs/disable_auto_deployment.jsonnet +++ b/integration_tests/configs/disable_auto_deployment.jsonnet @@ -2,7 +2,8 @@ local config = import 'default.jsonnet'; config { 'cronos_777-1'+: { - 'start-flags': '--trace --unsafe-experimental --inv-check-period 5', + 'cmd-flags': '--unsafe-experimental', + 'start-flags': '--trace --inv-check-period 5', 'app-config'+: { 'minimum-gas-prices':: super['minimum-gas-prices'], 'json-rpc'+: { diff --git a/integration_tests/configs/genesis_token_mapping.jsonnet b/integration_tests/configs/genesis_token_mapping.jsonnet index 2c3b713c0a..773b1227be 100644 --- a/integration_tests/configs/genesis_token_mapping.jsonnet +++ b/integration_tests/configs/genesis_token_mapping.jsonnet @@ -2,7 +2,8 @@ local config = import 'default.jsonnet'; config { 'cronos_777-1'+: { - 'start-flags': '--trace --unsafe-experimental --inv-check-period 5', + 'cmd-flags': '--unsafe-experimental', + 'start-flags': '--trace --inv-check-period 5', 'app-config'+: { 'minimum-gas-prices':: super['minimum-gas-prices'], 'json-rpc'+: { diff --git a/integration_tests/poetry.lock b/integration_tests/poetry.lock index 3a34193528..153b78d6e6 100644 --- a/integration_tests/poetry.lock +++ b/integration_tests/poetry.lock @@ -207,15 +207,15 @@ tools = ["hypothesis (>=3.6.1,<4)"] [[package]] name = "eth-account" -version = "0.5.7" -description = "eth-account: Sign Ethereum transactions and messages with local private keys" +version = "0.5.8" +description = "" category = "main" optional = false python-versions = ">=3.6, <4" develop = false [package.dependencies] -bitarray = ">=1.2.1,<1.3.0" +bitarray = ">=1.2.1,<3" eth-abi = ">=2.0.0b7,<3" eth-keyfile = ">=0.5.0,<0.6.0" eth-keys = ">=0.3.4,<0.4.0" @@ -225,10 +225,10 @@ hexbytes = ">=0.1.0,<1" rlp = ">=1.0.0,<3" [package.extras] -dev = ["bumpversion (>=0.5.3,<1)", "pytest-watch (>=4.1.0,<5)", "wheel", "twine", "ipython", "hypothesis (>=4.18.0,<5)", "pytest (>=6.2.5,<7)", "pytest-xdist", "tox (==3.14.6)", "flake8 (==3.7.9)", "isort (>=4.2.15,<5)", "mypy (==0.770)", "pydocstyle (>=5.0.0,<6)", "Sphinx (>=1.6.5,<2)", "sphinx-rtd-theme (>=0.1.9,<1)", "towncrier (>=19.2.0,<20)"] -doc = ["Sphinx (>=1.6.5,<2)", "sphinx-rtd-theme (>=0.1.9,<1)", "towncrier (>=19.2.0,<20)"] -lint = ["flake8 (==3.7.9)", "isort (>=4.2.15,<5)", "mypy (==0.770)", "pydocstyle (>=5.0.0,<6)"] test = ["hypothesis (>=4.18.0,<5)", "pytest (>=6.2.5,<7)", "pytest-xdist", "tox (==3.14.6)"] +lint = ["flake8 (==3.7.9)", "isort (>=4.2.15,<5)", "mypy (==0.770)", "pydocstyle (>=5.0.0,<6)"] +doc = ["Sphinx (>=1.6.5,<2)", "sphinx_rtd_theme (>=0.1.9,<1)", "towncrier (>=21.9.0)"] +dev = ["bumpversion (>=0.5.3,<1)", "pytest-watch (>=4.1.0,<5)", "wheel", "twine", "ipython"] [package.source] type = "git" @@ -777,7 +777,7 @@ tomlkit = "^0.7.0" type = "git" url = "https://github.com/crypto-com/pystarport.git" reference = "main" -resolved_reference = "286a446473e1f3e1e1a5e075ba1041d3b52e5fc9" +resolved_reference = "97e403875f31dd196e4062400a03358e66a13464" [[package]] name = "pytest" @@ -1079,7 +1079,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "d50ed7097f3e4b1f7fe2da084e7d0c6a53cbfdd55b3d13e16d3c2e8915ad14a0" +content-hash = "4c42654857d14b05711431944ce50438ba9f430f8922600b9d3cfb8420fd4dc6" [metadata.files] aiohttp = [ From 8395c193240fef8db1978cefa5f880b8a967ceb5 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Wed, 17 Aug 2022 10:37:13 +0800 Subject: [PATCH 2/2] fix devnet configs --- scripts/cronos-experimental-devnet.yaml | 3 ++- scripts/devnet.yaml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/cronos-experimental-devnet.yaml b/scripts/cronos-experimental-devnet.yaml index 5898325c8c..7341b8cc5e 100644 --- a/scripts/cronos-experimental-devnet.yaml +++ b/scripts/cronos-experimental-devnet.yaml @@ -1,6 +1,7 @@ cronos_777-1: cmd: cronosd - start-flags: "--trace --unsafe-experimental" + cmd-flags: "--unsafe-experimental" + start-flags: "--trace" app-config: minimum-gas-prices: 100000000000basetcro index-events: diff --git a/scripts/devnet.yaml b/scripts/devnet.yaml index a1aee17ae8..0bd249e769 100644 --- a/scripts/devnet.yaml +++ b/scripts/devnet.yaml @@ -1,7 +1,8 @@ dotenv: .env cronos_777-1: cmd: ./build/cronosd - start-flags: "--trace --unsafe-experimental" + cmd-flags: "--unsafe-experimental" + start-flags: "--trace" app-config: json-rpc: address: "0.0.0.0:{EVMRPC_PORT}"