Skip to content

Commit c766993

Browse files
authored
Merge PR #3454: Add --jail-whitelist to gaiad export
1 parent c04c696 commit c766993

File tree

7 files changed

+38
-12
lines changed

7 files changed

+38
-12
lines changed

PENDING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ IMPROVEMENTS
5858
* [\#3418](https://github.com/cosmos/cosmos-sdk/issues/3418) Add vesting account
5959
genesis validation checks to `GaiaValidateGenesisState`.
6060
* [\#3420](https://github.com/cosmos/cosmos-sdk/issues/3420) Added maximum length to governance proposal descriptions and titles
61+
* [\#3454](https://github.com/cosmos/cosmos-sdk/pull/3454) Add `--jail-whitelist` to `gaiad export` to enable testing of complex exports
6162
* [\#3424](https://github.com/cosmos/cosmos-sdk/issues/3424) Allow generation of gentxs with empty memo field.
6263

6364
* SDK
@@ -79,7 +80,7 @@ BUG FIXES
7980
- [\#3419](https://github.com/cosmos/cosmos-sdk/pull/3419) Fix `q distr slashes` panic
8081
- [\#3453](https://github.com/cosmos/cosmos-sdk/pull/3453) The `rest-server` command didn't respect persistent flags such as `--chain-id` and `--trust-node` if they were
8182
passed on the command line.
82-
83+
8384
* Gaia
8485

8586
* SDK

cmd/gaia/app/app_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ func TestGaiadExport(t *testing.T) {
5858

5959
// Making a new app object with the db, so that initchain hasn't been called
6060
newGapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true)
61-
_, _, err := newGapp.ExportAppStateAndValidators(false)
61+
_, _, err := newGapp.ExportAppStateAndValidators(false, []string{})
6262
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
6363
}

cmd/gaia/app/export.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package app
22

33
import (
44
"encoding/json"
5+
"log"
56

67
abci "github.com/tendermint/tendermint/abci/types"
78
tmtypes "github.com/tendermint/tendermint/types"
@@ -18,14 +19,14 @@ import (
1819
)
1920

2021
// export the state of gaia for a genesis file
21-
func (app *GaiaApp) ExportAppStateAndValidators(forZeroHeight bool) (
22+
func (app *GaiaApp) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []string) (
2223
appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {
2324

2425
// as if they could withdraw from the start of the next block
2526
ctx := app.NewContext(true, abci.Header{Height: app.LastBlockHeight()})
2627

2728
if forZeroHeight {
28-
app.prepForZeroHeightGenesis(ctx)
29+
app.prepForZeroHeightGenesis(ctx, jailWhiteList)
2930
}
3031

3132
// iterate to get the accounts
@@ -56,7 +57,23 @@ func (app *GaiaApp) ExportAppStateAndValidators(forZeroHeight bool) (
5657
}
5758

5859
// prepare for fresh start at zero height
59-
func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context) {
60+
func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []string) {
61+
applyWhiteList := false
62+
63+
//Check if there is a whitelist
64+
if len(jailWhiteList) > 0 {
65+
applyWhiteList = true
66+
}
67+
68+
whiteListMap := make(map[string]bool)
69+
70+
for _, addr := range jailWhiteList {
71+
_, err := sdk.ValAddressFromBech32(addr)
72+
if err != nil {
73+
log.Fatal(err)
74+
}
75+
whiteListMap[addr] = true
76+
}
6077

6178
/* Just to be safe, assert the invariants on current state. */
6279
app.assertRuntimeInvariantsOnContext(ctx)
@@ -136,13 +153,18 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context) {
136153
validator.BondHeight = 0
137154
validator.UnbondingHeight = 0
138155
valConsAddrs = append(valConsAddrs, validator.ConsAddress())
156+
if applyWhiteList && !whiteListMap[addr.String()] {
157+
validator.Jailed = true
158+
}
139159

140160
app.stakingKeeper.SetValidator(ctx, validator)
141161
counter++
142162
}
143163

144164
iter.Close()
145165

166+
_ = app.stakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
167+
146168
/* Handle slashing state. */
147169

148170
// reset start height on signing infos

cmd/gaia/app/sim_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func TestGaiaImportExport(t *testing.T) {
416416

417417
fmt.Printf("Exporting genesis...\n")
418418

419-
appState, _, err := app.ExportAppStateAndValidators(false)
419+
appState, _, err := app.ExportAppStateAndValidators(false, []string{})
420420
if err != nil {
421421
panic(err)
422422
}
@@ -520,7 +520,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
520520

521521
fmt.Printf("Exporting genesis...\n")
522522

523-
appState, _, err := app.ExportAppStateAndValidators(true)
523+
appState, _, err := app.ExportAppStateAndValidators(true, []string{})
524524
if err != nil {
525525
panic(err)
526526
}

cmd/gaia/cmd/gaiad/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application
6666
}
6767

6868
func exportAppStateAndTMValidators(
69-
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool,
69+
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
7070
) (json.RawMessage, []tmtypes.GenesisValidator, error) {
7171
if height != -1 {
7272
gApp := app.NewGaiaApp(logger, db, traceStore, false)
7373
err := gApp.LoadHeight(height)
7474
if err != nil {
7575
return nil, nil, err
7676
}
77-
return gApp.ExportAppStateAndValidators(forZeroHeight)
77+
return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
7878
}
7979
gApp := app.NewGaiaApp(logger, db, traceStore, true)
80-
return gApp.ExportAppStateAndValidators(forZeroHeight)
80+
return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
8181
}

server/constructors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type (
1919

2020
// AppExporter is a function that dumps all app state to
2121
// JSON-serializable structure and returns the current validator set.
22-
AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool) (json.RawMessage, []tmtypes.GenesisValidator, error)
22+
AppExporter func(log.Logger, dbm.DB, io.Writer, int64, bool, []string) (json.RawMessage, []tmtypes.GenesisValidator, error)
2323
)
2424

2525
func openDB(rootDir string) (dbm.DB, error) {

server/export.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
const (
1919
flagHeight = "height"
2020
flagForZeroHeight = "for-zero-height"
21+
flagJailWhitelist = "jail-whitelist"
2122
)
2223

2324
// ExportCmd dumps app state to JSON.
@@ -54,7 +55,8 @@ func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.C
5455
}
5556
height := viper.GetInt64(flagHeight)
5657
forZeroHeight := viper.GetBool(flagForZeroHeight)
57-
appState, validators, err := appExporter(ctx.Logger, db, traceWriter, height, forZeroHeight)
58+
jailWhiteList := viper.GetStringSlice(flagJailWhitelist)
59+
appState, validators, err := appExporter(ctx.Logger, db, traceWriter, height, forZeroHeight, jailWhiteList)
5860
if err != nil {
5961
return errors.Errorf("error exporting state: %v\n", err)
6062
}
@@ -78,6 +80,7 @@ func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.C
7880
}
7981
cmd.Flags().Int64(flagHeight, -1, "Export state from a particular height (-1 means latest height)")
8082
cmd.Flags().Bool(flagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)")
83+
cmd.Flags().StringSlice(flagJailWhitelist, []string{}, "List of validators to not jail state export")
8184
return cmd
8285
}
8386

0 commit comments

Comments
 (0)