Skip to content

fix(bip70): field-test corrections that missed the #1531 merge — dead rescue + double-pay on retry - #1534

Merged
bfoss765 merged 1 commit into
feat/kotlin-sdk-phase1from
fix/bip70-rescue-followup
Aug 5, 2026
Merged

bfoss765 merged 1 commit into
feat/kotlin-sdk-phase1from
fix/bip70-rescue-followup

Conversation

@HashEngineering

@HashEngineering HashEngineering commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

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 🔴

PaymentProtocolViewModel re-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:

  • original 2c3be7d8… — broadcast by the merchant, later mined;
  • post-failure rebuild ed08074b… — a different tx. A retry tap would have paid the merchant twice.
  • Independently confirmed: a fresh preview build for the same invoice after 2c3be7d8 mined produced ed08074b again, 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 goes context 0 (mempool) → 2 (inBlock) and never surfaces an InstantSend context or isInstantLocked, even when the network has IS-locked it (txlock: true on 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, ed08074b absent while never sent; server-broadcast 2c3be7d8 present). 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; tx ed08074b… on-chain with txlock: 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 typed ShieldedInviteAlreadyClaimed. 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

  • Bug Fixes
    • Improved payment recovery after network timeouts by detecting transactions observed in the mempool or wallet engine.
    • Prevented ambiguous transport failures from automatically rebuilding or retrying payments.
    • Limited automatic retry preparation to definitive payment rejections, reducing duplicate payment attempts.

…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]>
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

BIP70 timeout recovery now treats any SDK-observed transaction as proof of server broadcast. Payment preview rebuilding now occurs only after definitive DirectPayException failures. Tests cover mempool observation and ambiguous transport failures.

Changes

BIP70 payment flow

Layer / File(s) Summary
Server broadcast observation and recovery
wallet/src/de/schildbach/wallet/payments/SendCoinsTaskRunner.kt, wallet/test/de/schildbach/wallet/payments/SendCoinsTaskRunnerBIP70Test.kt
Recovery polls for approximately 20 seconds and completes when the SDK observes the transaction, including mempool observation.
Definitive failure retry gating
wallet/src/de/schildbach/wallet/ui/send/PaymentProtocolViewModel.kt, wallet/test/de/schildbach/wallet/ui/send/PaymentProtocolViewModelRaceTest.kt
Preview rebuilding remains enabled for DirectPayException refusals and disabled for ambiguous transport failures. Tests verify the send guard and reservation behavior.

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
Loading

Possibly related PRs

  • dashpay/dash-wallet#1531: Introduced the related BIP70 deferred-payment recovery and retry behavior in the same implementation and test areas.

Suggested reviewers: bfoss765

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main changes: BIP70 rescue recovery and prevention of double payment during retry.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bip70-rescue-followup

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@HashEngineering

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between c374245 and f0c40e9.

📒 Files selected for processing (4)
  • wallet/src/de/schildbach/wallet/payments/SendCoinsTaskRunner.kt
  • wallet/src/de/schildbach/wallet/ui/send/PaymentProtocolViewModel.kt
  • wallet/test/de/schildbach/wallet/payments/SendCoinsTaskRunnerBIP70Test.kt
  • wallet/test/de/schildbach/wallet/ui/send/PaymentProtocolViewModelRaceTest.kt

Comment on lines +229 to +246
// 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

@bfoss765
bfoss765 merged commit 1eaa1f0 into feat/kotlin-sdk-phase1 Aug 5, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants