Description
CalloraVault::deduct accepts an optional request_id: Symbol and emits it in events, but never persists or checks it, so a backend retry with the same request_id double-charges the consumer. Add a persistent processed-request set so a repeated request_id is rejected, giving safe at-least-once retry semantics.
Requirements and Context
- Add
StorageKey::ProcessedRequest(Symbol) persistent marker set on each successful deduct.
- Reject deducts whose
request_id was already processed (only when request_id is Some).
- Extend the marker's TTL and document retention; clarify behavior when
request_id is None.
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested Execution
- Fork the repo and create a branch
git checkout -b feature/vault-request-id-idempotency
- Implement changes
contracts/vault/src/lib.rs — processed-request storage + guard
contracts/vault/STORAGE.md — document retention/TTL
- Test and commit
cargo test -p callora-vault
- Test duplicate
request_id rejected, distinct ids succeed, None unaffected
- Include test output and notes in the PR
Example commit message
feat: enforce request_id idempotency in vault deduct
Acceptance Criteria
Guidelines
.rs under contracts/vault/src/, cargo test, /// docs, minimum 95% line coverage, no unwrap() in prod paths
- Clear documentation and inline comments
- Timeframe: 96 hours
Description
CalloraVault::deductaccepts an optionalrequest_id: Symboland emits it in events, but never persists or checks it, so a backend retry with the samerequest_iddouble-charges the consumer. Add a persistent processed-request set so a repeatedrequest_idis rejected, giving safe at-least-once retry semantics.Requirements and Context
StorageKey::ProcessedRequest(Symbol)persistent marker set on each successful deduct.request_idwas already processed (only whenrequest_idisSome).request_idisNone.Suggested Execution
contracts/vault/src/lib.rs— processed-request storage + guardcontracts/vault/STORAGE.md— document retention/TTLcargo test -p callora-vaultrequest_idrejected, distinct ids succeed,NoneunaffectedExample commit message
Acceptance Criteria
Some(request_id)deduct rejectedNonebehave correctlyGuidelines
.rsundercontracts/vault/src/,cargo test,///docs, minimum 95% line coverage, nounwrap()in prod paths