Repository navigation
fix: keep a stop requested during a server change's build - #1529
Conversation
A stop requested while a config change or its recovery builds the node finds no node to stop. The change now checks again after setup and releases the built node instead of starting it, and reads the stop count before its own stop. Verified: CI unit-test selection on an iPhone 17 Pro simulator (iOS 26.5) before the stop-count move, LightningServiceTests after it, swiftformat --lint on the changed files.
The restart reads the stop count when it is queued, so a stop requested while it waits behind another restart wins, and a config change ended by a stop no longer runs its recovery. Verified: CI unit-test selection on an iPhone 17 Pro simulator (iOS 26.5), swiftformat --lint on the changed files.
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 change affects Lightning restart and recovery flows across server settings and other restart callers. The PR appears safe to merge, with a non-blocking gap in tests for queued restarts. Findings
SummaryThis PR keeps stop requests from being overtaken by an Electrum or RGS server change.
Scope acknowledged by ovitrif: a stop between the node lookup and native Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Queue restart and capture stop count] --> B[Wait for previous restart]
B --> C[Stop old node]
C --> D{Stop requested?}
D -->|Yes| E[Throw without recovery]
D -->|No| F[Build node]
F --> G{Stop requested?}
G -->|Yes| H[Release built node]
H --> E
G -->|No| I[Start node]
Reviews (1) · Last reviewed commit: "fix: let a stop win over a queued restar..." · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Rechecks for a stop after setup in the config change and its recovery and releases the built node instead of starting it, reads the stop count when the restart is queued, and skips the recovery when a stop ended the change. Reviewed 4a90137f4, full tier, static: iOS does not build on Linux, so I did not build or run it.
What I checked, and 3 candidates I ruled out
Read in full: restart, restartNode, applyConfigChange, restartWithPreviousConfig, startRetryingBusyStore, startUnlessStopRequested, stop/stopNode, stopReleasingFinishedNode, setup in LightningService.swift; the new and existing tests in LightningServiceTests.swift.
Call sites traced: restart(electrumServerUrl:rgsServerUrl:) from SettingsViewModel+Electrum.swift:27, SettingsViewModel+Rgs.swift:22, LdkDebugScreen.swift:111, AppViewModel.swift:1956; stop() from WalletViewModel.stopNodeLocked (reached by NodeRestarter's recovery stop, resetNetworkGraph, stopForWipe).
Twin: compared with synonymdev/bitkit-android#2148, which also releases the built node when the stop count moved during setup.
Ruled out
- Release of a built, never-started node fails:
stopNoderunsnode.stop()throughstopReleasingFinishedNode, which swallowsNotRunning, the error ldk-node gives for a node that never started, then releases it and the lightning lock. - The release error is retried as a busy store:
startUnlessStopRequestedthrowsnodeNotSetup, whichisKvStoreSetupFailurerejects, sostartRetryingBusyStoredoes not start again. - Moving the capture to queue time cancels a restart over an unrelated stop: a stop counted while the restart waits is exactly the case the PR wants to win;
stop()is only reached from the recovery, graph reset and wipe paths, and none of them wants the restart to bring the node back.
The queued-capture timing has no test; Greptile already raised that, so I did not repeat it.
CI: SwiftFormat, validate and Greptile passed; Run Tests, Run Integration Tests and build-local were still pending when I read them.
Merge confidence: 4/5, no findings, but the unit tests have not reported on this head and the review is static.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the run metadata available to this reviewer does not report an effort setting)
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at 4a90137f.
No new actionable code findings.
No actionable code findings. A stop counted while an Electrum or RGS restart is queued, waiting, stopping the old node, or building the new one releases that built node and skips recovery, matching #1527. stopNode still treats ldk-node's NotRunning as the release of a built node that never started, so the node and the lightning lock are dropped. The race inside LightningService.start(), between the node lookup and native node.start(), remains the case the PR leaves out of scope; this change does not widen it.
Compared only the stop-during-build contract with bitkit-android#2148 at abd015b07. Both sides release the built node and skip recovery when a stop is counted during setup. Android also releases a node left behind by a failed or cancelled change, and it debounces a background stop. On iOS a failed change with no stop still runs recovery.
Device testing: not performed in this review. A journey cannot time a stop into the build, which is why the PR marks device testing N/A. The new tests in LightningServiceTests.swift cover releasing instead of starting and skipping recovery. They do not run restart(), so they would still pass if the stop count were read again after the queue wait. That gap is already in Greptile's comment. This review did not run the unit suite. On this head, GitHub's Run Tests and Run Integration Tests were still in progress; SwiftFormat and validate had passed. The author reports the unit suite passed locally at this revision.
Existing concern, unchanged from the merge base: recovery still calls setup with nil server URLs, and setup resolves nil to Env's network default rather than the saved Electrum or RGS server. A failed change that recovers would bring the node up on that default for the rest of the session.
Reviewer model: grok-4.7
Reasoning effort: xhigh
@piotr-iohk Confirmed: a normal start passes the saved servers, recovery passes nil. Out of scope here, since it predates this PR: tracked in #1530 under 3.2.0. |
|
Requested review from @pwltr instead of @ben-kaufman, who is away for a few days. |
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 4a90137. The earlier stop snapshot extends cancellation to the queue wait and old-node teardown.
Low — A canceled restart can stop the wallet’s replacement node. Bitkit/Services/LightningService.swift:448 looks up and stops the current node before checking whether the queued restart is still valid. If a routing-cache retry stops the node and finishes starting a replacement while that restart is queued, the restart can tear down the replacement and then exit, leaving Lightning offline while the wallet still reports it as running. Check for cancellation before touching the current node.
Low — An interrupted RGS change can report failure and still become the saved setting. Bitkit/ViewModels/Extensions/SettingsViewModel+Rgs.swift:71 saves the URL before the restart. If a separate node stop interrupts teardown, Connect or Reset shows a failure, and the next wallet start still uses the newly saved URL. Save the URL after the restart succeeds.
Review details
Quick review: Claude Opus 5.5, high reasoning effort
General review: GPT-6.2 Sol, high reasoning effort
Verification: GPT-6.2 Sol, high reasoning effort
A restart and its recovery read the current node before checking for a stop, and stop only that node; a restart that yields to a stop after setup releases only the node its own setup built. Another start (such as the routing-cache reset after a failed payment) may have built the current node after that stop. Verified: swiftformat lint, unit suite (CI selection) on an iOS simulator
Fixed in 7f490ab: a restart, and its recovery, read the current node before checking for a stop that came while they waited, and stop only that node. A restart that yields to a stop after
Out of scope: tracked in #1535, because the URL is saved before the restart on master too; this PR doesn't change that path. |
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since 4a90137f, including affected code paths and prior findings, at 7f490ab8. Baseline: QA review.
No new actionable code findings.
No new actionable code findings in the follow-up. A queued restart and its recovery snapshot the current node, then yield when a stop was requested while they waited, and a stop during setup releases only the node that setup built. A node another start built after that stop, including the routing-cache retry, stays up. That closes the replacement-node stop described in pwltr's review.
Existing concerns, still present and already tracked: recovery still passes nil server URLs, so a failed change comes back on the network default for the rest of the session (#1530). An RGS change still saves the URL before restart, so a failed change can remain the saved setting (#1535). Both remain in the current tree.
Compared the stop-during-setup contract with bitkit-android#2148 at a45ca2ae. Android's yield stops the current service node. This change releases only the node its own setup built.
Device testing: not performed in this review. Run Tests, Run Integration Tests, and SwiftFormat succeeded on this head. The new unit tests cover the static yield guard. A stop inside a real build remains outside what those tests and a journey can time. The Greptile thread on that test gap is resolved.
Reviewer model: grok-4.7
Reasoning effort: xhigh
Closes #1527
Companion: synonymdev/bitkit-android#2148
Keeps a stop requested while an Electrum or RGS change is building the node, matching synonymdev/bitkit-android#2148.
Description
setupand releases the node its ownsetupbuilt instead of starting it, never a node another start built since.Out of Scope
LightningService.start(): a stop that lands between its node lookup and the nativenode.start()can still be overtaken. The race is in every start path, not only config changes.SettingsViewModel+Rgs: a failed RGS change stays saved, since the URL is saved before the restart; predates this PR, tracked in bug: a failed rgs server change stays saved #1535 (review).restartWithPreviousConfig: recovery builds with the default servers instead of the saved ones; predates this PR, tracked in bug: recovery after a failed server change uses the default servers #1530 (review).Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
N/A — no device testing required: the stop has to land inside the build, which cannot be timed from the app.
Journeys
N/A — no user-visible behaviour change.
Manual Tests
N/A
Automated Checks
LightningServiceTests.swift— a built node is released instead of started after a stop during setup, and starts without one; a queued restart leaves the current node alone after a stop while it waited; a config change ended by a stop does not recover.Evidence
Gaps
Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium)Gemini 4 Neon(reasoning:high)