Skip to content

Harden subscription batching and query pagination#11

Open
jdrains110-beep wants to merge 4 commits intoPiNetwork:mainfrom
jdrains110-beep:fix/subscription-batch-and-pagination
Open

Harden subscription batching and query pagination#11
jdrains110-beep wants to merge 4 commits intoPiNetwork:mainfrom
jdrains110-beep:fix/subscription-batch-and-pagination

Conversation

@jdrains110-beep
Copy link
Copy Markdown

Summary

This PR hardens the subscription contract's scaling behavior and adds a safer read path for large subscription sets.

What changed

  • cap process() to a contract-enforced maximum batch size of 100 entries per call
  • reject overflowing approval-window math during register_service() instead of deferring it to later lifecycle calls
  • add get_subscriber_subs_paginated() and get_merchant_subs_paginated() so clients can page through large result sets without relying on unbounded vectors
  • add focused tests covering the batch cap, paginated queries, and early overflow rejection
  • document the new limits and paginated APIs in the subscription contract README

Why

The previous API surface depended on caller discipline for batch and query sizing. That makes process() and the listing APIs harder to use safely as subscription counts grow.

Closes #10

Validation

  • Verified no editor diagnostics in contracts/subscription/src/lib.rs
  • Verified no editor diagnostics in contracts/subscription/src/test.rs
  • Full cargo test could not be run here because cargo is not installed in this environment

Copilot AI review requested due to automatic review settings April 22, 2026 17:13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Hardens the Soroban subscription contract against unbounded batch/query sizes and shifts overflow validation earlier to make scaling behavior safer and more predictable for clients.

Changes:

  • Enforce a hard process() batch cap (100) regardless of caller-provided limit.
  • Add paginated query APIs for subscriber/service subscription listings, with a hard page-size cap (100).
  • Reject approval-window arithmetic overflow during register_service() and expand tests/docs accordingly.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
contracts/subscription/src/lib.rs Adds batch/page caps, early overflow validation, and new paginated query endpoints.
contracts/subscription/src/test.rs Adds tests for early overflow rejection, batch cap enforcement, and basic pagination behavior.
contracts/subscription/README.md Documents the new caps and paginated query APIs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +229 to +233
fn paginate_subscriptions(env: &Env, sub_ids: &Vec<u64>, offset: u32, limit: u32) -> SubscriptionPage {
let total = sub_ids.len();
let capped_limit = core::cmp::min(limit, MAX_QUERY_PAGE_SIZE);
let start = offset.min(total);
let end = start.saturating_add(capped_limit).min(total);
Comment on lines +292 to +294
price
.checked_mul(approve_periods as i128)
.ok_or(ContractError::TimestampOverflow)?;
Ok(())
}

fn paginate_subscriptions(env: &Env, sub_ids: &Vec<u64>, offset: u32, limit: u32) -> SubscriptionPage {
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.

Harden subscription batching and query pagination

2 participants