feat: blockchain reorganization detection for transaction confirmations (#514)#537
Conversation
|
@primexk5 is attempting to deploy a commit to the smartdevs17's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@primexk5 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! 🚀 |
|
Possible reasons:
🤖 Drips Wave Merge Agent |
|
Possible reasons:
🤖 Drips Wave Merge Agent |
|
❌ This PR has merge conflicts with Hi @primexk5, please resolve the conflicts so this can be merged. 🤖 Drips Wave Merge Agent |
e4ae39f to
e80f841
Compare
|
Hey @Smartdevs17 , the merge conflict has been resolved. Here's a summary of what was done: Root cause: The branch was based on an older ancestor of Fixes applied:
The PR now has a single clean commit sitting directly on top of |
|
Merge conflicts |
…ns (Smartdevs17#514) Implements the full reorg detection pipeline per issue Smartdevs17#514: - **ConfirmationTracker** (`confirmation-tracker.ts`): in-memory per-network tracking with configurable thresholds (Ethereum=12, Polygon=64, Stellar=1, all env-overridable). Detects finality and exposes findAffected() for orphaned block ranges. - **ReorgDetector** (`reorg-detector.ts`): polls EVM chains via ethers.js JsonRpcProvider and Stellar via Horizon REST API. Detects parentHash mismatches and same-height sibling blocks, walks back to common ancestor, atomically persists ReorgEvent + TransactionReorg rows via prisma.$transaction, marks affected payments as pending_review, and enqueues BullMQ re-verification jobs with 5× exponential backoff. Fires webhook alerts when reorg depth exceeds safety threshold. - **Reorg routes** (`routes/reorg.ts`): GET /api/v1/chain/reorgs, /dashboard, /history, /:id, POST /simulate — all protected by verifyInternalSignature HMAC middleware. - **Prisma schema**: adds ReorgEvent and TransactionReorg models plus pending_review payment status. - **20 unit tests** covering ConfirmationTracker, simulateReorg (including rolled_back status), and pollChain (same-height reorg, idempotent start, idle-poll no-op, parentHash mismatch). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
e80f841 to
38be019
Compare
|
@Smartdevs17 merge conflicts resolved |
|
Merged please kindly leave a review |
What this PR does
ConfirmationTracker— per-network in-memory tracking with configurable safety thresholds (Ethereum=12, Polygon=64, Stellar=1, env-overridable viaCONFIRMATION_THRESHOLD_*)ReorgDetector— polls EVM chains via ethers.jsJsonRpcProviderand Stellar via Horizon REST API; detectsparentHashmismatches and same-height sibling blocks; atomically persistsReorgEvent+TransactionReorgrows viaprisma.$transaction; marks affected paymentspending_review; enqueues BullMQ re-verification jobs (5× exponential backoff); fires webhook alerts when depth exceeds safety thresholdGET /api/v1/chain/reorgs,/dashboard,/history,/:id,POST /simulate) all protected byverifyInternalSignatureHMAC middlewareReorgEventandTransactionReorgPrisma models +pending_reviewpayment statusChanges
backend/prisma/schema.prisma— newReorgEvent,TransactionReorgmodels;pending_reviewpayment statusbackend/src/services/chain/confirmation-tracker.ts— new filebackend/src/services/chain/reorg-detector.ts— new filebackend/src/routes/reorg.ts— new file (5 routes)backend/src/index.ts— wired up router and detector lifecyclebackend/src/services/chain/__tests__/reorg-detector.test.ts— 20 unit testsWhy
Resolves all acceptance criteria from issue #514: reorg detection service, confirmation tracker, Prisma models, BullMQ queue for re-verification, dashboard routes, and integration tests.
How to test
For manual testing, POST to
/api/v1/chain/reorgs/simulatewith a validx-internal-signatureheader in dev mode.Notes
prisma.$transaction()ensures atomic writes across ReorgEvent + TransactionReorg + Paymentstart()is idempotent — safe to call multiple timesCloses #514