Repository navigation
fix(bip70): field-test corrections that missed the #1531 merge — dead rescue + double-pay on retry - #1534
Conversation
…k; stop re-arming on ambiguity Field test on testnet (Pixel 8 emulator, 2026-08-03) proved the IS-lock rescue could never fire, and found a second hazard. Both fixed here. Finding 1 — the signal was wrong. A merchant-broadcast tx WAS on the network and IS-locked (explorer txlock=true), yet the rescue released the reservation and reported failure. Diagnosis from the SDK's own store: the pinned engine advances an externally broadcast wallet-relevant tx context 0 (mempool) -> 2 (inBlock) within ~a minute and NEVER surfaces an InstantSend context or isInstantLocked flag, so a context>=instantSend test can't fire. What IS reliable is the row's EXISTENCE: dash-spv's mempool sync persists an unmined wallet-relevant tx seconds after relay, and — verified against real txids — a built-but-never-sent payment has NO row (a6cc9ead, ed08074b absent) while a server-broadcast one does (2c3be7d8 present). We have not broadcast at that point, so an observed tx was broadcast by the server. The rescue now polls for observation (~20s) and completes as paid. Finding 2 — auto-rebuild after an ambiguous failure is a double-pay hazard. The engine cannot see the mempool spend of the just-released inputs, so the rebuild picked DIFFERENT inputs (ed08074b) for an invoice whose original (2c3be7d8) was already on-chain; a retry tap would have paid the merchant twice. The preview is now re-armed ONLY on a definitive nack; an unresolved transport failure leaves the flow un-armed (canSendPayment false) so no blind retry is possible. Tests: rescue fires on mempool-context observation; no observation -> release; nack -> re-arm; ambiguous -> stays un-armed. Co-Authored-By: Claude Fable 5 <[email protected]>
📝 WalkthroughWalkthroughBIP70 timeout recovery now treats any SDK-observed transaction as proof of server broadcast. Payment preview rebuilding now occurs only after definitive ChangesBIP70 payment flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SendCoinsTaskRunner
participant DashNetwork
participant SDKTransactionStore
SendCoinsTaskRunner->>DashNetwork: await server broadcast observation
DashNetwork->>SDKTransactionStore: transaction becomes observable
SDKTransactionStore-->>SendCoinsTaskRunner: return observed transaction
SendCoinsTaskRunner-->>SendCoinsTaskRunner: complete payment
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
🧪 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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@wallet/src/de/schildbach/wallet/ui/send/PaymentProtocolViewModel.kt`:
- Around line 229-246: Handle non-DirectPayException failures in the payment
failure flow around deferredPaymentRef by setting an explicit unknown-payment
outcome instead of leaving the retry path available. Update
PaymentProtocolFragment’s error confirmation handling to remove the generic
retry action and direct the user to restart or resolve payment status for that
outcome; retain retry only when a new prepared payment preview exists.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e068c08e-9ab1-4650-91ff-07f2232211cb
📒 Files selected for processing (4)
wallet/src/de/schildbach/wallet/payments/SendCoinsTaskRunner.ktwallet/src/de/schildbach/wallet/ui/send/PaymentProtocolViewModel.ktwallet/test/de/schildbach/wallet/payments/SendCoinsTaskRunnerBIP70Test.ktwallet/test/de/schildbach/wallet/ui/send/PaymentProtocolViewModelRaceTest.kt
| // Re-arm ONLY on a definitive refusal (nack): the | ||
| // server said no, nothing is on the network, and a | ||
| // fresh reservation is safe. | ||
| // | ||
| // NEVER re-arm on an AMBIGUOUS failure (transport | ||
| // error that the network-observation rescue could | ||
| // not resolve): the engine cannot see the mempool | ||
| // spend of the released inputs, so a rebuilt retry | ||
| // may select DIFFERENT inputs and pay the merchant | ||
| // twice if the server did broadcast after all. | ||
| // Observed in the field test (2026-08-03): the | ||
| // rebuild produced a different tx (ed08074b) for | ||
| // an invoice whose original (2c3be7d8) was already | ||
| // on-chain. The user must restart the payment. | ||
| // | ||
| // Also never re-arm after Bip70AckedDisplayException | ||
| // — the merchant holds an ACKED tx. | ||
| if (ex is org.dash.wallet.common.services.DirectPayException) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Do not expose the generic retry action after an ambiguous failure.
For a non-DirectPayException, this branch leaves deferredPaymentRef null. PaymentProtocolFragment.kt Lines 187-189 then maps the error confirmation action to sendPayment(). The next confirmation reaches the no-prepared-payment branch at Lines 251-255 and fails again.
Add an explicit unknown-payment outcome. For that outcome, remove the retry action and direct the user to restart or resolve payment status. Keep retry only when a new preview exists.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@wallet/src/de/schildbach/wallet/ui/send/PaymentProtocolViewModel.kt` around
lines 229 - 246, Handle non-DirectPayException failures in the payment failure
flow around deferredPaymentRef by setting an explicit unknown-payment outcome
instead of leaving the retry path available. Update PaymentProtocolFragment’s
error confirmation handling to remove the generic retry action and direct the
user to restart or resolve payment status for that outcome; retain retry only
when a new prepared payment preview exists.
Follow-up to #1531. This is the field-test correction commit that missed that merge by five minutes — #1531 was merged at head
437cf5ffa(17:35 EDT); this fix was pushed at 17:40. It cherry-picks cleanly onto the merged line.The on-device test (Pixel 8, testnet, real broadcasts) found two defects in what was merged. One is a funds hazard.
1. Double-pay on retry after an ambiguous failure 🔴
PaymentProtocolViewModelre-arms the preview after any non-acked failure, including an ambiguous transport failure. The SDK engine cannot see the mempool spend of the just-released inputs, so the rebuild selects different inputs — a second, independently-valid payment for the same invoice.Reproduced on testnet, not theorised:
2c3be7d8…— broadcast by the merchant, later mined;ed08074b…— a different tx. A retry tap would have paid the merchant twice.2c3be7d8mined produceded08074bagain, i.e. that rebuild really was a distinct payment, not a re-serialisation.Fix: re-arm only on a definitive nack (server refused; nothing on the network). An unresolved transport failure leaves the flow un-armed (
canSendPayment == false) so no blind retry is possible; the user restarts the payment.2. The timeout rescue as merged can never fire
It keys on
TransactionContext >= instantSend. Measured on the pinned engine: an externally broadcast wallet-relevant tx goescontext 0 (mempool) → 2 (inBlock)and never surfaces an InstantSend context orisInstantLocked, even when the network has IS-locked it (txlock: trueon the explorer). Net effect as merged: the rescue never rescues and adds ~12 s to every failure.Fix: key on the row's existence, which is safe here because the engine only records transactions it has observed and a built-but-unbroadcast payment has no row — verified against real txids (
a6cc9ead,ed08074babsent while never sent; server-broadcast2c3be7d8present). We have not broadcast at that point in the flow, so an observed tx was broadcast by the BIP70 server. Window widened to ~20 s.Verified working after the fix: server broadcast the payment then returned HTTP 500 → engine observed it at context 0 in 1.3 s →
completing as paid→ reservation kept → bridged; txed08074b…on-chain withtxlock: true.Tests
Four arms in
SendCoinsTaskRunnerBIP70Test/PaymentProtocolViewModelRaceTest: observed → paid; never observed → release; nack → re-arm; ambiguous → stays un-armed.Verification status — please read
These suites are green on the pre-merge base (int11). I could not compile or run them against this branch's merged base locally: it pins
0.1.0-v41int13-SNAPSHOT, which is not in local Maven, and the pin cannot be downgraded — the merged shielded-invite path requires int13's typedShieldedInviteAlreadyClaimed. The int13 source is not pushed to any branch I can reach on dashpay/bfoss765/HashEngineering, so I can't build it either. Happy to re-run everything the moment the int13 AAR (or its source branch) is available — flagging it rather than implying verification I don't have.🤖 Generated with Claude Code
Summary by CodeRabbit