Skip to content

feat(subscription): add check_subscriptions batch read with SubStatus - #274

Merged
Busiii-adetiba merged 1 commit into
SynapsVault:mainfrom
Ayilojay:feat/subscription-check-subscriptions
Nov 25, 2026
Merged

Busiii-adetiba merged 1 commit into
SynapsVault:mainfrom
Ayilojay:feat/subscription-check-subscriptions

Conversation

@Ayilojay

Copy link
Copy Markdown

Clients verifying many memberships were forced to call is_active once per plan-subscriber pair. This adds a capped, ordered batch query that returns explicit Missing / Active / Expired results in a single transaction.

What changed

contracts/subscription/src/lib.rs

  • **** ( enum) — three variants:

    •   — no record exists for the pair
      
    • — live; value is ledgers until current_period_end
    •   — record exists but current_period_end ≤ ledger.sequence()
      

    A cancelled-but-active subscription returns Active (paid window still open).
    Expiry boundary is exclusive, consistent with the workspace convention.

  • **** — single-pair convenience read. Extends the persistent-entry TTL when a record is found, matching is_active and get_subscription.

  • **** — batch read of up to MAX_BATCH_SIZE (50) pairs. Output is index-aligned with input. Missing entries return SubStatus::Missing, not an error. Empty batch returns SubNotFound; oversized batch returns BatchTooLarge. Both guards fire before any storage read so the call is a cheap no-op on rejection.

  • **** — cap matching access-lease's check_leases. At one persistent read per entry the worst-case ledger-entry budget stays within the Soroban per-transaction limit.

  • **** — new discriminant, stable and pinned by the error_codes_are_stable test.

tests (inline mod tests)

  • — pins all discriminants including BatchTooLarge=14.
  • — four subscribers on one plan cover Active, Expired, cancelled-but-Active, and Missing; asserts index alignment and the exclusive expiry boundary.
  • — 50 missing pairs → 50 × Missing.
  • — 51 pairs → BatchTooLarge.
  • — 0 pairs → SubNotFound.
  • / / — unit coverage for the single-pair path.
  • — confirms the original is_active entrypoint is unaffected by the new functions.

docs/CONTRACTS.md

  • Added SubStatus type and MAX_BATCH_SIZE constant to the subscription Data section.
  • Added sub_status and check_subscriptions rows to the Functions table.
  • Added sub_status / check_subscriptions semantics (variants, boundary rule, TTL behaviour, pagination guidance).
  • Added BatchTooLarge = 14 to the subscription Errors table.
  • Added sub_status / check_subscriptions to the access-control matrix (permissionless).
  • Added BatchTooLarge to the cross-contract error code numbering table.
  • Added compatibility note: purely additive — no storage changes, no migration required, existing deployments unaffected.

Compatibility

No storage keys added or removed. No existing entrypoints changed. Older clients that do not know about SubStatus simply never call the new functions. is_active remains and is unmodified.

Summary

Checklist

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings and cargo test --workspace pass
  • New behaviour is covered by tests (including the unauthorised / error path)
  • docs/CONTRACTS.md and rustdoc updated for any interface, storage, event or error change
  • Error codes were appended, not renumbered
    closes [subscription] Add bounded batch subscription status reads #231

Clients verifying many memberships were forced to call is_active once per
plan-subscriber pair. This adds a capped, ordered batch query that returns
explicit Missing / Active / Expired results in a single transaction.

## What changed

### contracts/subscription/src/lib.rs

- **** ( enum) — three variants:
  -       — no record exists for the pair
  -   — live; value is ledgers until current_period_end
  -       — record exists but current_period_end ≤ ledger.sequence()
  A cancelled-but-active subscription returns Active (paid window still open).
  Expiry boundary is exclusive, consistent with the workspace convention.

- **** — single-pair convenience
  read. Extends the persistent-entry TTL when a record is found, matching
  is_active and get_subscription.

- **** — batch
  read of up to MAX_BATCH_SIZE (50) pairs. Output is index-aligned with input.
  Missing entries return SubStatus::Missing, not an error. Empty batch returns
  SubNotFound; oversized batch returns BatchTooLarge. Both guards fire before
  any storage read so the call is a cheap no-op on rejection.

- **** — cap matching access-lease's check_leases.
  At one persistent read per entry the worst-case ledger-entry budget stays
  within the Soroban per-transaction limit.

- **** — new discriminant, stable and pinned by
  the error_codes_are_stable test.

### tests (inline mod tests)

-  — pins all discriminants including BatchTooLarge=14.
-  — four subscribers on one plan cover
  Active, Expired, cancelled-but-Active, and Missing; asserts index alignment
  and the exclusive expiry boundary.
-  — 50 missing pairs → 50 × Missing.
-  — 51 pairs → BatchTooLarge.
-  — 0 pairs → SubNotFound.
-  /  /
   — unit coverage for the single-pair path.
-  — confirms the original is_active entrypoint is
  unaffected by the new functions.

### docs/CONTRACTS.md

- Added SubStatus type and MAX_BATCH_SIZE constant to the subscription Data
  section.
- Added sub_status and check_subscriptions rows to the Functions table.
- Added sub_status / check_subscriptions semantics (variants, boundary rule,
  TTL behaviour, pagination guidance).
- Added BatchTooLarge = 14 to the subscription Errors table.
- Added sub_status / check_subscriptions to the access-control matrix
  (permissionless).
- Added BatchTooLarge to the cross-contract error code numbering table.
- Added compatibility note: purely additive — no storage changes, no
  migration required, existing deployments unaffected.

## Compatibility

No storage keys added or removed. No existing entrypoints changed. Older
clients that do not know about SubStatus simply never call the new functions.
is_active remains and is unmodified.
@drips-wave

drips-wave Bot commented Nov 25, 2026

Copy link
Copy Markdown

@Ayilojay Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Busiii-adetiba
Busiii-adetiba merged commit a6d8817 into SynapsVault:main Nov 25, 2026
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.

[subscription] Add bounded batch subscription status reads

2 participants