Repository navigation
fix: wait a check before an unverified spark exit rebuild - #1886
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d32ef9e9cd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryThe driver now waits one check before rebuilding over a newly
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Check returns an unread unilateral step] --> B{Same transaction unread before this check?}
B -->|No| C[Save checked recovery and wait]
C --> A
B -->|Yes| D{No ready unilateral steps and no rebuild this block?}
D -->|Yes| E[Try rebuilding]
D -->|No| C
Reviews (1) · Last reviewed commit: "fix: wait a check before rebuilding over..." · Reviewed by Greptile |
|
Triage: milestone 3.2.0. This PR fixes the Spark emergency exit (#1782), which is 3.2.0 work, and closes no issue, so it carries the milestone itself. |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Makes the Spark exit driver rebuild over an unverified unilateral step only when that same txid was already Unverified in the stored recovery before this check, so one failed outspend read waits a check instead of rebuilding over a step that may be in flight. Reviewed d32ef9e, full tier, static.
What I checked, and 5 candidates I ruled out
Read in full: SparkExitDriver.kt at the head (check, driveWhileFunding, broadcastReady, buildFeeBump, withConfirmations, needsUnverifiedRebuild), and the new test in SparkExitDriverTest.kt.
Build: not built here. A Bitkit Android review never runs the branch's Gradle code on this box, so this is reasoned from the code and from CI.
CI: build-and-test, lint, build-local and ui-tests were still pending when I posted.
Ruled out
storedis not the previous check's result:checkcopieschecked.recoveryinto the record it returns, so the next tick'sstoredcarries the statuses of the last check. When a check throws,broadcastWithoutSdkleavesrecoveryalone, so the comparison goes back to the last successful check, which is still "before this one".- A step one read turned unverified gets sent anyway:
broadcastReadyonly sendsReadysteps or cooperative unverified ones, so a unilateral step waits, as the PR says. The new test checks this (chain.broadcasts.none { it.txid == "n2" }). - A fresh build whose steps come back unverified now waits two blocks: no. The adopted build's recovery is stored, so the next check that still can't read the step finds it in
unreadBeforeand rebuilds then. TheunverifiedRebuiltAtHeightonce-per-block guard is unchanged. - Reads that flip back and forth (Unverified, Ready, Unverified) never rebuild: on the
Readychecks the step is sent, which is what a rebuild is for, so nothing gets stuck. - The fee-bump and funding paths skip the new guard:
buildFeeBumpsetsunverifiedRebuiltAtHeightitself and runs before this guard.driveWhileFundingnever callsneedsUnverifiedRebuild, and itsisAskOverstill clears the ask on a clean check.
Codex's KDoc comment is a style point that has already been raised, so I left it out.
Merge confidence: 4/5. Files read whole and the change is covered by a step one failed read turns unverified waits for the next check instead of rebuilding, but I did not build it here and CI was still pending.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the run metadata available to this reviewer does not expose a setting)
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
coreyphillips
left a comment
There was a problem hiding this comment.
Two independent reviews, nothing blocking a merge.
|
@coreyphillips Your recheck on the iOS twin (synonymdev/bitkit-ios#1306) found that the guard still rebuilt over a step one failed read had just turned unverified, when another leaf's step was already unread. Fixed here the same way in 6b436dc: the rebuild needs every unverified unilateral step to have been unverified before this check. New test: Because the push was needed anyway, it also moves the private function's KDoc into a comment at the call site, which was Codex's point. Re-review is needed only because of this push: d32ef9e...6b436dc |
jvsena42
left a comment
There was a problem hiding this comment.
No findings. In breez 0.28.2, status_after_check marks a step Unverified only when an outspend read fails that check, and a clean check clears it (unilateral_exit.rs:1077-1097); a third-party spend or reorg arrives as Redo, which this doesn't touch. So:
- The hold can't stall an exit for good. A step that stays unread is in
unreadBeforeon the next tick and rebuilds one tick later, and a step that flaps is sent on its clean tick. - The hold returns before
unverifiedRebuiltAtHeightis set, so no block is lost. Unverifiedalready wasn't broadcast bybroadcastReady, so timelock exposure is unchanged.- Fewer rebuilds means fewer savings funding asks.
The iOS twin synonymdev/bitkit-ios#1306 (8150b1480, bfa6268a2) uses the same predicate and ships the same two tests.
Device gate: no device check needed: no UI change, and it only matters with a failing chain read during an exit. perf: at most one extra tick before an unverified rebuild.
Reviewer model: Claude Fable 5.2 (claude-fable-5-2), Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: not exposed
coreyphillips
left a comment
There was a problem hiding this comment.
Rechecked after 1 new commit (6b436dc). Nothing blocking remains.
new since the last review
worth doing, does not block
- A step that stays unread can now wait several blocks for its rebuild (app/src/main/java/to/bitkit/repositories/SparkExitDriver.kt:808-810)
|
@coreyphillips Your recheck on the iOS twin (synonymdev/bitkit-ios#1306) found that a funded unverified ask could still rebuild over a step a clean check had made ready and sent. The Android resume in Re-review is needed only because of this push: 6b436dc...f204417 |
coreyphillips
left a comment
There was a problem hiding this comment.
Rechecked after 2 new commits (f204417, 26aa61c). One point still blocks a merge.
addressed
- A step that stays unread can now wait several blocks for its rebuild (app/src/main/java/to/bitkit/repositories/SparkExitDriver.kt:808-810). Fixed: The point asked that the call-site comment and the description be corrected if the delay is acceptable.
SparkExitDriver.kt:548-549now says a step that stays unread is rebuilt at the first check, at most once a block, where no other step just turned unverified. The description now says the same and adds that this can take a few checks while other leaves' reads keep failing.needsUnverifiedRebuild(SparkExitDriver.kt:812-823) is unchanged, so the new wording matches the code.
new since the last review
needs changing before merge
- Funded unverified ask still rebuilds over a step sent on an earlier clean check (app/src/main/java/to/bitkit/repositories/SparkExitDriver.kt:207-217)
jvsena42
left a comment
There was a problem hiding this comment.
Re-approving at 26aa61c77. f20441738 ends a funded unverified ask without rebuilding once its unilateral steps read again (any Ready, or none Unverified). A rebuild then would conflict with the step about to be sent at the same fee. The funding already adopted stays in the record for a later rebuild or the leftover sweep, so the savings payment the user approved is neither repeated nor lost. The new SparkExitDriverTest case covers it, and iOS synonymdev/bitkit-ios#1306 (0869a9e34) uses the same predicate.
|
Pushed 45bd734: the funded unverified ask's resume now holds over a step this tick's check just turned unverified, using the recovery from before the check, as the check path's rebuild does. A step sent on an earlier clean check is no longer rebuilt over when the payment confirms on a tick whose read fails. New Re-review is needed only because of this push: 26aa61c...45bd734 |
Fixed in 45bd734; the push asks for a re-review.
coreyphillips
left a comment
There was a problem hiding this comment.
Rechecked after 1 new commit (45bd734). Nothing blocking remains.
addressed
- Funded unverified ask still rebuilds over a step sent on an earlier clean check (app/src/main/java/to/bitkit/repositories/SparkExitDriver.kt:207-217). Fixed:
ticknow passesstart.recoverytobuildOnceFunded(SparkExitDriver.kt:157), and the resume returns early when any unilateralUnverifiedstep was notUnverifiedin that recovery (SparkExitDriver.kt:224-230), matchingneedsUnverifiedRebuild. I traced your sequence through the new test at SparkExitDriverTest.kt:603-642. On the tick at 1_001 the funding is adopted, butunreadBeforetaken from thereadyrecovery is empty while n2 isUnverified, so it returnsfundedandrecoveris never called. I could not run the test because the Breez bindings and bitkit-core are not in the local Gradle cache.
new since the last review
worth doing, does not block
- Funded resume still rebuilds over a just-unread step when the next check fails (app/src/main/java/to/bitkit/repositories/SparkExitDriver.kt:224-233)
|
Pushed fe43ec3, test only: the new hold test now asserts the payment was adopted on the tick that holds the rebuild, so it cannot pass without reaching the hold. Same assertion as the iOS twin, synonymdev/bitkit-ios#1306 (31f884871), from @coreyphillips's nit there. Re-review is needed only because of this push: 45bd734...fe43ec3 |
jvsena42
left a comment
There was a problem hiding this comment.
Re-approving at 45bd7340c. buildOnceFunded now takes the tick-start recovery as stored. A funded unverified resume holds while any unilateral step was turned unverified by this check rather than an earlier one, the same rule as the check's own rebuild. A step that stays unread is in unreadBefore on the next tick and resumes then, so it can't stall. The hold returns before unverifiedRebuiltAtHeight is set, so no block is lost, and nothing new is paid. iOS synonymdev/bitkit-ios#1306 (d5940383c) does the same with before.recovery.
|
Pushed 60d49ce: the funded unverified ask's resume now skips a tick whose check failed, so it needs two checks that read a step unread before it rebuilds, as the check path does. The hold test now covers a failed check after the hold. Re-review is needed only because of this push: fe43ec3...60d49ce |
coreyphillips
left a comment
There was a problem hiding this comment.
Rechecked after 2 new commits (fe43ec3, 60d49ce). Nothing blocking remains.
addressed
- Funded resume still rebuilds over a just-unread step when the next check fails (app/src/main/java/to/bitkit/repositories/SparkExitDriver.kt:224-233). Fixed:
driveWhileFundingnow returns null when the check throws or there is no SDK (SparkExitDriver.kt:497-503).tickthen runsbroadcastWithoutSdkon the same record as before and setsisChecked = false(:146-149).buildOnceFundedreturns the held record before theunreadBeforeand height guards (:229), so a failed check never rebuilds, as on the check path. I traced your tail at SparkExitDriverTest.kt:644-648: the fake's emptychecksdeque throws onremoveFirst, andunverifiedRebuiltAtHeightis still 1_000 at tip 1_001. Without :229buildwould reachrecover, so the assertion separates the two. The!isDrivingWhileFundingpath keepsisChecked = truebut cannot reach the unverified-ask branch, because that branch needs NeedsFunding with a recovery and no rebuild. I could not run the test because breez_sdk_spark and bitkit-core are not in the local Gradle cache.
the reviewers disagree, your call
- QA Notes leave out the hold test that covers the last two claims (app/src/test/java/to/bitkit/repositories/SparkExitDriverTest.kt:604)
jvsena42
left a comment
There was a problem hiding this comment.
Re-approving at 60d49ce1f. driveWhileFunding now returns null when no check ran (no SDK, or the check failed), and the caller still falls back to broadcastWithoutSdk, so the send path is unchanged. A funded unverified resume no longer rebuilds on a tick whose check failed, matching the check path. fe43ec300 adds the assertion that the held resume adopted its payment.
|
Merging into master: @coreyphillips and @jvsena42 approved 60d49ce, every required check passes, and no review thread is open. |
|
QA for 2f18eb69b on master, with Breez SDK 0.28.2 from synonymdev/bitkit-android#1881 chore: bump breez sdk to 0.28.2:
The start, from the Spark screen to Paid from savings, and the exit after its funding confirmed:
|
|
Emergency exit result, 2f18eb69b with Breez SDK 0.28.2: this finishes the exit started in my comment above.
The recording shows Exit complete with both transaction IDs, the Spark screen, and Savings after the exit. p32x.mp4 |
Twin: synonymdev/bitkit-ios#1306
Description
check_recover_fundsmarks a stepUnverifiedwhen one outspend query for its inputs fails, and clears it on the next clean check. The driver rebuilt over any unverified unilateral step while nothing else was ready to send. So one rate-limited chain read could rebuild over a step already broadcast, with the same funding. If that build hitInsufficientCpfpFunds, the exit also asked the user for fee funding until a clean check withdrew the ask.Unverifiedin the stored recovery before the current check. A step one failed read turns unverified holds the rebuild until the next check, the same as a step that is ready to send. A step that stays unread rebuilds at the first check where no other step just turned unverified, once a block at most. When other leaves' reads keep failing, that can take a few checks.Design
N/A — no UI changes.
Preview
N/A
QA Notes
Automated Checks
SparkExitDriverTest:a step one failed read turns unverified waits for the next check instead of rebuilding: a ready step that one check turns unverified is neither rebuilt over nor sent, and the exit rebuilds only once the next check still can't read it.a step one failed read turns unverified holds the rebuild over another leaf's unread step.a funded unverified ask whose step reads again ends without a rebuild.a funded unverified ask holds its rebuild over a step sent on an earlier clean check: a step sent on a clean check while the payment was unconfirmed is not rebuilt over when the payment is adopted on a tick whose check can't read it, nor on a next tick whose check fails.