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

CNS-315: implement subscription renewal #352

Merged
merged 3 commits into from
Mar 16, 2023

Conversation

orenl-lava
Copy link
Contributor

@orenl-lava orenl-lava commented Mar 12, 2023

Implement subscription renewal:

Renewal takes place when buying a subscription for a consumer with an existing subscription, with the same plan (index and version). In this case, the existing subscription gets extended by the (new) duration requested. The total duration is limited to 1 year - and 1 additional month of grace to allow renewal with yearly discount before an existing subscription ends.

The first commit changes subscription logic to track CUs and remaining duration monthly.
The second commit adds support for subscription renewal.

(PR based on branch #351 for https://github.com/lavanet/lava/tree/CNS-334-subscription-fixes-tests-and-cli)

@orenl-lava orenl-lava force-pushed the CNS-315-subscription-renewal branch 6 times, most recently from bc7c274 to c96d2d0 Compare March 14, 2023 04:29
x/subscription/types/subscription.go Outdated Show resolved Hide resolved
x/subscription/types/subscription.go Show resolved Hide resolved
x/subscription/types/subscription.go Outdated Show resolved Hide resolved
x/subscription/keeper/epoch_start.go Outdated Show resolved Hide resolved
x/subscription/keeper/subscription.go Outdated Show resolved Hide resolved
x/subscription/keeper/subscription.go Show resolved Hide resolved
proto/subscription/subscription.proto Show resolved Hide resolved
@orenl-lava orenl-lava changed the title CNS 315: implement subscription renewal CNS-315: implement subscription renewal Mar 15, 2023
Yaroms
Yaroms previously approved these changes Mar 15, 2023
@orenl-lava orenl-lava force-pushed the CNS-334-subscription-fixes-tests-and-cli branch from c8f3ff9 to d6bd5ff Compare March 15, 2023 17:02
@orenl-lava orenl-lava force-pushed the CNS-315-subscription-renewal branch from abbf102 to bf12a3e Compare March 16, 2023 10:01
@orenl-lava orenl-lava changed the base branch from CNS-334-subscription-fixes-tests-and-cli to main March 16, 2023 10:02
@orenl-lava orenl-lava dismissed Yaroms’s stale review March 16, 2023 10:02

The base branch was changed.

Copy link
Collaborator

@omerlavanet omerlavanet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dup line, add zero check for duration

@orenl-lava orenl-lava requested a review from omerlavanet March 16, 2023 14:20
Plans always indicate CU limits per month. Therefore, change subscription logic
to track remaining CUs monthly:

- Keep track of remining duration (in months)

- Set expiry always 1 month forward, and then decrement the remaining duration:
  - if reaches zero: mark for deletion (to allow grace period for payments)
  - if marked for deleteion: grace period ended, delete the subscription
  - otherwise, reset remaining CU (to monthly limit as per the plan)

- Simplify "1 month forward" to be "same day-of-month next month, but no later
  than the 28th of that month" (useful to have a stable day-of-month).

- Use epochskeeper.BlocksToSave() for the number of blocks to linger until an
  expired subscription turns stale (instead of time based deadline).
Subscription renewal happens when buying a subscription for a consumer with an
existing subscription, with the same plan (index and version). The existing
subscription is extended by the new duration requested. The total duration is
limited to 1 year, but also 1 additional month to allow renewal with yearly
discount before an existing subscription ends.
@orenl-lava orenl-lava force-pushed the CNS-315-subscription-renewal branch from 7419770 to 8b26eff Compare March 16, 2023 14:35
@omerlavanet omerlavanet merged commit 8ef954c into main Mar 16, 2023
@omerlavanet omerlavanet deleted the CNS-315-subscription-renewal branch March 16, 2023 15:25
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

Successfully merging this pull request may close these issues.

3 participants