Skip to content

Validate Electrum server network before switching #1078

Description

@jvsena42

Summary

When changing the custom Electrum server in Settings → Advanced → Electrum server, the app does not validate that the server belongs to the wallet's network. Pointing a wallet at a server from a different network (e.g. a regtest wallet at a mainnet server) is accepted, after which the on-chain wallet sync fails indefinitely and the screen silently shows Disconnected with an endless retry loop.

Steps to reproduce

  1. Run a regtest (dev) wallet.
  2. Open Settings → Advanced → Electrum server.
  3. Enter a mainnet server, e.g. electrum.blockstream.info / 50002 (SSL), and tap Connect.
  4. The change is accepted ("Successfully changed electrum server").
  5. The Electrum server row shows Disconnected and the on-chain wallet sync keeps timing out.

Root cause (from device logs)

The server switch succeeds, but the regtest node then syncs against a mainnet chain. The Lightning tx sync still finishes fast (only a few channel script-hashes), while the on-chain wallet full re-scan against the remote mainnet chain exceeds its deadline:

LightningRepo: Changing ldk-node electrum server to: 'ssl://electrum.blockstream.info:50002'
LightningRepo: Successfully changed electrum server
...
ldk_node::chain::electrum: Incremental sync of on-chain wallet timed out: deadline has elapsed
LightningRepo: Error executing 'sync' [AppError='A wallet operation timed out.']
LightningRepo: Sync retry failed, will retry in 15s

The failed sync sets lastSyncError (LightningRepo.kt), and the screen derives isConnected = isNodeRunning && !hasSyncError (ElectrumConfigViewModel.observeState), so it renders Disconnected. The status is technically accurate, but the real problem — a wrong-network server — is never surfaced, and the app retries forever.

Expected behavior

Before switching, validate that the Electrum server's network matches the wallet's network. On mismatch, reject the change and show a clear error (e.g. "This server is on a different network") instead of accepting it and silently going Disconnected.

Proposed approach

  • Add a network check to the connect flow (ElectrumConfigViewModel.connectToServer / LightningRepo.restartWithElectrumServer), e.g. probe the server's genesis block hash (Electrum server.features / blockchain.block.header at height 0) and compare it against the wallet's expected network genesis before committing the switch.
  • Surface a dedicated validation error string rather than relying on the generic sync-error → Disconnected state.
  • Add unit coverage for the mismatch path in ElectrumConfigViewModelTest.kt.

Notes

  • Reproduced on a dev/regtest build; primarily affects users who manually enter a server, but the silent failure mode is poor UX on any network.
  • Unrelated to the ANR/ReDoS fix in fix: prevent electrum connect ANR in url regex #1077 — this is a separate, pre-existing gap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions