Skip to content

Commit

Permalink
CNS-434: fix two silent bugs in subscription logic
Browse files Browse the repository at this point in the history
1. CreateSubscription() should only update the expiry time if adding a new
subscription, otherwise upon update/extension.

2. GetPlanFromSubscription() should use the recorded Plan block rather than
that of when the subscription created.
  • Loading branch information
orenl-lava committed Jun 19, 2023
1 parent c84999b commit 741050d
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions x/subscription/keeper/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,16 @@ func (k Keeper) CreateSubscription(
utils.Attribute{Key: "duration", Value: sub.DurationLeft},
)
}

// use current block's timestamp to calculate next month's time
expiry := nextMonth(ctx.BlockTime())
sub.MonthExpiryTime = uint64(expiry.Unix())
}

// update total (last requested) duration and remaining duration
sub.DurationTotal = duration
sub.DurationLeft += duration

// use current block's timestamp to calculate next month's time
timestamp := ctx.BlockTime()

expiry := nextMonth(timestamp)

sub.MonthExpiryTime = uint64(expiry.Unix())

if err := sub.ValidateSubscription(); err != nil {
return utils.LavaFormatWarning("create subscription failed", err)
}
Expand Down Expand Up @@ -269,7 +266,7 @@ func (k Keeper) GetPlanFromSubscription(ctx sdk.Context, consumer string) (plans
)
}

plan, found := k.plansKeeper.FindPlan(ctx, sub.PlanIndex, sub.Block)
plan, found := k.plansKeeper.FindPlan(ctx, sub.PlanIndex, sub.PlanBlock)
if !found {
err := utils.LavaFormatError("can't find plan from subscription with consumer address", sdkerrors.ErrKeyNotFound,
utils.Attribute{Key: "consumer", Value: consumer},
Expand Down

0 comments on commit 741050d

Please sign in to comment.