Merge PR #3454: Add --jail-whitelist to gaiad export
This commit is contained in:
@@ -58,6 +58,6 @@ func TestGaiadExport(t *testing.T) {
|
||||
|
||||
// Making a new app object with the db, so that initchain hasn't been called
|
||||
newGapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true)
|
||||
_, _, err := newGapp.ExportAppStateAndValidators(false)
|
||||
_, _, err := newGapp.ExportAppStateAndValidators(false, []string{})
|
||||
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
|
||||
}
|
||||
|
||||
+25
-3
@@ -2,6 +2,7 @@ package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
@@ -18,14 +19,14 @@ import (
|
||||
)
|
||||
|
||||
// export the state of gaia for a genesis file
|
||||
func (app *GaiaApp) ExportAppStateAndValidators(forZeroHeight bool) (
|
||||
func (app *GaiaApp) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []string) (
|
||||
appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {
|
||||
|
||||
// as if they could withdraw from the start of the next block
|
||||
ctx := app.NewContext(true, abci.Header{Height: app.LastBlockHeight()})
|
||||
|
||||
if forZeroHeight {
|
||||
app.prepForZeroHeightGenesis(ctx)
|
||||
app.prepForZeroHeightGenesis(ctx, jailWhiteList)
|
||||
}
|
||||
|
||||
// iterate to get the accounts
|
||||
@@ -56,7 +57,23 @@ func (app *GaiaApp) ExportAppStateAndValidators(forZeroHeight bool) (
|
||||
}
|
||||
|
||||
// prepare for fresh start at zero height
|
||||
func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context) {
|
||||
func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []string) {
|
||||
applyWhiteList := false
|
||||
|
||||
//Check if there is a whitelist
|
||||
if len(jailWhiteList) > 0 {
|
||||
applyWhiteList = true
|
||||
}
|
||||
|
||||
whiteListMap := make(map[string]bool)
|
||||
|
||||
for _, addr := range jailWhiteList {
|
||||
_, err := sdk.ValAddressFromBech32(addr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
whiteListMap[addr] = true
|
||||
}
|
||||
|
||||
/* Just to be safe, assert the invariants on current state. */
|
||||
app.assertRuntimeInvariantsOnContext(ctx)
|
||||
@@ -136,6 +153,9 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context) {
|
||||
validator.BondHeight = 0
|
||||
validator.UnbondingHeight = 0
|
||||
valConsAddrs = append(valConsAddrs, validator.ConsAddress())
|
||||
if applyWhiteList && !whiteListMap[addr.String()] {
|
||||
validator.Jailed = true
|
||||
}
|
||||
|
||||
app.stakingKeeper.SetValidator(ctx, validator)
|
||||
counter++
|
||||
@@ -143,6 +163,8 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context) {
|
||||
|
||||
iter.Close()
|
||||
|
||||
_ = app.stakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
|
||||
/* Handle slashing state. */
|
||||
|
||||
// reset start height on signing infos
|
||||
|
||||
@@ -416,7 +416,7 @@ func TestGaiaImportExport(t *testing.T) {
|
||||
|
||||
fmt.Printf("Exporting genesis...\n")
|
||||
|
||||
appState, _, err := app.ExportAppStateAndValidators(false)
|
||||
appState, _, err := app.ExportAppStateAndValidators(false, []string{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -520,7 +520,7 @@ func TestGaiaSimulationAfterImport(t *testing.T) {
|
||||
|
||||
fmt.Printf("Exporting genesis...\n")
|
||||
|
||||
appState, _, err := app.ExportAppStateAndValidators(true)
|
||||
appState, _, err := app.ExportAppStateAndValidators(true, []string{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application
|
||||
}
|
||||
|
||||
func exportAppStateAndTMValidators(
|
||||
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool,
|
||||
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
|
||||
) (json.RawMessage, []tmtypes.GenesisValidator, error) {
|
||||
if height != -1 {
|
||||
gApp := app.NewGaiaApp(logger, db, traceStore, false)
|
||||
@@ -74,8 +74,8 @@ func exportAppStateAndTMValidators(
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return gApp.ExportAppStateAndValidators(forZeroHeight)
|
||||
return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
|
||||
}
|
||||
gApp := app.NewGaiaApp(logger, db, traceStore, true)
|
||||
return gApp.ExportAppStateAndValidators(forZeroHeight)
|
||||
return gApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user