Skip to content

Add grace period to AuthorizationExtent#516

Draft
bkontur wants to merge 5 commits into
mainfrom
bko-auth-nits
Draft

Add grace period to AuthorizationExtent#516
bkontur wants to merge 5 commits into
mainfrom
bko-auth-nits

Conversation

@bkontur
Copy link
Copy Markdown
Collaborator

@bkontur bkontur commented May 10, 2026

Introduces a renew-only grace window after expiration, controlled by Config::GracePeriod. Authorization lifecycle becomes:

  • now < expiration: active (store + renew)
  • expiration <= now < grace_until: in grace (renew only)
  • now >= grace_until: expired (both rejected, eligible for remove_expired_*)

Highlights:

  • Authorization gains grace_until; helpers Authorization::expired(now) / ::past_grace(now) replace the previous Pallet::expired / ::past_grace.
  • check_authorization rejects store-in-grace; check_authorization_expired and remove_expired_authorization wait for grace_until.
  • v3→v4 migration tail-extends Authorization with grace_until = expiration + GracePeriod; entries already past v4 grace are dropped (and authorization_removed called to release provider refs).
  • v1→v2 migration now writes a frozen V2Authorization via a From impl, so later field additions to Authorization are a compile error in v2 rather than a silent shape change.
  • Westend / Paseo runtimes set type GracePeriod = AuthorizationPeriod (14 days, matching the RFC).

Introduces a renew-only grace window after `expiration`, controlled by
`Config::GracePeriod`. Authorization lifecycle becomes:

- now < expiration: active (store + renew)
- expiration <= now < grace_until: in grace (renew only)
- now >= grace_until: expired (both rejected, eligible for remove_expired_*)

Highlights:

- `Authorization` gains `grace_until`; helpers `Authorization::expired(now)` /
  `::past_grace(now)` replace the previous `Pallet::expired` / `::past_grace`.
- `check_authorization` rejects store-in-grace; `check_authorization_expired`
  and `remove_expired_authorization` wait for `grace_until`.
- v3→v4 migration tail-extends `Authorization` with
  `grace_until = expiration + GracePeriod`; entries already past v4 grace are
  dropped (and `authorization_removed` called to release provider refs).
- v1→v2 migration now writes a frozen `V2Authorization` via a `From` impl, so
  later field additions to `Authorization` are a compile error in v2 rather
  than a silent shape change.
- Westend / Paseo runtimes set `type GracePeriod = AuthorizationPeriod`
  (14 days, matching the RFC).
@bkontur bkontur requested review from franciscoaguirre, karolk91 and rosarp and removed request for franciscoaguirre May 10, 2026 21:11
bkontur added 2 commits May 11, 2026 09:39
Regenerated from the latest devnet runtime. Picks up:

- new `MultiBlockMigrations` pallet (hosts `MigrateV2ToV3`)
- `TransactionStorage::GracePeriod` constant and `Authorization::grace_until`
  field added by the grace-period work
- auto-renewal storage (`AutoRenewals`, `PendingAutoRenewals`,
  `TransactionByContentHash`), events, errors, and the
  `enable_auto_renew` / `disable_auto_renew` / `apply_block_inherents` calls
Comment thread pallets/transaction-storage/src/lib.rs Outdated
/// The block at which this authorization expires (start of grace).
expiration: BlockNumber,
/// The block at which the grace window ends. Always `>= expiration`.
grace_until: BlockNumber,
Copy link
Copy Markdown
Member

@rosarp rosarp May 11, 2026

Choose a reason for hiding this comment

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

grace_until may not be required.

  • it adds to storage
  • adds db v3->v4 migration, which can otherwise be skipped
  • Compute cost of deriving it on read: one Get::get() and one saturating_add. The calculation is strictly cheaper than reading the extra 4 bytes from storage on every access.

Can we avoid this field? And compute it instead?
If we avoid then functionally, the PR could be reduced to:

  • keep Authorization { extent, expiration } (no new field, no v3→v4 migration)
  • replace auth.past_grace(now) with now >= auth.expiration.saturating_add(T::GracePeriod::get())
  • drop migrations::v4 and the STORAGE_VERSION bump entirely
  • keep all the lifecycle semantics in check_authorization / remove_expired_authorization

pub fn account_has_active_authorization(who: &T::AccountId) -> bool {
Authorizations::<T>::get(AuthorizationScope::Account(who.clone()))
.is_some_and(|a| !Self::expired(a.expiration))
.is_some_and(|a| !a.expired(Self::now()))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

External caller for this is hop-promotion::can_account_promote (pallets/hop-promotion/src/lib.rs:106)

This means HOP promotions stop the moment grace begins, even though the account can still renew.
Is this intentional?
Or this needs to be past_grace instead?

.ok_or(Error::<T>::AuthorizationNotFound)?;
ensure!(
!Self::expired(auth.expiration) &&
!auth.expired(Self::now()) &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same question, in grace_period, we will not allow enable_auto_renew call right?
May be this could be documented.

bkontur added 2 commits May 12, 2026 09:48
# Conflicts:
#	pallets/transaction-storage/src/lib.rs
#	pallets/transaction-storage/src/migrations.rs
@bkontur
Copy link
Copy Markdown
Collaborator Author

bkontur commented May 12, 2026

@rosarp thank you for comment, I will check later, I will postpone this PR for now and wait for slots

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.

2 participants