Skip to content

fix: keep a stopped node's late writes off its rebuilt node - #1521

Merged
ovitrif merged 3 commits into
masterfrom
chore/bump-ldk-node-rc82
Nov 27, 2026
Merged

ovitrif merged 3 commits into
masterfrom
chore/bump-ldk-node-rc82

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1520
Twin:

Refs: synonymdev/ldk-node#140

Updates LDKNode to 0.7.0-rc.82, which carries synonymdev/ldk-node#140, so both apps ship the same ldk-node in 3.2.0.

Description

  • Keeps a stopped node's late VSS writes from overwriting a rebuilt node's state, e.g. an older channel monitor over a newer one after a restart whose stop timed out.
    • Building the next node now waits up to 60 s for the old node's VSS writes still in flight, then drops any write the old node starts later. If they are still in flight after 60 s, the build fails with KvStoreSetupFailed and replaces nothing.
  • When an Electrum or RGS change's build fails on the old node's writes still in flight, the change now retries its own start up to 5 times instead of rejecting a valid server, since the busy store has nothing to do with it.
  • When a failed change falls back to the previous config and that build fails the same way, recovery retries its start up to 5 times too, instead of leaving Lightning offline until the app restarts. A stop requested meanwhile wins over every start.
  • Bumps the exact-version pin in project.pbxproj and Package.resolved. The Swift API is unchanged between rc.81 and rc.82.

Out of Scope

Design

N/A — no UI changes.

Preview

N/A

QA Notes

Setup

Dev (regtest) debug build on an iPhone 17 Pro simulator, iOS 26.5, against staging VSS and Electrum, with a new wallet.

Journeys

N/A — no user-visible behaviour change.

Manual Tests

  • 1. Settings → Advanced → Dev Settings → LDK → Restart, twice → each time the log shows Node stopped, LDK node setup, Node started and Node restarted successfully.
  • 2. Settings → Advanced → Electrum Server → port 1 → Connect To Host → the change fails, the log shows Failed ldk-node config change, attempting recovery…, then the node starts with the previous config.

Automated Checks

  • added LightningServiceTests cases: a start retries while the store is busy, gives up after 5 attempts, does not retry other failures, and does not start or retry once a stop was requested; a config change retries its own start on a busy store without falling back, and falls back after another failure.
  • ran RUSTFLAGS="--cfg vss_test" cargo test io::vss_store in ldk-node at the rc.82 tag against a local VSS server (see chore: release 0.7.0-rc.82 ldk-node#142).

Evidence

  • Unit suite (CI test selection) on an iPhone 17 Pro simulator, iOS 26.5, against the published LDKNodeFFI.xcframework of 0.7.0-rc.82 at 3ca8946: 4686 tests, 0 failures (5 skipped).
  • 1 and 2 passed on the same simulator at 416f572: the restarts and the recovery each stopped the node and rebuilt it on the same VSS store, and it started on the first attempt; recording in the QA comment. Since then, 443d622 rewraps two if bodies for SwiftFormat and 3ca8946 retries a config change's own start on a busy store; neither path is reached in 1 or 2 without a busy store.

Gaps

  • A VSS write still in flight past the 60 s wait cannot be triggered on demand in the app, so the busy-store retry is covered by the unit tests only.

Retries the recovery start while the build fails on a VSS store still busy with the stopped node's writes, and skips it once a stop was requested.

Verified: unit suite (CI selection) on an iPhone 17 Pro simulator, iOS 26.5, with bitkit-ios#1519 applied locally; simulator run of node start, two restarts and a failed Electrum change recovering.
@ovitrif ovitrif added this to the 3.2.0 milestone Nov 27, 2026
@ovitrif ovitrif self-assigned this Nov 27, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T08:26:05.378305Z 416f572 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

QA

Tested 416f572, a dev (regtest) debug build on an iPhone 17 Pro simulator, iOS 26.5, against staging VSS and Electrum, with a new wallet. The build resolved LDKNodeFFI.xcframework from 0.7.0-rc.82.

  • Node start: passed. The new wallet's node built on VSS and started.
  • 1. Restart twice from Dev Settings → LDK: passed. Each restart stopped the node, built the next one on the same VSS store and started it in about a second (Node restarted successfully), so the write fence let the rebuild through once the stopped node's writes had returned.
  • 2. Failed Electrum change: passed. Port 1 failed the start (Failed ldk-node config change, attempting recovery…), recovery released the built node, rebuilt it on the same store with the previous config and started it on the first attempt.
  • Unit suite (CI test selection): 4684 tests, 0 failures, 5 skipped, including the new recovery-start cases.

node-run2x.mp4

Not covered: a VSS write still in flight past the 60 s wait cannot be triggered on demand in the app, so the busy-store retry is covered by the unit tests only.

@ovitrif
ovitrif requested review from a team, ben-kaufman and piotr-iohk and removed request for a team November 27, 2026 08:24
Verified: swiftformat --lint on both files (0 require formatting)
@ovitrif ovitrif changed the title chore: bump ldk-node to 0.7.0-rc.82 fix: keep a stopped node's late writes off its rebuilt node Nov 27, 2026
@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Renamed to match its twin synonymdev/bitkit-android#2004; the ldk-node 0.7.0-rc.82 bump stays as described in the body.

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were established.RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no actionable issues were established.

Summary

Updates LDKNode to 0.7.0-rc.82 and adds recovery retries when a stopped node’s VSS writes still keep the store busy.

  • Lightning node rebuilds keep late writes from replacing newer saved state.
  • Failed settings changes retry recovery while old writes keep the store busy.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Config change fails] --> B[Stop failed node]
  B --> C{Stop requested?}
  C -->|Yes| D[Skip recovery start]
  C -->|No| E[Build and start previous config]
  E -->|Success| F[Recovery complete]
  E -->|Store busy and attempts remain| C
  E -->|Other error or final attempt| G[Log recovery failure]
  D --> H[Return original config error]
  F --> H
  G --> H
Loading

Reviews (1) · Last reviewed commit: "chore: bump ldk-node to 0.7.0-rc.82" · Reviewed by Greptile

@ovitrif ovitrif removed this from the 3.2.0 milestone Nov 27, 2026

@talosmachina talosmachina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings. Bumps LDKNode to 0.7.0-rc.82 (the VSS store fence of synonymdev/ldk-node#140) and makes the Electrum/RGS recovery start retry up to 5 times while the build fails with KvStoreSetupFailed, stopping as soon as a caller asks for a stop. Reviewed 443d622c6, full tier, static: iOS does not build on Linux, so nothing was compiled or run here.

What I checked, and 4 candidates I ruled out

Read in full: LightningService.swift lifecycle section (setup, restart, recovery, start, stop, stopNode), ServiceQueue.background, AppError(error:), NodeRestarter, SettingsViewModel+Electrum, WalletViewModel.stopNodeLocked / stopForWipe, AppReset server-settings wipe, ldk-node src/io/vss_store.rs and src/builder.rs at the rc.82 tag.
Call sites traced: every caller of stop(clearEventCallback:) (only WalletViewModel through NodeLifecycleService) and of restart(...) (Electrum, RGS, LDK debug screen). restartNode and restartWithPreviousConfig now use stopNode, so the restart's own stops do not count as requested stops; external stops still go through stop and bump requestedStops.
Error matching: setup builds inside ServiceQueue.background(.ldk), which wraps the thrown BuildError in AppError with underlyingError set (Errors.swift), so isKvStoreSetupFailure sees BuildError.KvStoreSetupFailed on the real path, as in the tests.
Binary: the bindings/swift sources are identical between rc.81 and rc.82, and the sha256 of the published LDKNodeFFI.xcframework.zip for v0.7.0-rc.82 matches the checksum in its Package.swift (abb06ea3...). Package.resolved pins the tag commit 1dd2f42e.
CI: SwiftFormat, validate and detect-changes green; Run Tests, Run Integration Tests and build-local still pending when this was posted.

Ruled out

  • Retry also matches an unreachable VSS server: KVStoreSetupFailed is also what the schema-version read returns after its retries, so offline each attempt can take minutes and the loop stretches recovery. Bounded at 5 attempts, and retrying while offline can bring the node back once the network returns, so this is a trade-off rather than a defect.
  • A stop during one attempt's setup: stop finds no node yet, and that attempt's start still runs. The same window existed for the single recovery start before this change; the new check only narrows it.
  • Native stop failed and the old node is still live: each build then waits the full 60 s fence and fails, so recovery gives up after about 5 minutes, bounded.
  • Lock leak between attempts: a failed setup releases the lightning lock in its defer and leaves configuredNode nil, so the next attempt's guard passes.

Merge confidence: 4/5, the unit and integration jobs had not finished, and the busy-store path is covered only by closure-level unit tests, not by a real fence timeout.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the run metadata available to this reviewer does not carry an effort setting)

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: full PR diff against its merge base, at 443d622.

1 actionable finding — resolve or provide an evidence-backed rebuttal.

The ldk-node rc.82 bump adds a VSS store fence: every build now waits up to 60 s for a node still live on the same store, and for its in-flight writes, then fails with KvStoreSetupFailed. The PR only retries that failure in restartWithPreviousConfig. The first attempt of an Electrum or RGS change is not retried. When the store is busy, a valid server is rejected and the node falls back to the previous server (see the finding). The rest of the change holds up in source analysis:

  • stop() and stopNode() are split correctly, so the restart's own stops don't count as requested stops.
  • BuildError.KvStoreSetupFailed reaches isKvStoreSetupFailure through ServiceQueue.background and AppError(error:).
  • A failed setup releases the lightning lock and leaves configuredNode nil between attempts.
  • The Swift binding's BuildError cases are unchanged between rc.81 and rc.82.

Dependency source inspected: synonymdev/ldk-node rc.81 366d56ef3c735406146ed12a34aba291776d29f6 against rc.82 1dd2f42e44561ee4005f109c0d2cb61e1de99123 (src/builder.rs, src/io/vss_store.rs, src/lib.rs).

Parity: compared with the twin bitkit-android#2004 at 35873ab4. Android uses the same 5-attempt recovery-only retry and the same stop-wins check (pendingStopJob). Its first restart attempt also goes straight to recovery on KvStoreSetupFailed, so the finding's mechanism looks the same there. That was not reviewed in full.

Other notes, not findings:

  • A restart can now block for several minutes: up to 60 s for the first attempt, plus up to 5 recovery builds of up to 60 s each, all on the serial .ldk queue. Meanwhile the Electrum/RGS screen stays loading.
  • A wallet wipe started during that window waits on in-flight server switches with a 30 s bound (AppReset.swift:60, SettingsViewModel.swift:363-371), so it fails with a timeout and must be retried.
  • KvStoreSetupFailed also covers an unreachable VSS server during the schema-version read, so recovery retries that case too.

Validation: I compiled and ran nothing; iOS can't build in this environment. The new LightningServiceTests cases only exercise startRetryingBusyStore with closures. No test covers the first restart attempt hitting a busy store. At review time, CI SwiftFormat passed; Run Tests and Run Integration Tests were still running. The author reports a passing unit suite and manual cases 1 and 2 at 416f5720. A busy store past the 60 s wait was not exercised at runtime.

Device testing: not performed in this review.

Suggested additional test cases:

  • iOS unit: stub setup so it throws AppError(error: BuildError.KvStoreSetupFailed) for the requested Electrum URL and succeeds when called again. Call restart(electrumServerUrl:). Expected: the requested server is retried and kept instead of falling back to the previous config.
  • iOS manual (needs a way to block VSS writes, e.g. a proxy that holds VSS PUTs for more than 60 s): change the Electrum server to a valid host while VSS writes are held. Expected: no server-change error caused only by the busy store, and the screen doesn't stay loading for minutes.

Findings

  • [MEDIUM] Retry a busy-store build failure on the requested Electrum/RGS restart, not only in recovery — inline at Bitkit/Services/LightningService.swift:461.

Reviewer model: claude-opus-5-5
Reasoning effort: high

Comment thread Bitkit/Services/LightningService.swift Resolved
An Electrum or RGS change whose build fails because the stopped node's VSS writes are still in flight now retries its own start before falling back to the previous config.

Verified: unit suite (CI selection) on an iPhone 17 Pro simulator, iOS 26.5; swiftformat --lint on both files.

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: changes since 443d622c6, including affected code paths and unit tests, at 3ca894644. Baseline: previous review (inheriting the unchanged ldk-node 0.7.0-rc.82 dependency bump and VSS fence contract, stop()/stopNode() accounting, and changelog.d/next/1520.fixed.md).

No new actionable code findings.

LightningService.applyConfigChange retries the config change's own setup + start up to busyStoreStartAttempts (5) on BuildError.KvStoreSetupFailed, yields to requested stops via stopRequested, falls back to restartWithPreviousConfig (which also releases any node built during a non-busy failure before skipping restart if a stop was requested), and rethrows the original error. BitkitTests/LightningServiceTests.swift adds focused coverage for retrying on a busy store without falling back and falling back on non-busy failures.

Parity comparison against synonymdev/bitkit-android#2004 at 35873ab4e: iOS at 3ca894644 now retries KvStoreSetupFailed on the config change's own start as well as during recovery, whereas the Android twin at 35873ab4e currently retries KvStoreSetupFailed only in restartWithPreviousConfig() (restartWithElectrumServer and restartWithRgsServer still call start(shouldRetry = false, ...) directly).

Validation and limitations: CI SwiftFormat passed at 3ca894644, while CI Run Tests, Run Integration Tests, and e2e-tests (build-local) were still in progress during this review. Xcode compilation and unit tests could not be executed locally on this Linux host (the author reports 4686 unit tests passing locally at 3ca894644).

Recommended before device testing

Device testing: not performed in this review. The author's manual cases 1 and 2 were reported passing at 416f5720e; the busy-store retry path itself is covered by unit tests (LightningServiceTests) rather than live device reproduction.

Earlier findings reconciled at this revision: 1 verified fixed.

Reviewer model: gemini-4-neon
Reasoning effort: high

@ovitrif
ovitrif requested review from jvsena42 and pwltr and removed request for ben-kaufman November 27, 2026 11:26
@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Ben is away for a few days, so I moved this review request to @pwltr and @jvsena42.

@ovitrif

ovitrif commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Merged: approved by @piotr-iohk at 3ca8946, checks green, every thread resolved.

@ovitrif
ovitrif merged commit 676956b into master Nov 27, 2026
22 checks passed
@ovitrif
ovitrif deleted the chore/bump-ldk-node-rc82 branch November 27, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: a stopped node's late writes can overwrite its rebuilt node's state

3 participants