Skip to content

Commit

Permalink
fix: put iterator in closure (#1934)
Browse files Browse the repository at this point in the history
Co-authored-by: Milan Mulji <[email protected]>
  • Loading branch information
yaruwangway and mmulji-ic authored Dec 13, 2022
1 parent d9dcbcb commit 7308d50
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,25 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [

counter := int16(0)

defer iter.Close()
for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
if !found {
panic("expected validator, not found")
// Closure to ensure iterator doesn't leak.
func() {
defer iter.Close()
for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
if !found {
panic("expected validator, not found")
}

validator.UnbondingHeight = 0
if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
validator.Jailed = true
}

app.StakingKeeper.SetValidator(ctx, validator)
counter++
}

validator.UnbondingHeight = 0
if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
validator.Jailed = true
}

app.StakingKeeper.SetValidator(ctx, validator)
counter++
}
}()

_, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
if err != nil {
Expand Down

0 comments on commit 7308d50

Please sign in to comment.