Skip to content

fix: recover with the saved servers after a failed server change - #1546

Merged
piotr-iohk merged 4 commits into
masterfrom
fix/recovery-saved-servers
Nov 28, 2026
Merged

piotr-iohk merged 4 commits into
masterfrom
fix/recovery-saved-servers

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1530
Refs: #1529

Description

  • Fixes recovery after a failed Electrum or RGS server change restarting the node on the network's default servers, because it built the node with nil server URLs; it now uses the saved servers, the same ones a normal start passes
  • WalletViewModel hands the saved servers to LightningService as a closure, since LightningService.swift is also compiled into the notification extension and the unit tests, which have no server config services; those keep the defaults
  • Android has no twin: its LightningService already resolves a missing URL to the saved electrumServer and rgsServerUrl settings

Recovery passes the saved servers to the setupNode call that #1529 added to restartWithPreviousConfig.

Out of Scope

Design

N/A — no UI changes.

Preview

N/A — no user-visible changes.

QA Notes

Setup

Debug build (regtest, staging backend), a new wallet.

Journeys

N/A — not drivable; see Manual Tests.

Manual Tests

  • 1. Save a custom RGS URL (Settings > Advanced > Rapid-Gossip-Sync, e.g. https://Bitkit.stag0.blocktank.to/rgs/snapshot), then connect Electrum to unreachable.invalid → the change fails and the app log shows recovery building with the saved RGS URL, not the default — needs the app log, which journeys do not read
  • 2. Save a custom working Electrum server, then connect to unreachable.invalid → recovery's Using Electrum server log line shows the saved server — needs a second working Electrum server and the app log

Automated Checks

  • added WalletViewModelRecoveryServersTests.swift — WalletViewModel hands recovery the saved Electrum and RGS servers
  • ran the unit suite (CI's selection) on an iOS 27.0 simulator

Evidence

On an iPhone 17 Pro simulator (iOS 27.0), regtest, with a custom RGS URL saved, then a failed Electrum change to unreachable.invalid:

  • master (947d27b): recovery built the node with the default RGS URL.
  • this PR (f4cb0e0, plus a local log line for the Electrum URL): recovery built it with the saved RGS URL, and the node started.
  • this PR after the master merge (e8cc136, same log line): recovery built the node through setupNode with the saved RGS URL and the saved Electrum server, and the node started.
  • WalletViewModelRecoveryServersTests passes at 5baaea2 and e8cc136.

Gaps

    1. not run: Connect on a second spelling of the staging Electrum host did nothing in the simulator, so no custom Electrum server was saved; the unit test covers the Electrum wiring.

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium)
  • Implementation: Claude Opus 5.5 (reasoning: medium)
  • Review: Gemini 4 Neon (reasoning: high)
  • Review rounds: 1

Recovery after a failed Electrum or RGS change called setup with nil
URLs, which setup resolves to the network defaults, so a wallet with a
custom server ran on the default for the rest of the session. Recovery
now reads the saved servers through a closure WalletViewModel sets,
the same ones a normal start passes. LightningService.swift is also
compiled into the notification extension and the unit tests, which
have no server config services, so they keep the defaults.

Verified: swiftformat --lint on the changed files
Verified: none (runs next on m1a)
@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-27T21:59:40.069228Z 5baaea2 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 requested review from a team, coreyphillips and piotr-iohk and removed request for a team November 27, 2026 21:58
@ovitrif

ovitrif commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

QA:
Tested on iPhone 17 Pro simulator (iOS 27.0), regtest, at f4cb0e0; 5baaea2 adds only the unit test.

🟢 Recovery after a failed Electrum change keeps the saved RGS server
Recovery after a failed Electrum change keeps the saved RGS server

With a custom RGS URL saved, a failed change to Electrum unreachable.invalid recovered with the saved RGS URL and the node started; master recovered with the default RGS URL.

masterthis PR
master2x.mp4
branch2x.mp4

Device tests skipped ⚠️:

  • Recovery after a failed Electrum change keeps the saved Electrum server: no second working Electrum server could be saved in the simulator; WalletViewModelRecoveryServersTests covers the wiring and passes at 5baaea2.

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5 · The PR appears safe to merge, with a non-blocking gap in the recovery test.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects Lightning recovery after a server-change restart fails.

The PR appears safe to merge, with a non-blocking gap in the recovery test.

Findings

  1. P2 Recovery is not tested ▶

Summary

Recovery now reads saved Electrum and RGS URLs through a closure set by WalletViewModel, then passes them to setup. Other targets keep the default closure.

  • Lightning recovery restarts with the servers saved in the app.

Reviews (1) · Last reviewed commit: "test: recovery reads the saved servers" · Reviewed by Greptile

Verified: swiftformat --lint on the changed file

@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. Recovery after a failed Electrum or RGS change now restarts the node with the saved servers, read through a closure WalletViewModel installs on LightningService, instead of nil URLs that fall back to the network defaults. Reviewed c012075 (5baaea2 plus a test rename), full tier.

What I checked, and 4 candidates I ruled out

Read in full: restart, restartNode, applyConfigChange, restartWithPreviousConfig and configureGossipSource in LightningService.swift; the normal start in WalletViewModel.swift; ElectrumConfigService.getCurrentServer, RgsConfigService.getCurrentServerUrl; both connect flows in SettingsViewModel+Electrum.swift and SettingsViewModel+Rgs.swift.
Call sites traced: every restart caller (the two settings flows, LdkDebugScreen, the post-migration restart in AppViewModel); only the recovery path reads the new closure.
CI: SwiftFormat and validate green; unit and integration runs still pending at review time.
Build: Not built: on this track the review reasons from the code and CI, and iOS does not build on Linux.

Ruled out

  • Recovery passes an empty RGS URL where the normal start passes nil: getCurrentServerUrl() falls back to Env.ldkRgsServerUrl, which is non-empty on every network, so the empty case is unreachable.
  • A failed Electrum change recovers onto the server that just failed: the Electrum flow saves only after a successful connection, so the closure reads the previous server.
  • The notification extension or a test target picks up app config: the default closure returns (nil, nil), the same as before.
  • Preview WalletViewModel() instances overwrite the shared closure: they build the same .standard-backed services, so the values read are the same; the new test restores the previous closure.

Merge confidence: 4/5, WalletViewModelRecoveryServersTests covers the wiring but CI's unit run had not finished and the branch was not built here.

Reviewer model: Claude Opus 5.5
Reasoning effort: Not exposed (the reviewer's run metadata does not carry a reasoning 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 c012075.

No new actionable code findings.

No actionable code findings. Recovery after a failed Electrum or RGS server change builds the node with the saved Electrum and RGS URLs, the same values a normal start passes. Electrum is stored only after the new server connects, so a failed Electrum change recovers onto the previously saved server. A failed RGS change is already stored before the restart (#1535); recovery follows that stored URL. The save order is unchanged in this diff.

Compared bitkit-android at 64670dba, limited to recovery startup and server persistence. A recovery start omits custom URLs, and LightningService resolves them to the saved Electrum and RGS settings. Both new URLs are written only after the change succeeds.

WalletViewModelRecoveryServersTests asserts that the closure returns the saved URLs. It does not run restartWithPreviousConfig. The resolved thread withdrew the request for a unit test that fails a real node build. On this revision, CI unit tests (run), integration tests, SwiftFormat, and translation validation succeeded. The local end-to-end job was still queued. I did not run those checks.

Device testing: not performed in this review. The author reports manual case 1 on f4cb0e0 (iPhone 17 Pro simulator, iOS 27.0, regtest): with a custom RGS URL saved, a failed Electrum change recovered on that RGS URL and the node started. The production files are the same at this head. Manual case 2 was not run.

Recommended before device testing: case 2 needs a second working Electrum server. The author reports that connecting to another spelling of the staging Electrum host did not save a custom server in the simulator.

Reviewer model: grok-4.7
Reasoning effort: xhigh

…servers

# Conflicts:
#	Bitkit/Services/LightningService.swift
@piotr-iohk

Copy link
Copy Markdown
Collaborator

@ovitrif please resolve conflicts.

@ovitrif

ovitrif commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Resolved in e8cc136: merged master; recovery now passes the saved servers to the setupNode call from #1529.

@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 at e8cc136, re-reviewed after the comparison base changed from 947d27b to 7c65088 and master changes touched LightningService.swift.

No new actionable code findings.

No actionable code findings. Recovery after a failed Electrum or RGS change builds the node with the saved Electrum and RGS URLs, the same values a normal start passes. The merge onto master kept those URLs: restartWithPreviousConfig calls setupNode with savedServerUrls(). Electrum is stored only after the new server connects, so a failed Electrum change recovers onto the previously saved server. A failed RGS change is already stored before the restart (#1535); recovery follows that stored URL. That save order is outside this diff.

Compared bitkit-android at 76c508bb, limited to recovery startup and server persistence. A recovery start omits custom URLs, and LightningService resolves them to the saved Electrum and RGS settings. Both new URLs are written only after the change succeeds.

WalletViewModelRecoveryServersTests asserts that the closure returns the saved URLs. restartWithPreviousConfig is outside that test. The resolved thread withdrew the request for a unit test that fails a real node build.

SwiftFormat (run) and translation validation (run) succeeded on this head. Unit tests (run) and integration tests (run) were still running. I did not run those checks.

Device testing: not performed in this review. The author reports manual case 1 on f4cb0e0 (iPhone 17 Pro simulator, iOS 27.0, regtest): with a custom RGS URL saved, a failed Electrum change recovered on that RGS URL and the node started. That commit predates this head's move of recovery from setup to setupNode. Manual case 2 was not run.

Recommended before device testing: re-run case 1 on this head. Case 2 still needs a second working Electrum server; the author reports that another spelling of the staging Electrum host did not save a custom server in the simulator.

Reviewer model: grok-4.7
Reasoning effort: xhigh

@ovitrif

ovitrif commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

QA:
Tested on iPhone 17 Pro simulator (iOS 27.0), regtest, at e8cc136 (after the master merge; recovery now builds through setupNode).

🟢 1. Recovery after a failed Electrum change keeps the saved servers
1. Recovery after a failed Electrum change keeps the saved servers

With a custom RGS URL saved, a failed change to Electrum unreachable.invalid recovered through setupNode with the saved RGS URL and the saved Electrum server, and the node started.

head2x.mp4

Device tests skipped ⚠️:

    1. no second working Electrum server could be saved in the simulator; WalletViewModelRecoveryServersTests covers the wiring and passes at e8cc136.

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

Device QA passed on e8cc13695 on an iPhone 17 simulator running iOS 27.2 on regtest. The installed CI build’s source tree matched the PR head.

  • Saved https://Bitkit.stag0.blocktank.to/rgs/snapshot as custom RGS. After an Electrum connection to unreachable.invalid failed, the recovery logs showed that exact saved RGS URL.
  • Connected to a second Electrum server at tcp://127.0.0.1:60002 and confirmed it saved. After the failed change, recovery selected that previously saved server and logged Node started.

Both Electrum servers were independently queried on the same regtest chain. The device exercised the DNS failure and recovery on the unchanged CI app.

@piotr-iohk
piotr-iohk enabled auto-merge November 28, 2026 11:53
@piotr-iohk
piotr-iohk merged commit 65062fc into master Nov 28, 2026
22 checks passed
@piotr-iohk
piotr-iohk deleted the fix/recovery-saved-servers branch November 28, 2026 11:58
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: recovery after a failed server change uses the default servers

3 participants