Repository navigation
fix: bind send approval to the prepared mining fee - #1952
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[High impact] The reviewed changes appear safe to merge; both previous findings are fixed. SummaryThe PR requires renewed approval when a prepared Bitcoin transaction costs more than the fee first shown.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Prepare transaction] --> B{Fee above approved fee?}
B -->|No| E[Save receipt and broadcast]
B -->|Yes| C[Show actual fee for approval]
C -->|Approved on same node| E
C -->|Cancelled or interrupted| D[Release prepared transaction]
D --> F[Clean up unsent attempt]
F --> G[Close only the original send sheet]
Reviews (2) · Last reviewed commit: "fix: keep a new send open when an ended ..." · Reviewed by Greptile |
|
Triage: this PR goes in the 3.2.0 milestone under #1657. Twin: synonymdev/bitkit-ios#1350. |
talosmachina
left a comment
There was a problem hiding this comment.
1 finding (1 P2). Holds an on-chain send whose prepared mining fee is above the approved one and asks for a fresh swipe and PIN on the actual fee instead of failing it, with the review torn down on node stop, sheet dismissal or a 2 min timeout. Reviewed 0d85e0170, full tier, static.
What I checked, and 5 candidates I ruled out
Read: the diff of LightningRepo.kt (checkApprovedSpend, stopLocked, sendOnChain around the prepare step), OnchainSendCoordinator.kt, LightningService.prepareOnchainSend, AppViewModel.kt (reviewPreparedFee, onConfirmPay, onSwipeToPay, handleSanityChecks, getFeeEstimate, resetSendState), SendSheet.kt, SendConfirmScreen.kt; ldk-node PreparedOnchainSend (broadcast, Drop) at the fork's main.
Not built: per this repo's track rules an auto review does not run the branch's Gradle build; this is reasoned from code and CI.
CI: build-and-test, lint, detekt, compose-ui and build-local green; e2e-tests-local - lightning_security still pending at review time.
Ruled out
- Double release on stop:
stopLockedtakes the reference withgetAndSet(null), and the review path releases only when itscompareAndSet(prepared, null)wins, sodestroyruns once. - Broadcast after release:
broadcastchecksisReleasedunder its mutex beforesubmit, andisUsablealso checks the node and wallet index the receipt was signed with. - An old swipe approving the new fee:
onConfirmPaycompletes the review only whenisSwipedwas set by a swipe made after the review started, andreviewPreparedFeeclearsshouldConfirmPaywhen it opens. - Editing the reviewed send:
changesReviewedSendblocks fee, amount, address and method events, tags are frozen, back closes the sheet, and the finalisSameSendcheck compares amount, address and fee. - Fee-over-threshold warnings skipped: the review drops the two fee warnings from
confirmedWarningsandhandleSanityChecksre-runs onpreparedFeeSats.
Merge confidence: 4/5, one P2 on the cancel path, and the change was not built here.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (no setting is reported by this runner)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
Verdict:
Findings: No new findings reported; code review was skipped. The existing prepared-handle cleanup finding and stale send-sheet cleanup finding were not independently verified or duplicated here.
QA for 0d85e01:
Review and approve a higher mining fee ⏭️ J1.1: not driven while the PR is draft.
The base repository rules require AI reviewers to skip drafts until ready for review.
Cancel a higher-fee payment ⏭️ J1.2: not driven while the PR is draft.
Skipped under the same draft-review rule.
Coverage: full review of 5fa540e9..0d85e01 was requested but not performed. No build, unit tests or device cases ran; all changed runtime behavior remains unverified by this run. Author-reported results were read as context and are not counted as passes.
Twin: synonymdev/bitkit-ios#1350 targets the same fee-approval behavior; implementation parity was not reviewed.
Reviewed by gpt-6.1-sol-high
talosmachina
left a comment
There was a problem hiding this comment.
Re-review of 94675a051 after 0d85e0170. 1 earlier finding: 1 fixed. Greptile's two threads: both fixed. 0 new findings. Full tier on the delta, static.
What I checked
Delta read: git diff 0d85e0170..94675a051, LightningRepo.checkApprovedSpend and stopLocked, PreparedOnchainSend.release/broadcast, AppViewModel.proceedWithPayment through showOnchainPaymentFailure, the three new tests.
Earlier finding (unreleased handle on a cancelled review): fixed in e74236a40. finally now releases unless isKept, and isKept is set only after an approval on a usable handle. A review that throws (back, dismissal, route lost, timeout, Paykit re-check) and the node-stop branch both release now. compareAndSet against stopLocked's getAndSet(null) keeps discard to one call, and an approved handle is still never released before broadcast.
Greptile, old cleanup closing a new sheet: fixed in 94675a051. session is taken in proceedWithPayment before the transition delay, passed through proceedWithOnchainPayment and the failure cleanup, and compared with sendSession after failOnchainPayment and reconcile() return. Both places that open a new send or dismiss the sheet bump sendSession, so a send opened during cleanup is never closed. The node-stop branch is gated the same way now.
Not built: Bitkit Android reviews are reasoned from code and CI here.
CI at 94675a051: build-and-test, build-local, lint and detekt green. The red build is from a superseded run: its BUILD_RESULT and COMPOSE_RESULT are cancelled, so it is not this change. compose-ui and the e2e shards were still pending when I posted.
Merge confidence: 4/5, no open findings. It is not 5 because this is a send-path change that was not built here and the e2e shards had not finished.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (this runner does not report a setting)
There was a problem hiding this comment.
Verdict: ✅ Approve
Findings: No new findings. The prepared-handle release and stale send-sheet cleanup findings are fixed at 94675a0, consistent with the earlier re-review.
QA for 94675a0:
Built from 94675a0. DevDebug on an Android 16 Pixel 10 Pro emulator, staging regtest, FIFO coin selection and PIN required for payments.
Review and approve a higher mining fee ✅ Fee rose from 180 to 277 sats; a fresh swipe and PIN sent it once.
J1.1: The amount stayed at 99,820 sats. Fee, amount and tag edits did not open another screen during review. The sent activity showed the approved 277-sat fee. App logs confirmed one sendOnChain invocation and one created sent activity.
J1-1-2x.2x.mp4
Higher-fee approval and the resulting activity, at 2× speed.
Cancel a higher-fee payment ✅ Back cancelled the 207-sat review without sending.
J1.2: The original fee was 110 sats. Back closed the sheet without a success screen or error toast, the full 99,903-sat balance remained, and a new 5,000-sat send reached Confirm. App logs contained no new sent activity for the cancelled attempt.
J1-2-2x.2x.mp4
Cancellation and a fresh confirmation, at 2× speed.
Report a review interrupted in the background ✅ Node stop cancelled the review; the not-sent toast appeared after unlocking.
J1.3: The fee rose from 180 to 277 sats. Backgrounding stopped the node and cancelled the review, as checked in app logs. Returning showed the PIN lock first; unlocking showed the not-sent toast. The full 149,903-sat balance remained, with no new sent activity.
J1-3-2x.2x.mp4
Background interruption, foreground lock and deferred toast, at 2× speed.
Let a higher-fee review expire ✅ The review ended after two minutes without sending.
J1.4: The fee rose from 246 to 345 sats. Without another approval, the sheet closed and the not-sent toast appeared. App logs measured 120.04 seconds from review to cancellation and contained no new sent activity. The full 199,903-sat balance remained; a fresh 5,000-sat send reached Confirm.
J1-4-2x.2x.mp4
Review expiry and a fresh confirmation, at 2× speed.
Check: Prepared-handle and send-session cleanup ✅ Focused regression tests passed.
./gradlew assembleDevDebug and ./gradlew testDevDebugUnitTest --tests to.bitkit.repositories.LightningRepoTest --tests to.bitkit.viewmodels.AppViewModelSendFlowTest passed at 94675a0. LightningRepoTest.kt verifies immediate release after an unsuccessful review and retention through approved broadcast. AppViewModelSendFlowTest.kt verifies preservation of a newer send sheet while the previous send's reconciliation finishes.
Coverage: delta 0d85e01…94675a0, four files, plus the previously open cleanup findings. Concurrent cleanup and release counts were checked by unit tests, rather than device instrumentation. The unchanged ordinary-send and max-send paths rely on the author's device evidence at f5ae14a13; they were not repeated. No planned case remains unrun.
Twin: synonymdev/bitkit-ios#1350 fix: bind send approval to the prepared mining fee enforces the same approval behavior; iOS retains the candidate across send invocations while Android waits within the original send.
Reviewed by gpt-6.1-sol-high
|
Merged, as it was approved and green. |
Fixes #1657
Twin: synonymdev/bitkit-ios#1350
This PR binds an on-chain send's approval to the mining fee of the transaction that is actually broadcast. Before, Confirm showed an estimate, the transaction was prepared again after the swipe (coin selection could pick different inputs), and it was broadcast without comparing its fee to the one approved.
Description
LightningRepo.sendOnChaintakes an optional reviewer. After preparation and beforeretainPreparedReceipt, a fee at or below the approved one sends as before. A higher fee suspends on the reviewer while the prepared handle is held, then broadcasts that same handle once. Spark funding and Spark exit pass no reviewer and keep their existingOnchainSendChangedError.AppViewModelcaptures the fee shown at the start of the send as the approved fee and, on a higher prepared fee, puts the actual fee and amount on Confirm, re-arms the fee warnings and requires a new swipe plus PIN/biometric. Paykit payer andensurePaymentAllowedare re-checked after approval. Edits and tag changes are blocked during the review.estimateSendAllFee), which is what the send prepares. With an anchor reserve the old fixed-amount estimate was lower than the drain, so the confirmation understated the fee. Max-send fee warnings use the shown fee.wallet__send_fee_changed_not_sent; the review toast reuses the existing fees-changed strings.Out of Scope
HwSendViewModelcomposes again before signing without an in-app fee comparison; the device confirms the signed transaction. Left out because fix: hold hardware sends before broadcasting #1772 is reworking that path.LightningService.stop()callers outsidestopLocked(e.g.resetNetworkGraph) do not release the reviewed handle first; the stale-node check refuses it on approval.Design
N/A — no design available. Reuses the existing Confirm screen and toasts.
Preview
N/A — not run on a device yet.
QA Notes
Setup
devDebug build on an emulator against staging regtest, fresh wallet funded with
./lsp, PIN with "Also require for payments" on, coin selection First-In-First-Out. Confirm preselects inputs and the send reuses them, so an ordinary send does not diverge; the reproduction (inprepared-fee-review.xml) is an amount within about one fee of the whole balance, so preselection fails, plus a deposit confirmed while Confirm is open.Journeys
prepared-fee-review.xml— a higher prepared fee is shown for re-approval, then sent once; Back sends nothing; includes the working reproduction and emulator driving notesManual Tests
N/A
Automated Checks
LightningRepoTest.kt— higher fee is not broadcast before approval and is broadcast once after; cancel, deadline expiry, node stop and a replaced node send nothing and release the attempt; request attempts are released through the existing cleanupAppViewModelSendFlowTest.kt— review shows the actual fee, needs a new swipe, sends once; dismiss, reset, timeout, leaving Confirm and node interruption send nothing with the right toast; max sends show and warn on the drain fee; tags blocked during reviewSparkExitRepoTest.kt,SparkFundingViewModelTest.kt— stubs match the new parameterEvidence
./gradlew testDevDebugUnitTestat f5ae14a: 6163 tests, 0 failures.detekt --rerun-tasksandlintDevDebugpass.dc605f47…462a). PIN → sent 0.8 s.0df897ff…1fea).a55560f8…481d).cc9e2f4e…1a64).sendOnChain, selection or fee calculation after a review started.Review round 1 (fixes at 94675a0):
a review that ends without approval releases the prepared send at oncefailed before the fix.a review ended by its node stopping does not close a send opened during its cleanupfailed before the fix.testDevDebugUnitTest(6167), detekt and lint pass.Gaps
AppViewModelSendFlowTest.kt.SendSheetnull back-stack-entry skip is Compose code with no unit test.Models used
Claude Opus 5.5(reasoning: Not exposed)Claude Fable 5.2(reasoning: Not exposed)Claude Fable 5.2(reasoning: Not exposed)🤖 Generated with Claude Code