Skip to content

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

Merged
ovitrif merged 8 commits into
masterfrom
fix/ldk-node-rc82
Nov 24, 2026
Merged

ovitrif merged 8 commits into
masterfrom
fix/ldk-node-rc82

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #2003

Updates ldk-node-android to 0.7.0-rc.82, which carries synonymdev/ldk-node#140.

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 foreground restart whose stop timed out.
    • Building the next node now waits up to 60 s for the old node's VSS write calls 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, and the existing recovery rebuilds the node.
  • When a failed Electrum or RGS change falls back to the previous config and that build also fails on the old node's writes still in flight, recovery now retries the start up to 5 times instead of leaving Lightning offline until the app restarts. A background stop requested meanwhile wins over every recovery start.
  • Fixes the kdocs on releaseHandle and awaitNodeRelease: the release gate waits until free_node returns, not for the old node's detached work, which can still run after a timed-out stop.
  • Renames exitBeforeRuntimeShutdown to exitBeforeDetachedWorkOverlaps, after the reason it stays since rc.81.
  • Adds the rc.82 checksums to gradle/verification-metadata.xml.

Design

N/A — no UI changes.

Preview

N/A

QA Notes

Setup

Dev (regtest) debug build on a rootable Android 15 emulator, with staging VSS (34.65.252.32:443) blocked by iptables; Electrum on the same host stays reachable.

Journeys

N/A — no user-visible behaviour change.

Manual Tests

  1. Timed-out stop in the foreground (recipe from this review):
    • Create a wallet and wait for the node to start.
    • Block VSS and wait until wallet sync stops.
    • With the app in front, change the Electrum server in Settings to restart the node.
    • Unblock VSS.
    • Expected: the stop detaches the stuck work, the runtime shutdown waits for it, the rebuilt node does not overwrite or get overwritten, and the app does not abort.
  2. Recovery after both build waits: as in 1, but unblock VSS only after the change and the first recovery start have both failed.
    • Expected: a later recovery start succeeds and Lightning runs again without restarting the app.

Automated Checks

Evidence

  • Manual test 1, ldk-node log in order:
    1. Detaching background tasks after cancellation timed out.
    2. Deferring runtime shutdown until detached work still running at shutdown has ended.
    3. The restart's build waited the full 60 s on the old node's write and failed with Writes of the current store to this VSS store are still in flight; the app logged Failed ldk-node config change, recovering in background… and rebuilt the node on the previous server.
    4. After unblocking: Dropped write of key //events: another node was built on this VSS store, then Shut down the runtime after detached work ended.
    5. Node started and a completed on-chain sync 6 s later; no SIGABRT or fatal signal in logcat, and the app process lived through the whole run.
  • Manual test 2 on 4820414: the change's build and the first recovery start each failed after 60 s with KV store setup failed, then Retrying recovery start '2/5'; with VSS unblocked, Node started and Successfully started node with previous config followed 11 s later and syncs resumed, with no fatal signal and the same app process throughout.
  • just compile, just test and just lint pass on 35873ab.
  • ./gradlew :app:assembleDevDebug passes against the published com.synonym:ldk-node-android:0.7.0-rc.82.

Gaps

  • None.

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium)
  • Implementation: Claude Opus 5.5 (reasoning: medium), Claude Sonnet 5.5 (reasoning: high)
  • Review: Claude Sonnet 5.5 (reasoning: high)

Bumps ldk-node to 0.7.0-rc.82, which fences a replaced VSS store's writes. The release-gate kdocs now say the gate waits for free_node, not for the old node's detached work (#2003), and the background exit is named for the overlap it avoids.

Verified: none (metadata and build run next)
Verified: ./gradlew --write-verification-metadata sha256 :app:assembleDevDebug
Verified: none (changelog text only)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 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-23T23:41:49.803117Z dab084a 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.

@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Updates ldk-node-android to 0.7.0-rc.82 to keep stopped nodes' late VSS writes from overwriting rebuilt nodes.

  • Rebuilt Lightning nodes keep old VSS writes from changing their state.

No actionable issues found. Builds and tests were not run during this review.

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

@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 ldk-node-android to 0.7.0-rc.82 for the VSS write fence, renames the background exit after the reason it stays, and corrects the release-gate kdocs. Reviewed 7f8ef77, light tier, static: Android branches are not built here, so this is reasoned from the code, the rc.81..rc.82 ldk-node diff and CI.

What I checked, and 4 candidates I ruled out

Read in full: the PR diff; LightningService.setup, build, stop, releaseHandle, awaitNodeRelease; LightningRepo.start, restartWithElectrumServer, restartWithRgsServer, restartWithPreviousConfig
ldk-node rc.81..rc.82: src/builder.rs, src/lib.rs (start, stop), the fence in src/io/vss_store.rs (STORE_FENCES, REPLACED_WRITES_TIMEOUT = 60 s, start_marked_live)
CI: build-and-test, lint, compose-ui, build-local still pending at review time

Ruled out

  • FFI break from the bump: bindings/ldk_node.udl is unchanged between rc.81 and rc.82, and the only new failure mode, BuildException.KvStoreSetupFailed after the 60 s wait, is already mapped in Errors.kt and surfaces through setup's failure path, so restartWith* falls into restartWithPreviousConfig as the QA evidence shows.
  • The 60 s build wait outliving the release gate: awaitNodeRelease (90 s) runs before build, and the fence wait is inside build on the LDK queue with node == null, so nothing that needs a live node is queued behind it.
  • Old node's start racing the rebuilt one: rc.82 refuses start on a node whose store was replaced (PersistenceFailed), and the app never restarts a released handle; setup always builds a new Node.
  • The background exit becoming redundant: the fence state is process-wide (STORE_FENCES static), so a process exit still resets it and the cold start path is unaffected; keeping the exit is consistent with the new kdoc.

Merge confidence: 4/5, CI was still running and the app's handling of the new build wait is covered by the manual test 1 evidence rather than a unit test.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the review session does not report it)

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 35873ab (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

Comment thread gradle/libs.versions.toml Resolved
A stopped node's VSS write can keep retrying for minutes, past one build's 60 s wait, so the single recovery start failed and Lightning stayed offline until the app restarted. Recovery now retries the start while the build fails on the busy store, up to five times.

Verified: none (gate runs next)
Verified: none (gate runs next)
@ovitrif
ovitrif requested a review from ben-kaufman November 24, 2026 00:57

@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 6fc5bb2.

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

The ldk-node 0.7.0-rc.82 fence (1dd2f42e44561ee4005f109c0d2cb61e1de99123) waits up to 60s for a stopped node's in-flight VSS writes and fails the build without replacing the store. Recovery retries that KvStoreSetupFailed up to five times. A background stop requested before the first recovery start is still cleared by that start, so a later retry can run Lightning with background payments off. The resolved thread covers a stop requested during an in-flight recovery build; later retries now yield to that stop.

Device testing: not performed in this review. The author's manual tests 1 and 2 keep the app in the foreground. This review did not run the unit tests. The author reports just compile, just test, and just lint on 6fc5bb2.

Scoped comparison of bitkit-ios 2be17dd7919262391f996928744317d25f93ab07: LightningService.restartWithPreviousConfig does one setup and start. Only that recovery start was read.

Suggested additional test cases:

  • Android, with Keep Bitkit active in background off. Block VSS, change the Electrum server, send the app to the background during the wait, then unblock VSS. Expected: Lightning stays stopped while the app is backgrounded, and returning to the app starts it.
  • Unit: in LightningRepoTest, call stopDebounced() from the failing new-server setup, before recovery's first setup, and let a later previous-config setup succeed. Expected: nodeLifecycleState stays off Running.

Findings

  • [MEDIUM] Yield to a background stop before the first recovery start — inline at app/src/main/java/to/bitkit/repositories/LightningRepo.kt:1301.

Reviewer model: grok-4.7
Reasoning effort: xhigh

@ovitrif
ovitrif requested a review from piotr-iohk November 24, 2026 07:30

@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 6fc5bb2, including the recovery start path those changes affect, at 35873ab. Baseline: previous review. Inherited coverage: the ldk-node 0.7.0-rc.82 VSS write fence and Gradle verification metadata, LightningService stop and background process exit, KvStoreSetupFailed classification, and the changelog fragment.

No new actionable code findings.

restartWithPreviousConfig checks the pending background stop before every recovery start, including the first, and calls startNode with shouldCancelPendingStop = false. A stop requested while the failed Electrum or RGS build is still running stays pending, so that recovery leaves the node stopped. Returning to the foreground still goes through WalletViewModel.start, which cancels the pending stop and starts the node. The recovery attempt cap remains 5. This is source analysis; the new unit test was inspected and not executed in this review.

Compared with bitkit-ios at 2be17dd for the Electrum change only: a failed connection reloads the stored server after lightningService.restart. That check did not cover the rest of the iOS app. iOS has no debounced background stop on this path.

Device testing: not performed in this review. Ready for device testing.

Suggested additional test cases

  • Android, dev regtest, with VSS blocked as in manual test 1. Start an Electrum server change, send the app to the background before that build fails, and leave it there. Expected: Lightning stays down while the app is backgrounded, and the process is not aborted. Bring the app back to the foreground. Expected: the node starts on the previous Electrum server without restarting the app.

Earlier findings reconciled at this revision: 3 verified fixed.

Reviewer model: grok-4.7
Reasoning effort: xhigh

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code scan at 35873ab: no HIGH or MEDIUM. Two LOWs are inline, both about a stop losing to the new recovery path. I reviewed this as a funds/lifecycle change (ldk-node bump plus node start/stop).

What I checked and found clean:

  • Two nodes on one store. Every build runs under lifecycleMutex after awaitNodeRelease. A failed setup leaves node == null, and the rc.82 fence refuses a build while a node is live. Retry attempts can't overlap each other or a foreground start.
  • Retry bound. At most 5 attempts, only on KvStoreSetupFailed. WipeInProgressError, RecoveryModeError and start errors end the loop. A setup failure never takes the shouldRetry path, so retries don't nest.
  • Error matching. LightningService.build throws LdkError(BuildException), and the cause-chain walk matches it bare or wrapped.
  • Wipe during retry. WipeWalletUseCase sets isWiping before its stop(), so the next attempt exits with WipeInProgressError.
  • Cancellation. No runCatching around suspend calls in the loop. startNode rethrows CancellationException.
  • Upgrade. v3.1.1 ships rc.80. rc.81..rc.82 changes builder.rs, vss_store.rs, lib.rs and tests. The fence is in-memory state, and the VSS schema version and key obfuscation are unchanged, so there is no persisted-format change.
  • Nit, not a finding: the configChangeMutex kdoc says recovery is cheap to wait on. With rc.82 a recovery can take up to 5 × 60 s.

Performance-relevant: yes. The PR adds a retry loop and a wait of up to 60 s on the node start path. On a device I'll measure:

  • foreground start time to Node started after a >5 s background, against master;
  • spinner time and total recovery time for an Electrum change with VSS blocked.

Device gate (partial): 35873ab — not run yet; pending the start-time measurement against master and manual tests 1-2 (VSS blocked by iptables on a rootable emulator). The device result will follow in a second review.
Skipped — covered by CI at 35873ab: unit tests, lint, detekt, compose UI, local e2e (all green).

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving at 35873ab. The code scan and the device gate found nothing above LOW. The two LOWs from my code scan are still open, each with a unit test that fails at this head. Fix them here or move them to a follow-up issue, whichever you prefer; please reply on each thread saying which.

Device gate: 35873ab vs merge base 1b3f373 (rc.81). Both are dev debug builds on a rootable Android 15 emulator against staging. VSS was blocked with iptables on tcp/443 to 34.65.252.32 only, since Electrum uses the same IP.

  • perf: 3 runs per case.
    • Foreground start, ON_START → Node started: median 8.6 s (base 7.6 s).
    • Cold launch → Node started: median 18.3 s (base 17.5 s).
    • The difference is about 0.8 s inside start; build takes the same time on both.
    • Idle on Home for 2 min: 1.5 VSS puts/min (base 2.0). 0 put errors and 0 dropped writes on both, and the same single Firebase WARN on both.
  • Manual test 1 ✅ Spinner 107.5 s. The rebuild fails with still in flight, and the app logs Failed ldk-node config change, recovering in background…. Dropped write of key //events follows, then Node started 52.5 s after the unblock. Same pid throughout, no fatal signal.
  • Manual test 2 ✅ Retries reached 3/5: the old write drained only at 10:29:32 UTC, after the unblock, so a third build also timed out. Node started came 90.8 s after the unblock and syncs resumed. Same pid, no fatal signal.
  • LOW 1 on device: inconclusive. I tapped the notification's Stop at retry 2/5 with keep-active on. The service's onDestroy logged Skipping node stop: activity is active. The process was then frozen as cached, so retry 3/5 never ran. On relaunch the loop logged Skipped recovery start because a stop was requested, then started normally. The unit test on that thread still reproduces the gap with the process alive.
  • l10n: no UI text changed. Figma: no UI changes. iOS: no twin found.

Skipped — covered by CI at 35873ab: unit tests, lint, detekt, compose UI, local e2e (all green).

@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.

Approving at 35873ab4. I tested a locally built devDebug APK on an Android 15 ARM64 emulator with a fresh staging regtest wallet.

Device check Result
Background and reopen Passed. After 12 seconds on Android Home, I reopened Bitkit. The logs showed the node stop, start again, and complete wallet sync in the same process (PID 4163).
Electrum settings restart Passed. I changed the capitalization of the staging hostname, then restored the default. After each change, Settings showed Connected and the node completed wallet sync in PID 4163.
Late writes during rebuild and recovery after repeated waits Both PR manual tests passed in jvsena42’s device run on this commit. My run covered the two normal restart paths above.
Stop while recovery is pending Unverified on device. The stop in my background test occurred during normal operation.

Two LOW findings remain open on whether recovery honors a stop request. Notification Stop · Graph reset during recovery

@ovitrif

ovitrif commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

Merging: approved at 35873ab with CI green; the two recovery-stop Lows follow in their own PR.

@ovitrif
ovitrif merged commit ebe3980 into master Nov 24, 2026
23 checks passed
@ovitrif
ovitrif deleted the fix/ldk-node-rc82 branch November 24, 2026 13:16
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.

docs: node release gate does not wait for detached work

5 participants