Skip to content

Commit fb80ae1

Browse files
author
yihuang
authored
Problem: init/validate-genesis cmd include gravity module by default (#639)
* 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 * fix devnet configs
1 parent 4be9702 commit fb80ae1

File tree

11 files changed

+111
-46
lines changed

11 files changed

+111
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
- [cronos#502](https://github.com/crypto-org-chain/cronos/pull/502) Fix failed tx are ignored in json-rpc apis.
1515
- [cronos#556](https://github.com/crypto-org-chain/cronos/pull/556) Bump gravity bridge module version to include bugfixes (including grpc endpoint)
16+
- [cronos#639](https://github.com/crypto-org-chain/cronos/pull/639) init and validate-genesis commands don't include experimental modules by default.
1617

1718
### Improvements
1819
- [cronos#418](https://github.com/crypto-org-chain/cronos/pull/418) Support logs in evm-hooks and return id for SendToEthereum events

app/app.go

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -174,33 +174,8 @@ var (
174174
// ModuleBasics defines the module BasicManager is in charge of setting up basic,
175175
// non-dependant module elements, such as codec registration
176176
// and genesis verification.
177-
ModuleBasics = module.NewBasicManager(
178-
auth.AppModuleBasic{},
179-
genutil.AppModuleBasic{},
180-
bank.AppModuleBasic{},
181-
capability.AppModuleBasic{},
182-
staking.AppModuleBasic{},
183-
mint.AppModuleBasic{},
184-
distr.AppModuleBasic{},
185-
gov.NewAppModuleBasic(getGovProposalHandlers()),
186-
params.AppModuleBasic{},
187-
crisis.AppModuleBasic{},
188-
slashing.AppModuleBasic{},
189-
feegrantmodule.AppModuleBasic{},
190-
upgrade.AppModuleBasic{},
191-
evidence.AppModuleBasic{},
192-
authzmodule.AppModuleBasic{},
193-
ibc.AppModuleBasic{},
194-
transfer.AppModuleBasic{},
195-
vesting.AppModuleBasic{},
196-
ica.AppModuleBasic{},
197-
icactlmodule.AppModuleBasic{},
198-
evm.AppModuleBasic{},
199-
feemarket.AppModuleBasic{},
200-
gravity.AppModuleBasic{},
201-
// this line is used by starport scaffolding # stargate/app/moduleBasic
202-
cronos.AppModuleBasic{},
203-
)
177+
// Contains experimental modules by default.
178+
ModuleBasics = GenModuleBasics(true)
204179

205180
// module account permissions
206181
maccPerms = map[string][]string{
@@ -231,6 +206,40 @@ func init() {
231206
DefaultNodeHome = filepath.Join(userHomeDir, "."+Name)
232207
}
233208

209+
// GenModuleBasics generate basic module manager according to experimental flag
210+
func GenModuleBasics(experimental bool) module.BasicManager {
211+
basicModules := []module.AppModuleBasic{
212+
auth.AppModuleBasic{},
213+
genutil.AppModuleBasic{},
214+
bank.AppModuleBasic{},
215+
capability.AppModuleBasic{},
216+
staking.AppModuleBasic{},
217+
mint.AppModuleBasic{},
218+
distr.AppModuleBasic{},
219+
gov.NewAppModuleBasic(getGovProposalHandlers()),
220+
params.AppModuleBasic{},
221+
crisis.AppModuleBasic{},
222+
slashing.AppModuleBasic{},
223+
feegrantmodule.AppModuleBasic{},
224+
upgrade.AppModuleBasic{},
225+
evidence.AppModuleBasic{},
226+
authzmodule.AppModuleBasic{},
227+
ibc.AppModuleBasic{},
228+
transfer.AppModuleBasic{},
229+
vesting.AppModuleBasic{},
230+
ica.AppModuleBasic{},
231+
icactlmodule.AppModuleBasic{},
232+
evm.AppModuleBasic{},
233+
feemarket.AppModuleBasic{},
234+
// this line is used by starport scaffolding # stargate/app/moduleBasic
235+
cronos.AppModuleBasic{},
236+
}
237+
if experimental {
238+
basicModules = append(basicModules, gravity.AppModuleBasic{})
239+
}
240+
return module.NewBasicManager(basicModules...)
241+
}
242+
234243
// App extends an ABCI application, but with most of its parameters exported.
235244
// They are exported for convenience in creating helper functions, as object
236245
// capabilities aren't needed for testing.
@@ -293,6 +302,9 @@ type App struct {
293302

294303
// module configurator
295304
configurator module.Configurator
305+
306+
// if enable experimental gravity-bridge feature module
307+
experimental bool
296308
}
297309

298310
// New returns a reference to an initialized chain.
@@ -346,6 +358,7 @@ func New(
346358
keys: keys,
347359
tkeys: tkeys,
348360
memKeys: memKeys,
361+
experimental: experimental,
349362
}
350363

351364
app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey], experimental)

app/genesis.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ import (
1616
type GenesisState map[string]json.RawMessage
1717

1818
// NewDefaultGenesisState generates the default state for the application.
19-
func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState {
20-
return ModuleBasics.DefaultGenesis(cdc)
19+
func NewDefaultGenesisState(cdc codec.JSONCodec, experimental bool) GenesisState {
20+
return GenModuleBasics(experimental).DefaultGenesis(cdc)
2121
}

app/state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ func StateRandomizedFn(
162162
accs []simtypes.Account, genesisTimestamp time.Time, appParams simtypes.AppParams,
163163
) (json.RawMessage, []simtypes.Account) {
164164
numAccs := int64(len(accs))
165-
genesisState := NewDefaultGenesisState(cdc)
165+
// test with experimental modules by default
166+
genesisState := NewDefaultGenesisState(cdc, true)
166167

167168
// generate a random amount of initial stake coins and a random initial
168169
// number of bonded accounts

app/test_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func setup(withGenesis bool, invCheckPeriod uint, experimental bool) (*App, Gene
8686
}
8787
app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, appOption)
8888
if withGenesis {
89-
return app, NewDefaultGenesisState(encCdc.Codec)
89+
return app, NewDefaultGenesisState(encCdc.Codec, experimental)
9090
}
9191
return app, GenesisState{}
9292
}

cmd/cronosd/cmd/root.go

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/cosmos/cosmos-sdk/simapp/params"
1313
"github.com/cosmos/cosmos-sdk/snapshots"
14+
"github.com/cosmos/cosmos-sdk/types/module"
1415

1516
"github.com/spf13/cast"
1617
"github.com/spf13/cobra"
@@ -113,12 +114,12 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
113114

114115
rootCmd.AddCommand(
115116
ethermintclient.ValidateChainID(
116-
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
117+
WrapInitCmd(app.DefaultNodeHome),
117118
),
118119
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
119120
genutilcli.MigrateGenesisCmd(),
120-
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
121-
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
121+
WrapGenTxCmd(encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
122+
WrapValidateGenesisCmd(),
122123
AddGenesisAccountCmd(app.DefaultNodeHome),
123124
tmcli.NewCompletionCmd(rootCmd, true),
124125
ethermintclient.NewTestnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),
@@ -333,3 +334,48 @@ func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) {
333334
overwriteFlagDefaults(c, defaults)
334335
}
335336
}
337+
338+
// WrapValidateGenesisCmd extends `genutilcli.ValidateGenesisCmd` to support `--unsafe-experimental` flag.
339+
func WrapValidateGenesisCmd() *cobra.Command {
340+
wrapCmd := genutilcli.ValidateGenesisCmd(module.NewBasicManager())
341+
wrapCmd.RunE = func(cmd *cobra.Command, args []string) error {
342+
experimental, err := cmd.Flags().GetBool(cronos.ExperimentalFlag)
343+
if err != nil {
344+
return err
345+
}
346+
moduleBasics := app.GenModuleBasics(experimental)
347+
return genutilcli.ValidateGenesisCmd(moduleBasics).RunE(cmd, args)
348+
}
349+
wrapCmd.Flags().Bool(cronos.ExperimentalFlag, false, "Enable experimental features")
350+
return wrapCmd
351+
}
352+
353+
// WrapInitCmd extends `genutilcli.InitCmd` to support `--unsafe-experimental` flag.
354+
func WrapInitCmd(home string) *cobra.Command {
355+
wrapCmd := genutilcli.InitCmd(module.NewBasicManager(), home)
356+
wrapCmd.RunE = func(cmd *cobra.Command, args []string) error {
357+
experimental, err := cmd.Flags().GetBool(cronos.ExperimentalFlag)
358+
if err != nil {
359+
return err
360+
}
361+
moduleBasics := app.GenModuleBasics(experimental)
362+
return genutilcli.InitCmd(moduleBasics, home).RunE(cmd, args)
363+
}
364+
wrapCmd.Flags().Bool(cronos.ExperimentalFlag, false, "Enable experimental features")
365+
return wrapCmd
366+
}
367+
368+
// WrapGenTxCmd extends `genutilcli.GenTxCmd` to support `--unsafe-experimental` flag.
369+
func WrapGenTxCmd(txEncCfg client.TxEncodingConfig, genBalIterator banktypes.GenesisBalancesIterator, defaultNodeHome string) *cobra.Command {
370+
wrapCmd := genutilcli.GenTxCmd(module.NewBasicManager(), txEncCfg, genBalIterator, defaultNodeHome)
371+
wrapCmd.RunE = func(cmd *cobra.Command, args []string) error {
372+
experimental, err := cmd.Flags().GetBool(cronos.ExperimentalFlag)
373+
if err != nil {
374+
return err
375+
}
376+
moduleBasics := app.GenModuleBasics(experimental)
377+
return genutilcli.GenTxCmd(moduleBasics, txEncCfg, genBalIterator, defaultNodeHome).RunE(cmd, args)
378+
}
379+
wrapCmd.Flags().Bool(cronos.ExperimentalFlag, false, "Enable experimental features")
380+
return wrapCmd
381+
}

integration_tests/configs/disable_auto_deployment.jsonnet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ local config = import 'default.jsonnet';
22

33
config {
44
'cronos_777-1'+: {
5-
'start-flags': '--trace --unsafe-experimental --inv-check-period 5',
5+
'cmd-flags': '--unsafe-experimental',
6+
'start-flags': '--trace --inv-check-period 5',
67
'app-config'+: {
78
'minimum-gas-prices':: super['minimum-gas-prices'],
89
'json-rpc'+: {

integration_tests/configs/genesis_token_mapping.jsonnet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ local config = import 'default.jsonnet';
22

33
config {
44
'cronos_777-1'+: {
5-
'start-flags': '--trace --unsafe-experimental --inv-check-period 5',
5+
'cmd-flags': '--unsafe-experimental',
6+
'start-flags': '--trace --inv-check-period 5',
67
'app-config'+: {
78
'minimum-gas-prices':: super['minimum-gas-prices'],
89
'json-rpc'+: {

integration_tests/poetry.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/cronos-experimental-devnet.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cronos_777-1:
22
cmd: cronosd
3-
start-flags: "--trace --unsafe-experimental"
3+
cmd-flags: "--unsafe-experimental"
4+
start-flags: "--trace"
45
app-config:
56
minimum-gas-prices: 100000000000basetcro
67
index-events:

0 commit comments

Comments
 (0)