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

tech debt: refactor light client prune above and below #1397

Open
danwt opened this issue Nov 5, 2024 · 0 comments
Open

tech debt: refactor light client prune above and below #1397

danwt opened this issue Nov 5, 2024 · 0 comments

Comments

@danwt
Copy link
Contributor

danwt commented Nov 5, 2024

// PruneSignersAbove removes bookkeeping for all heights ABOVE h for given rollapp
// This should only be called after canonical client set
// TODO: plug into hard fork
func (k Keeper) PruneSignersAbove(ctx sdk.Context, rollapp string, h uint64) error {
client, ok := k.GetCanonicalClient(ctx, rollapp)
if !ok {
return gerrc.ErrInternal.Wrap(`
prune light client signers for rollapp before canonical client is set
this suggests fork happened prior to genesis bridge completion, which
shouldnt be allowed
`)
}
rng := collections.NewPrefixedPairRange[string, uint64](client).StartExclusive(h)
seqs := make([]string, 0)
heights := make([]uint64, 0)
// collect first to avoid del while iterating
if err := k.clientHeightToSigner.Walk(ctx, rng, func(key collections.Pair[string, uint64], value string) (stop bool, err error) {
seqs = append(seqs, value)
heights = append(heights, key.K2())
return false, nil
}); err != nil {
return errorsmod.Wrap(err, "walk signers")
}
for i := 0; i < len(seqs); i++ {
if err := k.RemoveSigner(ctx, seqs[i], client, heights[i]); err != nil {
return errorsmod.Wrap(err, "remove signer")
}
}
return nil
}
// PruneSignersBelow removes bookkeeping for all heights BELOW h for given rollapp
// This should only be called after canonical client set
func (k Keeper) PruneSignersBelow(ctx sdk.Context, rollapp string, h uint64) error {
client, ok := k.GetCanonicalClient(ctx, rollapp)
if !ok {
return gerrc.ErrInternal.Wrap(`
prune light client signers for rollapp before canonical client is set
this suggests fork happened prior to genesis bridge completion, which
shouldnt be allowed
`)
}
rng := collections.NewPrefixedPairRange[string, uint64](client).EndExclusive(h)
seqs := make([]string, 0)
heights := make([]uint64, 0)
// collect first to avoid del while iterating
if err := k.clientHeightToSigner.Walk(ctx, rng, func(key collections.Pair[string, uint64], value string) (stop bool, err error) {
seqs = append(seqs, value)
heights = append(heights, key.K2())
return false, nil
}); err != nil {
return errorsmod.Wrap(err, "walk signers")
}
for i := 0; i < len(seqs); i++ {
if err := k.RemoveSigner(ctx, seqs[i], client, heights[i]); err != nil {
return errorsmod.Wrap(err, "remove signer")
}
}
return nil
}

The two functions should be drier (generic or whatever). Also, the actual logic how their called in hook_listener can be simplified

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