Feature/webhook signing dedup dlq - #413
Merged
therealjhay merged 2 commits intoJul 28, 2026
Merged
Conversation
- Betta-Pay#353: Replace stellarId @unique with @@unique([stellarId, contractId, ledger]) composite constraint. Persist event catches P2002 and skips duplicates. - Betta-Pay#351: Add HMAC-SHA256 payload signing via signPayload(). Worker includes X-BettaPay-Signature header when signingSecret is set on the subscription. - Betta-Pay#354: Add dead-letter queue (indexer-webhooks-dlq) for webhook jobs that exhaust all retries. Admin endpoints GET /api/admin/webhooks/dead-letter and POST /api/admin/webhooks/dead-letter/:id/replay.
- Fresh deployments start from max(1, tip - INITIAL_BACKFILL_LEDGERS) instead of ledger 1, avoiding hours of catch-up. - Existing deployments resume from the latest indexed event + 1. - INDEX_FROM_LEDGER env var for manual override. - Falls back to ledger 1 if Stellar RPC is unavailable at startup. - 8 unit tests covering fresh DB, resume, manual override, RPC failure, floor-at-1, and invalid config edge cases.
|
@Omoboi-dev 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.
Summary
Closes #351
Closes #352
Closes #353
Closes #354
Adds intelligent startup ledger discovery, HMAC-SHA256 webhook signing, composite unique constraint for event deduplication, and a dead-letter queue for failed webhook deliveries.
Changes
#352 — Intelligent startup ledger discovery
max(1, tip - INITIAL_BACKFILL_LEDGERS)(default 1000) instead of ledger 1INDEX_FROM_LEDGERenv var for manual override#353 — Composite unique constraint for event deduplication
stellarId @uniquewith@@unique([stellarId, contractId, ledger])composite constraint onIndexedEventpersistEventnow catches PrismaP2002errors and skips duplicates with a debug log instead of crashing20260728120000_add_composite_unique_indexed_event#351 — HMAC-SHA256 webhook payload signing
signPayload(body, secret)to@bettapay/webhook-deliveryproducingt={unix_ts},s={hex_hmac}formatWebhookJobDataaccepts optionalsigningSecretX-BettaPay-Signatureheader when secret is presentsigningSecretfromWebhookSubscriptionto each delivery job#354 — Dead-letter queue for failed webhook deliveries
indexer-webhooks-dlqBullMQ queuefailedevent handler moves jobs to DLQ after all retries exhaustedGET /api/admin/webhooks/dead-letter— lists DLQ entries with paginationPOST /api/admin/webhooks/dead-letter/:id/replay— re-queues a DLQ entry to the main delivery queue and removes it from DLQx-service-tokenauthremoveOnFail: falsefor keeping all failed jobs