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>
This commit is contained in:
colin axnér 2020-08-25 17:55:19 +02:00 committed by GitHub
parent 78194e1cdd
commit 56f4ccfd26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 28 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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,
)

View File

@ -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)
}

View File

@ -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.

View File

@ -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)
}
}