Fix /verify and /settle silently 500ing on transient RPC failure - #4
Merged
Merged
Conversation
Root cause of "VAPOR never receives real transactions as a facilitator":
verifyPayment()'s on-chain reads (authorizationState/balanceOf) and its
risk-scan step (scanAddress(), which shares the same RPC client) had no
error handling at all. Any transient RPC trouble — a rate limit, a
timeout, a non-archive node rejecting a historical query, or simply no
RPC URL configured — threw straight out of verifyPayment(), past the
route handler (Express 5 auto-forwards a rejected async handler to
errorMiddleware), and became an unrecorded 500.
Since /settle re-runs verifyPayment() internally before ever broadcasting
(prepareSettlement -> verifyPayment), both endpoints shared this exact
fragility. And because the throw happens before recordVerification/
recordSettlement or verifyOutcomesTotal/settleOutcomesTotal are ever
reached, the failure was invisible in VAPOR's own /stats too — from a
resource server's perspective this is indistinguishable from "the
facilitator is down," so it falls back to whatever facilitator is next
in its own chain, and VAPOR never shows a trace of the attempt.
Fix: wrap the on-chain state read in a try/catch that returns a clean,
recorded `{isValid: false, invalidReason: "temporarily unable to verify
on-chain state (RPC error)"}` instead of throwing, and wrap the risk-scan
step so a scan failure degrades to `{isValid: true, payer}` with no
riskAssessment — which is what verifyPayment's own docstring already said
should happen ("a risk-scan failure still returns isValid: true... VAPOR
informs, it doesn't unilaterally decide") but the code didn't actually
deliver on for an infra failure, only for a completed-but-negative scan.
Adds tests/unit/verification.service.test.ts (new — no prior unit test
covered verifyPayment's own branching at all) covering both degrade paths
plus the existing success/nonce-reuse/insufficient-balance/policy-denial
behavior, so this can't silently regress again.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesVerification resilience
Estimated code review effort: 3 (Moderate) | ~20 minutes ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Root cause
verifyPayment()'s on-chain reads (authorizationState/balanceOf) and its risk-scan step (scanAddress(), which shares the same RPC client) had no error handling at all. Any transient RPC trouble — a rate limit, a timeout, a non-archive node rejecting a historical query, or no RPC URL configured — threw straight out ofverifyPayment(), past the route handler (Express 5 auto-forwards a rejected async handler toerrorMiddleware), and became an unrecorded 500.Since
/settlere-runsverifyPayment()internally before ever broadcasting (prepareSettlement→verifyPayment), both endpoints shared this exact fragility.Because the throw happens before
recordVerification/recordSettlementorverifyOutcomesTotal/settleOutcomesTotalare ever reached, the failure was invisible in VAPOR's own/statstoo — from a resource server's perspective this is indistinguishable from "the facilitator is down," so it silently falls back to whatever facilitator is next in its chain, and VAPOR never shows a trace the attempt happened at all.Fix
getPublicClient+authorizationState/balanceOf) in a try/catch that returns a clean, recorded{isValid: false, invalidReason: "temporarily unable to verify on-chain state (RPC error)"}instead of throwing.{isValid: true, payer}with noriskAssessment— which is whatverifyPayment's own docstring already said should happen ("a risk-scan failure still returns isValid: true... VAPOR informs, it doesn't unilaterally decide") but the code didn't actually deliver on for an infra failure, only for a completed-but-negative scan.Tests
Adds
tests/unit/verification.service.test.ts(new — no prior unit test coveredverifyPayment's own branching at all), covering both new degrade paths plus the existing success/nonce-reuse/insufficient-balance/policy-denial behavior so this can't silently regress again.npx tsc --noEmitclean. New test file: 7/7 passing. Pre-existing failures intests/integration/{app,api-key-scoping,route-scoped-middleware}.test.ts(all/stats-related, DB/Prisma setup issue) confirmed present identically onmainwithout this change — unrelated to this fix.Generated by Claude Code
Summary by CodeRabbit
Bug Fixes
Tests