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

app: (*SommelierApp).prepForZeroHeightGenesis should instead use a defer iter.Close() to ensure that the store gets closed on any panic #295

Open
odeke-em opened this issue Mar 15, 2024 · 0 comments

Comments

@odeke-em
Copy link

Summary of Bug

Given the usage of panics down below image in this code section

sommelier/app/export.go

Lines 155 to 174 in 3157d97

iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)
for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
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++
}
iter.Close()
, despite having an iter.Close() down at Line 174, it is important to use defer iter.Close() which will allow for clean up by closing the store and releasing resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant