feat: enforce request_id idempotency in vault deduct#389
Open
Harbduls wants to merge 1 commit into
Open
Conversation
Add persistent processed-request markers so a backend retry with the same request_id is rejected, giving safe at-least-once retry semantics. Changes: - StorageKey::ProcessedRequest(Symbol) new temporary-storage key; written on every successful deduct/batch_deduct where request_id is Some(id); auto-expires after ~30 days (REQUEST_ID_BUMP_AMOUNT). - VaultError::DuplicateRequestId (code 28) returned when a deduct is attempted with a request_id that was already processed within the retention window. - deduct(): idempotency check before any state mutation; marker written after successful balance update, before token transfer. - batch_deduct(): full-pass duplicate check (against storage AND within the batch itself) before any state write; all markers written atomically after the balance update. - is_request_processed(request_id): new public view that returns true when the marker is present in temporary storage. - REQUEST_ID_BUMP_THRESHOLD / REQUEST_ID_BUMP_AMOUNT constants added. - Module declarations added to lib.rs for all test sub-modules. - contracts/vault/STORAGE.md updated with ProcessedRequest key, temporary-storage TTL table, retention policy, and version 1.2 entry. - contracts/vault/src/test_idempotency.rs: 14 new tests covering duplicate rejection, distinct ids, None pass-through, failed-deduct non-marking, batch atomicity, intra-batch duplicate detection, and is_request_processed view correctness.
|
@Harbduls 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! 🚀 |
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 #350
Add persistent processed-request markers so a backend retry with the same request_id is rejected, giving safe at-least-once retry semantics.
Changes: