feat(contract): add deterministic expiry sweeping with bounded work - #197
Open
Johnpii1 wants to merge 2 commits into
Open
feat(contract): add deterministic expiry sweeping with bounded work#197Johnpii1 wants to merge 2 commits into
Johnpii1 wants to merge 2 commits into
Conversation
feat: add bounded expiry sweep batches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #189
Motivation
Expired escrowed transfers must be reclaimable without risking unbounded work or double-refunds.
Provide a permissionless, idempotent cleanup mechanism that respects expiry semantics and transaction budgets.
Description
Add a new permissionless entrypoint sweep_expired_batch(start_id: u64, limit: u32) -> Result<Vec, Error> that inspects at most min(limit, MAX_SWEEP_BATCH_SIZE) sequential ids (inclusive cursor, 0 clamped to 1) and refunds only transfers whose ledger_timestamp > expiry, marking them Cancelled and emitting cancelled events (implementation in src/lib.rs).
Introduce MAX_SWEEP_BATCH_SIZE constant (50) to bound per-call work and make retries deterministic and safe (no double refunds).
Update storage and accounting during sweeps: transfer token from contract to recorded sender, decrement TotalEscrowed, call assert_supply_invariant, and extend instance TTL when work occurred.
Add regression/unit tests covering expiry boundary, live-transfer skipping, idempotency, cursor advancement, bounded work, and fund/liability conservation (src/test.rs).
Document the new entrypoint and behavioural guarantees in README.md and docs/entrypoint-reference.md.
Testing
Ran formatting and style checks: cargo fmt --all -- --check and cargo clippy --lib --locked -- -D warnings, which completed successfully.
Ran unit tests: cargo test --locked sweep_expired_batch (targeted) and cargo test --locked (full suite); result: tests passed (full suite: 131 passed, 0 failed, 4 ignored).
Built release WASM: make build and verified artifact budget with ./scripts/test-check-wasm-size.sh, both checks succeeded.
Verified no diff/check issues with git diff --check (passed).