Repository navigation
fix: hold hardware sends before broadcasting - #1772
ben-kaufman wants to merge 14 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
|
@ben-kaufman #1952 and synonymdev/bitkit-ios#1350 (for #1657 / #1079) make an on-chain send compare the fee of the transaction prepared after the swipe with the fee shown on Confirm. If it is higher, nothing is broadcast and the user re-approves that same transaction. Those PRs leave hardware-wallet sends out because this PR reworks that path. Could this one and its twin be parked for now? Then I would extend #1952 / #1350 to cover hardware sends too. #1771 / #1773 and #1209 / #1211 can stay as they are; whichever lands second rebases. |
|
@ben-kaufman #1770 (keep signed hardware sends on retry) is now merged, like its iOS twin. This draft also keeps a signed hardware send whose broadcast may have gone out, so please reconcile it with what landed on |
Twin: synonymdev/bitkit-ios#1210
This PR keeps a signed hardware-wallet send whose broadcast may have gone out, so the same payment is never signed or sent a second time.
Description
Stops waiting for a hardware broadcast after 60 s without cancelling it. The send then shows on Send Pending with its txid and unknown-outcome copy, and its late answer still lands: an accepted broadcast stays pending until the wallet sees the transaction, and a late answer proving nothing was sent releases the send with a "Payment not sent" toast and closes the sheet. A Shop payment keeps its existing guarded sheet, and its late answer is delivered as before.
Holds a plain hardware send whose broadcast failed after dispatch without proof that nothing was sent, instead of letting it be cancelled and signed again. A first broadcast that core could not decode or connect for, or that the only server to receive it refused, still proves nothing went out and releases it: an Electrum server and its Bitcoin Core node keep nothing they refused (min relay fee, mempool min fee, non-final, txn-mempool-conflict), and a missing coin there is one already spent.
Writes every plain hardware send to its own store before broadcasting, and does not broadcast when that write fails. A held send survives closing the sheet and restarting the app.
Scopes the hold to its payment (wallet, address and amount, address case ignored). Other payments from any wallet can still be signed, and removing a wallet drops its in-memory hold, while the stored hold guards the payment again once the wallet is back.
Adds Broadcast again on Send Pending, which re-writes the hold and broadcasts the identical stored bytes, never signing again. Making the same payment again from any sheet does the same. An accepted broadcast shows an info toast and stays pending.
Releases a held send only on proof it can never confirm, and only while the wallet has not seen its txid:
mandatory-orblock-script-verify-flag-failedand thebad-txnsconsensus checks);Fee, mempool, dust, standardness, conflict and unreadable refusals keep the hold, with a toast saying the payment may still confirm. A late proof that nothing was sent releases a hold only while no other dispatch of the same bytes may have sent it.
Records a held send as sent once the wallet sees its transaction (a replaced transaction, which no longer exists, does not count): the activity and its tags first, then the hold is released, then the success screen shows if its pending screen is open. Stored holds the wallet has seen are also released as watcher activity arrives and at startup, keeping their tags, so a later deliberate repeat of the same payment is a new one. A completion while the sheet is closed is never replayed later as a stale success.
Asks "This payment was already sent on . Send it again?" when the same payment is made while a seen hold has not been released yet. Send again signs a new payment; View payment shows the one already sent.
Fails closed on unreadable hold records. A record that cannot be read is kept as it is, read again by every later read so a newer app version can recover it, and refuses sends from its wallet; a record whose wallet cannot be read, or a file that cannot be read at all, refuses every hardware send. The sign sheet shows what the record still says (amount, address, txid, date), then offers Clear record, or Clear for all wallets when the whole file is concerned, in destructive styling with a second confirmation that says exactly what is deleted (this wallet's unreadable records, those whose wallet cannot be read, or every record of all wallets when the file cannot be read) and that ignores taps for its first second. Nothing is ever reset silently.
Clears held sends with the rest of the wallet on a wipe; a clear that fails fails the wipe.
Out of Scope
Design
N/A — no design available. Send Pending maps to
Send (Edge cases) › Transaction pending Lightningindocs/screens-map.md; the hardware unknown-outcome copy, the Broadcast again button and the unreadable-record dialog reuse existing layouts and have no frame of their own.Preview
N/A
QA Notes
Setup
bitkit-dockerpaired over Bridge as described injourneys/hardware-wallet/README.md, and on-chain funds sent to the hardware wallet with./lsp.Journeys
N/A — not drivable; see Manual Tests.
Manual Tests
Automated Checks
HwSendViewModelTest.kt— a broadcast unanswered for 60 s lets the sheet go to Send Pending, keeps its hold, and completes only once the wallet sees it, recording the activity before the releaseHwSendViewModelTest.kt— a late answer proving nothing was sent releases the send, unless another dispatch of the same bytes may have sent it; a late answer that may have gone out keeps itHwSendViewModelTest.kt— a lost or failed broadcast keeps the signed transaction, and the same payment is broadcast again as the same bytes, never signed again, while other payments and other wallets can still be signedHwSendViewModelTest.kt— Broadcast again re-writes the hold first, runs one dispatch at a time across sheets, stays pending when accepted, keeps the hold on fee, dust or unreadable refusals, and releases only on a consensus refusal or a final spend of a coin by another transactionHwSendViewModelTest.kt— a send is held before its broadcast, an unwritable or unreadable hold store blocks signing and broadcasting, and the unreadable-record dialog clears only on requestHwSendViewModelTest.kt— a held payment the wallet has seen is recorded, then shown as sent or, on Send again, signed anew; a replaced transaction is not seen; removing a wallet forgets its in-memory hold; a completion while no sheet listens is not replayedHwSendViewModelTest.kt— a broadcast that never answers stops blocking Broadcast again after 2 minutes, a refused Broadcast again says why, and a Broadcast again the wallet saw meanwhile completes as sent without a dispatchHwSendViewModelTest.kt— an unreadable record shows what it still says and is cleared only after a second confirmation, for all wallets when the whole file is concernedHwHeldDispatchTrackerTest.kt— one dispatch of the same bytes at a time, expiry counts as possibly sent, and finished dispatches are prunedHwSendViewModelTest.kt— a Shop broadcast unanswered for 60 s keeps its sheet guarded and its late answer still landsHwHeldSendStoreTest.kt— an unreadable file fails every read and write until cleared; an unreadable record is kept through writes, read again later, reports what it still says, and refuses only its wallet, or every wallet when its wallet cannot be readHwWalletRepoTest.kt— a held send is found only for its own payment, unreadable records refuse sends, a seen hold is tagged and released unless its transaction was replaced, a wipe clears held sends or fails, and only a 6-confirmation spend of a coin by another transaction proves a held send can never confirmBroadcastExceptionExtTest.kt— only undecodable bytes or a failed connect prove nothing was sent; only undecodable bytes or a consensus or script refusal in the server's JSON prove a transaction can never confirmSignedTransactionIdTest.kt— reads the coins a signed transaction spendsHwSendViewModelTest.ktandPaykitPaymentProofRepoTest.kt— connectivity failures use core's real Electrum connect prefix, and the view model takes the shared dispatch trackerEvidence
416466178:just compile,just test(4904 tests, 0 failures),just lintand./gradlew compileDevReleaseKotlin compileDevDebugAndroidTestKotlinpassed.Gaps
Models used
Opus 5.5(reasoning:Not exposed)Opus 5.5(reasoning:Not exposed)Opus 5.5(reasoning:Not exposed)Metadata note: the session does not expose a reasoning setting.