ChainSafe / ChainSafe/open-creator-rails

Clear/purge expired and claimed subscriptions for smaller loops

Open
#53 1 comment 0 reactions 1 assignee Claimed by @rob1997 View on GitHub
Dominant language
Solidity
Stars
2
Forks
1
PR merge metrics
No merged PRs in 30d

Description

**What**

Add a mechanism to clear or purge subscription entries that have expired and have been fully claimed (both creator and registry fees). This reduces the number of entries iterated over in `_claimable` and related loops, leading to smaller loops and lower gas.

**Why**

Expired, fully-claimed subscriptions remain in storage and are still iterated in `_claimable`, adding unnecessary gas. Purging them shrinks the effective range of subscription data, speeds up claims, and can reduce storage.

**How**

- Add `purgeExpiredClaimedSubscription(address subscriber)` (or similar) that removes subscription entries where `endTime <= block.timestamp` and both creator and registry have claimed up to at least that `endTime`.
- Criteria for purge: subscription `endTime <= block.timestamp`, `creatorClaimedAt[subscriber] >= endTime`, `registryClaimedAt[subscriber] >= endTime`. Delete the entry and update indices/nonce so future loops skip it.
- Consider nonce compaction: after purging older entries, the loop could start from a "base nonce" or the nonce could be decremented so `_claimable` iterates from the first non-purged subscription.
- Callable by anyone (gas reimbursement incentive) or by owner/registry. Ensure no claimable value is lost.
- Integrate with "last claimed nonce" optimization (issue #49) if implemented—purged entries allow advancing the loop start.
- Add tests: purge after full claim, purge with mixed state, verify loop bounds.

**Acceptance Criteria**

- Expired and fully-claimed subscription entries can be purged
- Purge does not remove entries that still have unclaimed fees
- `_claimable` and related loops iterate over a smaller range after purge
- Purge logic is safe (no loss of claimable value)
- Tests cover purge scenarios

**Estimation**

**Dependencies**

Depends on Asset contract with claim and subscription logic; synergizes with #49 (last claimed nonce)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.