Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt committed Nov 5, 2024
1 parent 3eb2090 commit f1a7975
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 41 deletions.
43 changes: 3 additions & 40 deletions x/lightclient/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ func (k Keeper) CanUnbond(ctx sdk.Context, seq sequencertypes.Sequencer) error {
})
}

// PruneSigners removes bookkeeping for all heights ABOVE h for given rollapp
// 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) PruneSigners(ctx sdk.Context, rollapp string, h uint64) error {
func (k Keeper) PruneSignersAbove(ctx sdk.Context, rollapp string, h uint64) error {
client, ok := k.GetCanonicalClient(ctx, rollapp)
if !ok {
return gerrc.ErrInternal.Wrap(`
Expand Down Expand Up @@ -130,10 +130,7 @@ shouldnt be allowed
return nil
}

// func (p *PairRange[K1, K2])
type Foo[K1, K2 any] func(p *collections.PairRange[K1, K2], k2 K2) *collections.PairRange[K1, K2]

// PruneSignersBelow PruneSigners removes bookkeeping for all heights BELOW h for given rollapp
// 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)
Expand Down Expand Up @@ -166,40 +163,6 @@ shouldnt be allowed
return nil
}

// PruneSignersBelow PruneSigners removes bookkeeping for all heights BELOW h for given rollapp
// This should only be called after canonical client set
func (k Keeper) PruneGeneric(ctx sdk.Context, rollapp string, h uint64, f Foo[string, 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)
rng := f(collections.NewPrefixedPairRange[string, uint64](client), 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
}

// GetSigner returns the sequencer address who signed the header in the update
func (k Keeper) GetSigner(ctx sdk.Context, client string, h uint64) (string, error) {
return k.clientHeightToSigner.Get(ctx, collections.Join(client, h))
Expand Down
2 changes: 1 addition & 1 deletion x/lightclient/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *TestSuite) TestUnbondConditionFlow() {
utest.IsErr(s.Require(), err, sequencertypes.ErrUnbondNotAllowed)

// we prune some, but still not allowed
err = s.k().PruneSigners(s.Ctx, seq.RollappId, 6)
err = s.k().PruneSignersAbove(s.Ctx, seq.RollappId, 6)
s.Require().NoError(err)

err = s.k().CanUnbond(s.Ctx, seq)
Expand Down

0 comments on commit f1a7975

Please sign in to comment.