Skip to content

Commit

Permalink
fix(iro): last plan id invariant fix (#1568)
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt authored Nov 27, 2024
1 parent 39f197c commit 2c31dd3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions x/iro/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ func InvariantPlan(k Keeper) uinv.Func {
}

lastPlanID := k.GetLastPlanId(ctx)
if lastPlanID != plans[len(plans)-1].Id {
return fmt.Errorf("last plan id mismatch: lastPlanID: %d, lastPlanInListID: %d", lastPlanID, plans[len(plans)-1].Id)
max_ := plans[0].Id
for _, plan := range plans {
max_ = max(plan.Id, max_)
}
if lastPlanID != max_ {
return fmt.Errorf("last plan id mismatch: lastPlanID: %d, max: %d", lastPlanID, max_)
}

var errs []error
Expand Down
2 changes: 1 addition & 1 deletion x/iro/keeper/iro.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (k Keeper) MustGetPlanByRollapp(ctx sdk.Context, rollappId string) types.Pl
return plan
}

// GetAllPlans returns all plans
// GetAllPlans returns plans sorted lexically by ID e.g. 1,10,100...
func (k Keeper) GetAllPlans(ctx sdk.Context, tradableOnly bool) (list []types.Plan) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PlanKeyPrefix)
iterator := sdk.KVStorePrefixIterator(store, []byte{})
Expand Down

0 comments on commit 2c31dd3

Please sign in to comment.