Repository navigation
fix: hold a redo spark exit rebuild over a waiting leaf - #1892
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: 4125b72d12
ℹ️ 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 affects rebuild timing in Spark emergency exits, not the wider transaction flow. The PR appears safe to merge, with a non-blocking request to test the remaining hold branches. Findings
SummaryHolds a
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Build Redo replacement] --> B{Leaves out a waiting leaf from the old recovery?}
B -->|No| E[Adopt replacement]
B -->|Yes| C{Readable tip and six blocks elapsed?}
C -->|Yes| E
C -->|No| D[Save hold and retry later]
D --> A
Reviews (1) · Last reviewed commit: "fix: hold a redo spark exit rebuild over..." · Reviewed by Greptile |
|
Ran the Spark exit unit tests locally on 4125b72: |
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.
worth doing, does not block
- A held Redo rebuild in a funded NeedsFunding phase rebuilds every tick (app/src/main/java/to/bitkit/repositories/SparkExitDriver.kt:249). After its top-up is adopted, a held Redo rebuild runs a full prepare and recover on every tick for the whole hold, not once every
REBUILD_INTERVAL. The PR says the hold "tries again at the usual rebuild pace". That is true on theRunning+isRebuildingpath, whichisRebuildDuegates intick, but not here. Path, traced in the code: 1. A Redo check callsrebuild. Its build throwsInsufficientCpfpFunds, soaskForFundingleaves the record inNeedsFundingwithisRebuildingandisRedoRebuildset. 2. The funding confirms.buildOnceFundedadopts it throughadoptFundingand falls toelse -> build(funded, sdk)(SparkExitDriver.kt:249). The prepare skips leaf-2 asUnverified, soholdingRedoreturns the record still inNeedsFunding, withlastBuildAt = now. 3. On the next tick,fundingTopUptook UTXOs totalling at least the shortfall, sofundingShortfallSatsis now null andfunded = record. That record is neitherisFundingWaitingLeavesnorisUnverifiedAsk, so it reacheselse -> build(funded, sdk)again. That branch has noisRebuildDuecheck, so thelastBuildAtthe hold set is never read. With the 60 s foreground tick inSparkExitRepo, that is about 60 prepare, export-state-import, recover and CPFP-signing rounds over the 6 blocks. The firstbuildOnceFundedbranch (unfunded Redo) is paced byisRebuildDue, so only the funded branch is affected. Before this PR this path adopted on its first funded build, so it never looped. Nothing broadcasts during the loop, and the hold still ends on height, so the cost is SDK and chain load, not a wrong exit. That is why this is not blocking. Confirmed by reading the code andSparkExitMath.fundingTopUp. I wrote a scratch test for this path in a temp copy, but Gradle could not resolve the GitHub Packages dependencies offline (ldk-node, bitkit-core, breez 0.28.2), so it did not run. A possible fix: inbuildOnceFunded, returnfunded(which keeps the adopted funding) whenfunded.isRebuilding && funded.redoHeldSince != null && !isRebuildDue(funded), before theelsebranch. Add a test that ticks a held funded Redo twice insideREBUILD_INTERVALand asserts onerecoverRequestsentry. No test covers the hold on this path, or on the cooperative-only branch at line 346. - Funded Redo holds bypass the rebuild interval (app/src/main/java/to/bitkit/repositories/SparkExitDriver.kt:382)
talosmachina
left a comment
There was a problem hiding this comment.
No findings. A Redo rebuild that drops a waiting leaf the diverged generation still recovers is held (not adopted) for REDO_HOLD_BLOCKS from the first such build, at the rebuild pace. Reviewed 4125b72, full tier, static: Bitkit Android PRs are not built here, so this is reasoned from the code and CI.
What I checked, and 4 candidates I ruled out
Read: SparkExitDriver.build end to end (both adopt sites, the unexitable-leaf and lost-leaf exits), holdingRedo, SparkExitRecord.adopt, the JSON read/write of redoHeldSince, the new driver/repo/record tests
Twin: matches synonymdev/bitkit-ios#1309 (same 6-block window, same guard on the diverged generation's leaves, same uncounted hold without a tip)
Ruled out
- Stale
redoHeldSinceleaking into a later Redo: every adopt clears it, and the stall, unverified and fee-bump rebuilds that resetisRedoRebuildonly start from arunningcheck, which does not run whileisRebuilding, so a hold is always ended by an adopt. - Hold blocking a valid generation:
keepsValidGenerationOveris checked first and is false for a Redo rebuild, so the hold only ever replaces a generation that is never sent again. - Tight rebuild loop while held: the hold stamps
lastBuildAt, soisRebuildDuepaces it like any rebuild. - Reorg below
since:height >= sincekeeps the hold rather than underflowing; it ends once the chain passessince + 6again.
CI: lint, detekt, build-local green; build-and-test, compose UI and e2e still running at review time.
Merge confidence: 4/5, the unit tests covering the hold were still running in CI and the change was not built here.
|
f742ad0 applies the fixes from @coreyphillips's review of the iOS twin (synonymdev/bitkit-ios#1309), whose two bugs exist here too:
Two new tests in Re-review is needed only because of this push: 4125b72...f742ad0 |
jvsena42
left a comment
There was a problem hiding this comment.
No findings.
- The hold can't stall an exit on mainnet. The tip read and the SDK share one backend (
Env.sparkChainServiceUrl(BITCOIN)is the onlyEsploraSparkExitChainread host). So a hold with no readable tip needs that host to serve the SDK's prepare/recover while failing/blocks/tip/heighton every due build. A transient tip failure only moves the start or the expiry to the next build. - A held record can't be fee-bumped.
payHigherFeeLockedrefuses whileisRebuilding, soisRedoRebuildisn't cleared mid-hold and no diverged generation re-enters the send path. f742ad0e5: the hold moves toRunningonly whenfundingShortfallSats == null. Both funding branches are paced byisRebuildDue, which closes coreyphillips's every-tick note. The hold check runs beforeisWaiting, so an empty prepare doesn't start the retry clock.- No new send path: held builds sign CPFP transactions that are discarded. Strikes are computed only in
adopt.redoHeldSincepersists, so process death resumes the hold. Lost-leaf detection still runs before the hold.
The iOS twin synonymdev/bitkit-ios#1309 uses the same predicate.
Device gate: no device check needed: it needs a lost CPFP race plus a skipped leaf, which no journey can force; SparkExitDriverTest is the evidence. perf: up to about 6 extra prepare/recover rounds per Redo episode at the 10-minute pace.
Reviewer model: Claude Fable 5.2 (claude-fable-5-2), Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: not exposed
|
6e1c7a2 adds the two cases Greptile asked for: a Redo hold while the tip can't be read, and a hold over a build of only failed cooperative leaves. Test-only. Re-review is needed only because of this push: f742ad0...6e1c7a2 |
|
@coreyphillips both points in #1892 (review) are addressed:
|
coreyphillips
left a comment
There was a problem hiding this comment.
Rechecked after 2 new commits (f742ad0, 6e1c7a2). Nothing blocking remains.
addressed
- A held Redo rebuild in a funded NeedsFunding phase rebuilds every tick (app/src/main/java/to/bitkit/repositories/SparkExitDriver.kt:249). Fixed:
holdingRedonow setsphase = Runningwhenrecord.fundingShortfallSats == null(SparkExitDriver.kt:385-386). AfteradoptFunding,fundingTopUponly returns UTXOs totalling at least the shortfall, so the shortfall is null. The next tick therefore takes theRunning if record.isRebuildingbranch, which returns early unlessisRebuildDue(line 169, lines 1221-1224). It no longer reacheselse -> build(funded, sdk)at line 249. I confirmed this by reading the code.a redo hold after a funded top-up runs at the rebuild paceassertsPhase.Runningand no second recover inside the interval. Both assertions fail without the change. Gradle could not resolve bitkit-core or breez 0.28.2 offline, so I did not run it. - Funded Redo holds bypass the rebuild interval (app/src/main/java/to/bitkit/repositories/SparkExitDriver.kt:382). Fixed: This is the same path as point 1. The hold no longer leaves a covered record in
NeedsFunding(SparkExitDriver.kt:385). That means the unconditionalbuild(funded, sdk)at line 249 is reached only on the tick the top-up is adopted. Later ticks are gated byisRebuildDueat line 169. I traced it throughfundingTopUpandfundingShortfallSats. The new driver test ticks twice at the samenowand checks thatrecoverRequestsdoes not grow.
new since the last review
worth doing, does not block
- Unfunded Redo hold keeps a stale fee ask on screen though the build was paid (app/src/main/java/to/bitkit/repositories/SparkExitDriver.kt:385)
|
@jvsena42 thanks. Your approval is on f742ad0; this repo needs one on the last push, so I re-requested you on 6e1c7a2. That commit only adds the two tests Greptile asked for: f742ad0...6e1c7a2 |
|
Merging: CI is green and @coreyphillips and @jvsena42 approved, with no open threads. The deferred point about the stale fee ask on an unfunded Redo hold is tracked in #1894. |
Twin: iOS PR to follow on
feat/breez-spark-lightning.Description
check_recover_fundsasRedo, notValid. The driver never sends a diverged generation again, and its Redo rebuild skipped the hold that keeps a leaf in the exit when a build leaves it waiting. So when one failed chain read made the rebuild's prepare skip a leaf asUnverified, that leaf's steps went unsent until the rest of the exit was done, which can be weeks. Before 0.28.2 the same race went through the lost-race fallback rebuild, which kept that hold.Validstays as it is.Design
N/A — no UI changes.
Preview
N/A
QA Notes
Automated Checks
SparkExitDriverTest:a redo rebuild beside a waiting leaf holds until the leaf reads: a Redo rebuild whose prepare skips leaf-2 asUnverifiedadopts nothing and sends nothing, then adopts both leaves once leaf-2 reads.a redo rebuild beside a leaf that stays unread adopts after the hold: the hold keeps its start height for 6 blocks, then the rebuild is adopted with leaf-2 waiting.a redo hold after a funded top-up runs at the rebuild pace: a hold whose top-up was adopted leaves the funding phase and doesn't build again before the rebuild interval.an empty prepare during a redo hold leaves the retry clock alone: a prepare that skips every leaf during the hold sets no retry clock; it starts once the hold ends.a redo hold goes on uncounted while the tip cannot be read: a missing tip neither starts nor ends the hold.a redo rebuild of only failed cooperative leaves beside a waiting leaf holds too: the failed-only build is held like any other.a redo after a refund sent spent strikes it once and not again once its rebuild is accepted: a Redo over a refund logged as input-spent strikes the refund once; after the rebuild's refund is accepted, a second Redo does not strike it again. Asked for by @jvsena42 on chore: bump breez sdk to 0.28.2 bitkit-ios#1306 (review).SparkExitRepoTest:a start never lowers a funding index a scan moved past its quote, promised to @coreyphillips on fix: find a restored wallet's exit funding before the next quote #1887.SparkExitRecordTest: the round trip and the defaults now includeredoHeldSince.