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

Fix AfterImport and update black/white list variable namings #7159

Merged
merged 4 commits into from
Aug 25, 2020
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
20 changes: 10 additions & 10 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
22 changes: 11 additions & 11 deletions simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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. */
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ func TestAppSimulationAfterImport(t *testing.T) {
_, _, err = simulation.SimulateFromSeed(
t,
os.Stdout,
app.BaseApp,
newApp.BaseApp,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh copy paste. Sorry about that

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,
)
Expand Down
4 changes: 2 additions & 2 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion simapp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions x/simulation/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
}
Expand Down