Repository navigation
fix: find a restored wallet's exit funding before the next quote - #1887
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. |
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryThe PR checks restored exit funding before choosing the next funding address.
The added tests cover restored-index recovery, scan failure, cancelled-address promotion, and scans starting at 1,000. Tests were inspected, not run. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Request exit quote] --> B{Recovery pending?}
B -->|No| E[Choose next funding index]
B -->|Yes| C[Scan funding addresses]
C -->|Read or save fails| D[Fail quote and keep recovery pending]
C -->|Success| F[Keep found coins and save higher index]
F --> E
E --> G[Start exit without lowering saved index]
Reviews (1) · Last reviewed commit: "fix: find a restored wallet's exit fundi..." · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. While a restore is pending, an exit quote now runs the funding scan before it picks its index, a start never lowers an index the scan moved, a forgotten exit's funding address that holds coins is re-listed as kept change, and the scan ceiling counts from its start. Reviewed 5f22319, full tier.
What I checked, and 5 candidates I ruled out
Read in full: SparkExitRepo.kt (loadQuote, start, cancel/forget, refreshEarlierAddresses, nextFundingIndex, recoverFunding), SparkExitFunding.kt (SparkExitMath.nextFundingIndex, scanNextFundingIndex, fundingIndexAfterForget), SparkExitEarlierAddress.kt (isWatched, SparkExitEarlierAddressStore.add), the BackupRepo.kt restore hunk, and the four new tests.
Call sites traced: nextFundingIndex() has one caller (loadQuote); recoverFunding is called from it and from refreshEarlierAddresses.
Build: not built here. An unrequested review of this repo is reasoned from the code and CI. build-and-test, lint and ui-tests were still pending at review time; Greptile passed.
Ruled out
- Quote after a restore with no chain hosts:
chainnull skips the scan, as before.nextFundingIndexthen falls back to the kept index and the record, so this is not new behaviour. - Extra chain reads on every quote:
recoverFundingreturns null before reading anything unlessfundingIndexKeyis insparkExitFundingRecoveryPending(or no index and no record exist), and a successful scan clears that flag. - Quote and foreground refresh scanning at once: both writes take
maxOfof the cached index, andearlierAddressStore.addis idempotent per address under its file lock, so the two cannot regress the index or duplicate an entry. - A still-watched cancelled address converted to kept change:
addreplaces aCANCELLED_FUNDINGentry withKEPT_CHANGEonly when the address holds coins, which widens the watch from 28 days to always. A later exit that reuses the address still removes the entry instart. - Scan ceiling overflow:
from + FUNDING_SCAN_MAX_ADDRESSESis computed inULongand clamped toUInt.MAX_VALUE, and the new test covers a start at the old ceiling.
Merge confidence: 4/5. No findings and the change is covered by SparkExitRepoTest and SparkExitFundingTest, but build-and-test and lint had not finished when I read the PR.
Reviewer model: claude-opus-5-5
Reasoning effort: Unknown (not present in the run metadata available to this review)
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
|
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. |
|
@coreyphillips found on the iOS twin (synonymdev/bitkit-ios#1305) that the scan's gap term overflows for a restored index near the top of its range. On Android Re-review is needed only because of this push: 5f22319...286930c |
jvsena42
left a comment
There was a problem hiding this comment.
No findings. This is the Android side of the quote-before-recovery gap I reproduced on synonymdev/bitkit-ios#1305.
- The counter only goes up:
startusesmaxOf(current, quoteIndex + 1)(:815),recoverFundingwritesmaxOf(current, scanned)(:1187), and the restore merge is a per-key max. - A scan error fails the quote closed: it fails before
pendingis set, with no cache write and the restore still pending.a quote while a restore is pending fails when the scan failscovers it. - Non-pending quotes are unaffected: they cost one cache read and no network.
- No funds path changes: no payment, broadcast or signing path is touched.
One note, not blocking: recoverFunding has no in-flight sharing. A quote opened while the foreground scan is running starts a second full scan against the single mainnet read host, and one failed read fails that quote. A Mutex with a re-read of the pending flag would let the quote reuse the running scan.
Device gate: no device check needed: it needs a restore whose backup missed the last exit's index; the unit tests cover it. perf: the first quote after a restore now waits for the scan (20+ sequential reads); worth timing once on a restored wallet.
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.
Two independent reviews, nothing blocking a merge.
nits
- Start's never-lower funding index branch has no test (app/src/main/java/to/bitkit/repositories/SparkExitRepo.kt:815)
Twin: synonymdev/bitkit-ios#1305
Description
Three gaps in the restore scan of #1782, raised by @coreyphillips on the iOS twin, which gets the same fixes:
Design
N/A — no UI changes.
Preview
N/A
QA Notes
Automated Checks
SparkExitRepoTest:a quote while a restore is pending scans past the restored funding index first: with index 3 restored and address 3 funded, the quote funds from address 4 and lists address 3's coins.a quote while a restore is pending fails when the scan fails: no quote, nothing kept.a restored funding index at a forgotten exit's address lists its late payment as kept change.SparkExitFundingTest:a funding scan from past its ceiling still reads forward.Not tested