feat: caller-supplied idempotency key for place_bets batch#769
Merged
greatest0fallt1me merged 1 commit intoJun 29, 2026
Merged
Conversation
- Add DataKey::PlaceBetsIdem(Address, BytesN<32>) to storage.rs - Add PLACE_BETS_IDEM_TTL_LEDGERS = 7 * LEDGERS_PER_DAY constant - Add Error::IdempotentBatchAlreadyApplied = 509 to err.rs - Add idempotency_key: BytesN<32> param to BetManager::place_bets - Guard: reject reuse within TTL with IdempotentBatchAlreadyApplied - Consume key atomically after successful batch (persistent + TTL) - Update lib.rs entrypoint and all existing call sites - Add place_bets_idempotency_tests.rs: 5 tests covering happy path, duplicate key rejection, different key acceptance, per-user key scoping, and post-TTL re-use
|
@Keengfk 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.
feat: caller-supplied idempotency key for place_bets batch
Summary
place_bets previously had no per-batch deduplication token. A client retry
after a partial failure could double-submit bets. This PR adds a
caller-supplied BytesN<32> idempotency key consumed atomically on the first
successful call.
Changes
storage.rs
from different users never collide
s/ledger); documented inline
err.rs
bets.rs
(atomic)
lib.rs
place_bets_idempotency_tests.rs (new)
key scoped per user, key reusable after TTL
Acceptance criteria
┌───────────┬────────┐
│ Criterion │ Status │
├──────────────────────────────────────────────────────────┼────────┤
│ Repeated key rejected with IdempotentBatchAlreadyApplied │ ✅ │
├──────────────────────────────────────────────────────────┼────────┤
│ TTL documented in storage.rs constants │ ✅ │
├──────────────────────────────────────────────────────────┼────────┤
│ No unwrap() introduced │ ✅ │
├──────────────────────────────────────────────────────────┼────────┤
│ Key scoped to (user, key) — no cross-user collisions │ ✅ │
└──────────────────────────────────────────────────────────┴────────┘
Testing
cargo test -p predictify-hybrid place_bets_idempotency -- --nocapture
cargo test -p predictify-hybrid batch_operations_tests -- --nocapture
closes #621