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: init/validate-genesis cmd include gravity module by default #639

Merged
merged 4 commits into from
Aug 17, 2022
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 @@ -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
Expand Down
67 changes: 40 additions & 27 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
JayT106 marked this conversation as resolved.
Show resolved Hide resolved

// module account permissions
maccPerms = map[string][]string{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion app/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down
52 changes: 49 additions & 3 deletions cmd/cronosd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}),
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion integration_tests/configs/disable_auto_deployment.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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'+: {
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/configs/genesis_token_mapping.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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'+: {
Expand Down
16 changes: 8 additions & 8 deletions integration_tests/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion scripts/cronos-experimental-devnet.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 2 additions & 1 deletion scripts/devnet.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
dotenv: .env
cronos_777-1:
cmd: ./build/cronosd
start-flags: "--trace --unsafe-experimental"
cmd-flags: "--unsafe-experimental"
start-flags: "--trace"
config:
tx_index:
indexer: "null"
Expand Down