diff --git a/app/export.go b/app/export.go index f0386a6c31..18473782b7 100644 --- a/app/export.go +++ b/app/export.go @@ -5,7 +5,7 @@ import ( "fmt" storetypes "cosmossdk.io/store/types" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,10 +20,10 @@ func (app *App) ExportAppStateAndValidators( forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string, ) (servertypes.ExportedApp, error) { // as if they could withdraw from the start of the next block - ctx := app.NewContextLegacy(true, tmproto.Header{Height: app.LastBlockHeight()}) + ctx := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()}) // We export at last height + 1, because that's the height at which - // Tendermint will start InitChain. + // CometBFT will start InitChain. height := app.LastBlockHeight() + 1 if forZeroHeight { height = 0 @@ -37,6 +37,7 @@ func (app *App) ExportAppStateAndValidators( if err != nil { return servertypes.ExportedApp{}, err } + appState, err := json.MarshalIndent(genState, "", " ") if err != nil { return servertypes.ExportedApp{}, err @@ -57,7 +58,8 @@ func (app *App) ExportAppStateAndValidators( // prepare for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated -// in favor of export at a block height +// +// in favor of export at a block height func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) error { var applyAllowedAddrs bool @@ -123,11 +125,11 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str // reinitialize all validators if err := app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { - // donate any unwithdrawn outstanding reward fraction tokens to the community pool valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator()) if err != nil { panic(err) } + // donate any unwithdrawn outstanding reward fraction tokens to the community pool scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valBz) if err != nil { panic(err) @@ -142,7 +144,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str } if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valBz); err != nil { - return true + panic(err) } return false }); err != nil { @@ -160,9 +162,11 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str return err } if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil { + // never called as BeforeDelegationCreated always returns nil return err } if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil { + // never called as AfterDelegationModified always returns nil return err } } @@ -200,8 +204,9 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str // Iterate through validators by power descending, reset bond heights, and // update bond intra-tx counters. - store := ctx.KVStore(app.keys[stakingtypes.StoreKey]) + store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey)) iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) + counter := int16(0) for ; iter.Valid(); iter.Next() { addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key())) @@ -218,6 +223,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str if err := app.StakingKeeper.SetValidator(ctx, validator); err != nil { return err } + counter++ } if err := iter.Close(); err != nil { diff --git a/app/test_helpers.go b/app/test_helpers.go index a4479932d8..9a2d5fd9fb 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -131,7 +131,7 @@ func SetupWithGenesisValSet(t *testing.T, cronosAdmin string, valSet *tmtypes.Va require.NoError(t, err) // init chain will set the validator set and initialize the genesis accounts - app.InitChain( + _, err = app.InitChain( &abci.RequestInitChain{ ChainId: TestAppChainID, Validators: []abci.ValidatorUpdate{}, @@ -139,6 +139,7 @@ func SetupWithGenesisValSet(t *testing.T, cronosAdmin string, valSet *tmtypes.Va AppStateBytes: stateBytes, }, ) + require.NoError(t, err) return app }