From 56f4ccfd2615a742b7c760d78484ddb2518ea6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Tue, 25 Aug 2020 17:55:19 +0200 Subject: [PATCH] Fix AfterImport and update black/white list variable namings (#7159) * fix sim bug and rename remaining references of black/white list * make server export command flags public * make missed flag public Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> --- server/export.go | 20 ++++++++++---------- simapp/export.go | 22 +++++++++++----------- simapp/sim_test.go | 4 ++-- simapp/simd/cmd/root.go | 4 ++-- simapp/types.go | 2 +- x/simulation/simulate.go | 4 ++-- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/server/export.go b/server/export.go index d54a859addf2..18eb00dc7380 100644 --- a/server/export.go +++ b/server/export.go @@ -18,9 +18,9 @@ import ( ) const ( - flagHeight = "height" - flagForZeroHeight = "for-zero-height" - flagJailWhitelist = "jail-whitelist" + FlagHeight = "height" + FlagForZeroHeight = "for-zero-height" + FlagJailAllowedAddrs = "jail-allowed-addrs" ) // ExportCmd dumps app state to JSON. @@ -60,11 +60,11 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return err } - height, _ := cmd.Flags().GetInt64(flagHeight) - forZeroHeight, _ := cmd.Flags().GetBool(flagForZeroHeight) - jailWhiteList, _ := cmd.Flags().GetStringSlice(flagJailWhitelist) + height, _ := cmd.Flags().GetInt64(FlagHeight) + forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight) + jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs) - appState, validators, cp, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailWhiteList) + appState, validators, cp, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs) if err != nil { return fmt.Errorf("error exporting state: %v", err) } @@ -107,9 +107,9 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com } cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") - cmd.Flags().Int64(flagHeight, -1, "Export state from a particular height (-1 means latest height)") - cmd.Flags().Bool(flagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)") - cmd.Flags().StringSlice(flagJailWhitelist, []string{}, "List of validators to not jail state export") + cmd.Flags().Int64(FlagHeight, -1, "Export state from a particular height (-1 means latest height)") + cmd.Flags().Bool(FlagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)") + cmd.Flags().StringSlice(FlagJailAllowedAddrs, []string{}, "List of validators to not jail state export") return cmd } diff --git a/simapp/export.go b/simapp/export.go index 7f4a2036cbb5..07c59c2fdcc6 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -18,14 +18,14 @@ import ( // ExportAppStateAndValidators exports the state of the application for a genesis // file. func (app *SimApp) ExportAppStateAndValidators( - forZeroHeight bool, jailWhiteList []string, + forZeroHeight bool, jailAllowedAddrs []string, ) (appState json.RawMessage, validators []tmtypes.GenesisValidator, cp *abci.ConsensusParams, err error) { // as if they could withdraw from the start of the next block ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) if forZeroHeight { - app.prepForZeroHeightGenesis(ctx, jailWhiteList) + app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) } genState := app.mm.ExportGenesis(ctx, app.appCodec) @@ -41,22 +41,22 @@ func (app *SimApp) ExportAppStateAndValidators( // prepare for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated // in favour of export at a block height -func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []string) { - applyWhiteList := false +func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { + applyAllowedAddrs := false - //Check if there is a whitelist - if len(jailWhiteList) > 0 { - applyWhiteList = true + // check if there is a allowed address list + if len(jailAllowedAddrs) > 0 { + applyAllowedAddrs = true } - whiteListMap := make(map[string]bool) + allowedAddrsMap := make(map[string]bool) - for _, addr := range jailWhiteList { + for _, addr := range jailAllowedAddrs { _, err := sdk.ValAddressFromBech32(addr) if err != nil { log.Fatal(err) } - whiteListMap[addr] = true + allowedAddrsMap[addr] = true } /* Just to be safe, assert the invariants on current state. */ @@ -141,7 +141,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str } validator.UnbondingHeight = 0 - if applyWhiteList && !whiteListMap[addr.String()] { + if applyAllowedAddrs && !allowedAddrsMap[addr.String()] { validator.Jailed = true } diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 49bdf801d554..659ce601c120 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -255,10 +255,10 @@ func TestAppSimulationAfterImport(t *testing.T) { _, _, err = simulation.SimulateFromSeed( t, os.Stdout, - app.BaseApp, + newApp.BaseApp, AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 - SimulationOperations(app, app.AppCodec(), config), + SimulationOperations(newApp, newApp.AppCodec(), config), app.ModuleAccountAddrs(), config, ) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index dab291737475..ab961123e724 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -192,7 +192,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty } func exportAppStateAndTMValidators( - logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string, + logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, ) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) { encCfg := simapp.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd. @@ -208,5 +208,5 @@ func exportAppStateAndTMValidators( simApp = simapp.NewSimApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), encCfg) } - return simApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList) + return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) } diff --git a/simapp/types.go b/simapp/types.go index 94fac5b77dba..dab807cd04d5 100644 --- a/simapp/types.go +++ b/simapp/types.go @@ -35,7 +35,7 @@ type App interface { // Exports the state of the application for a genesis file. ExportAppStateAndValidators( - forZeroHeight bool, jailWhiteList []string, + forZeroHeight bool, jailAllowedAddrs []string, ) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) // All the registered module account addreses. diff --git a/x/simulation/simulate.go b/x/simulation/simulate.go index d0ee64bbeba0..2b7feb92e40f 100644 --- a/x/simulation/simulate.go +++ b/x/simulation/simulate.go @@ -50,7 +50,7 @@ func SimulateFromSeed( appStateFn simulation.AppStateFn, randAccFn simulation.RandomAccountFn, ops WeightedOperations, - blackListedAccs map[string]bool, + blockedAddrs map[string]bool, config simulation.Config, ) (stopEarly bool, exportedParams Params, err error) { // in case we have to end early, don't os.Exit so that we can run cleanup code. @@ -83,7 +83,7 @@ func SimulateFromSeed( var tmpAccs []simulation.Account for _, acc := range accs { - if !blackListedAccs[acc.Address.String()] { + if !blockedAddrs[acc.Address.String()] { tmpAccs = append(tmpAccs, acc) } }