Skip to content

feat: Export Static Channel Backup - #1387

Open
Jem256 wants to merge 3 commits into
jamaljsr:masterfrom
Jem256:scb-export
Open

feat: Export Static Channel Backup#1387
Jem256 wants to merge 3 commits into
jamaljsr:masterfrom
Jem256:scb-export

Conversation

@Jem256

@Jem256 Jem256 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Addresses part of #635

Description

This PR adds the export half of static channel backup (SCB) support for LND nodes, closing out the first part of #635. A user can now export a running LND (or litd) node's channel backup to disk from either the Actions tab or the node's right-click context menu, for later use in channel recovery testing. The restore half is intentionally out of scope and will follow in a separate PR.

Steps to Test

  1. Start a network with an LND node and open a channel
  2. Click "Export Channel Backup" from the Actions tab or Node Context Menu
  3. Confirm the written .backup file is byte-identical to the node's own channel.backup inside its Docker volume

Screenshots

image

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ef4324b) to head (fdc31a4).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1387   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          211       212    +1     
  Lines         7190      7232   +42     
  Branches      1447      1404   -43     
=========================================
+ Hits          7190      7232   +42     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Jem256
Jem256 marked this pull request as ready for review August 18, 2026 06:06
@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown

Greptile Summary

Adds static channel-backup export for running LND and litd nodes through the Actions tab and node context menu.

  • Adds the ExportAllChannelBackups LND RPC and Electron IPC path.
  • Adds a save-dialog, filesystem-write, notification, and localized UI flow.
  • Extends LightningService implementations and tests for supported and unsupported node types.

Confidence Score: 4/5

The PR should not merge until an absent LND backup payload is rejected instead of producing a successful zero-byte recovery file.

The export path currently turns missing multi-channel backup data into an empty buffer, writes it to disk, and reports success; the renderer also bypasses the repository’s required IPC boundary for native dialog and filesystem operations.

Files Needing Attention: src/lib/lightning/lnd/lndService.ts and src/store/models/lightning.ts

Important Files Changed

Filename Overview
src/lib/lightning/lnd/lndService.ts Extracts the multi-channel backup bytes but silently converts a missing payload into an empty successful export.
src/store/models/lightning.ts Implements save-dialog and file-writing orchestration, including direct privileged renderer access that violates the repository process boundary.
electron/lnd/lndProxyServer.ts Adds the ExportAllChannelBackups RPC handler and registers it with the existing LND IPC listener map.
src/components/designer/lightning/actions/ExportChannelBackupButton.tsx Adds button and context-menu variants with asynchronous success and error notifications.
src/components/designer/NodeContextMenu.tsx Exposes backup export for started LND and litd nodes without considering whether backup data exists.

Sequence Diagram

sequenceDiagram
  actor User
  participant UI as Export Button
  participant Store as Lightning Store
  participant Main as LND IPC Proxy
  participant LND
  participant Disk
  User->>UI: Export Channel Backup
  UI->>Store: exportChannelBackup(node)
  Store->>User: Show save dialog
  Store->>Main: exportAllChannelBackups
  Main->>LND: ExportAllChannelBackups
  LND-->>Main: ChanBackupSnapshot
  Main-->>Store: Backup bytes
  Store->>Disk: Write selected .backup file
  Store-->>UI: Selected file path
  UI-->>User: Export success notification
Loading

Reviews (1): Last reviewed commit: "feat(lnd): add channel backup export but..." | Re-trigger Greptile

Comment on lines +223 to +225
return Buffer.from(
(res.multiChanBackup?.multiChanBackup as unknown as Uint8Array) || [],
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Reject missing backup payloads

When LND omits multiChanBackup, this fallback converts the missing payload into an empty buffer; the store then writes a zero-byte .backup file and reports a successful export, leaving the user with an unusable recovery artifact.

Suggested change
return Buffer.from(
(res.multiChanBackup?.multiChanBackup as unknown as Uint8Array) || [],
);
const backup = res.multiChanBackup?.multiChanBackup;
if (!backup) {
throw new Error('No channel backup is available to export');
}
return Buffer.from(backup as unknown as Uint8Array);

}

const api = injections.lightningFactory.getService(node);
const backup = await api.exportChannelBackup(node);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Avoid privileged renderer access

This renderer-side store directly opens an Electron remote dialog and writes to the filesystem, bypassing the repository requirement that privileged operations cross the main-process IPC boundary. This couples the feature to renderer filesystem access and prevents it from working where remote or direct renderer access is disabled.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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.

1 participant