Skip to content

Auto-reconnect Lightning peers and document service management#1

Merged
refined-element merged 4 commits into
mainfrom
feature/persistent-ln-peers-and-service-management
Apr 29, 2026
Merged

Auto-reconnect Lightning peers and document service management#1
refined-element merged 4 commits into
mainfrom
feature/persistent-ln-peers-and-service-management

Conversation

@refined-element
Copy link
Copy Markdown
Owner

Summary

  • Auto-reconnect Lightning peers: New persistent_peers config in [lightning]. A reconnector ticks every 60s and dials any listed peer that's not currently connected. Solves the "LN channel goes dark after a reboot or transient TCP drop" problem.
  • Service management docs: README gains Stop and Auto-Start sections (macOS launchd + Linux systemd) so non-AI users can run the node as a service. A template launchd plist lands in config/com.bitcoinwolfe.node.plist.

Why

The Lightning node had no mechanism to keep critical peer connections alive after a disconnect. If LDK lost the TCP connection to a counterparty, the channels stayed open on-chain but became is_usable: false until a manual ln_connect. This was hit in practice after an OS update reboot — the channel partner's address wasn't stored anywhere, so reconnection required AI assistance to look up the IP.

The reconnector fixes the reconnection loop. The README/launchd docs fix the bootstrap loop.

Implementation

Reconnector (crates/wolfe-node/src/main.rs):

  • After the LDK background processor starts, spawn a task that ticks every 60s.
  • Each tick: snapshot peer_manager().list_peers() into a HashSet<PublicKey>, then iterate config peers and dial any not in the set.
  • Hostnames are re-resolved every tick (via ToSocketAddrs) so DHCP/DNS churn on the LAN doesn't permanently break reconnection.
  • Connect failures log at debug! (silent retries) since the next tick will try again; only invalid config entries warn.
  • A new parse_ln_peer helper splits pubkey@host:port into (PublicKey, SocketAddr).

Config (crates/wolfe-types/src/config.rs):

  • Add persistent_peers: Vec<String> to LightningConfig with sensible default (empty).

Service management:

  • config/com.bitcoinwolfe.node.plist: Template plist with __WOLFE_BINARY__ / __WOLFE_DIR__ placeholders. KeepAlive with SuccessfulExit=false means launchd restarts on crashes but respects intentional stop. ThrottleInterval=10 prevents tight crash loops.
  • README Stop section: Ctrl+C, JSON-RPC stop, kill, dashboard Settings page — all converge on the same graceful shutdown path.
  • README Auto-Start sections: step-by-step for macOS (launchctl load) and Linux (systemctl enable).

Test plan

  • cargo build --release -p wolfe-node — clean build
  • cargo clippy --release -p wolfe-node -p wolfe-types -- -D warnings — clean
  • Live verification: started node with persistent_peers = ["02acb60b...@host:9735"], observed persistent Lightning peer reconnector started log, killed peer connection, watched it reconnect on the next tick. Lightning info reported num_peers: 1 and channels became is_usable: true automatically.
  • launchd plist verified: installs to ~/Library/LaunchAgents/, starts on login, restarts on crash, respects RPC stop.

🤖 Generated with Claude Code

The Lightning node had no way to keep critical peer connections alive
after a TCP drop — once a peer disconnected, channels became unusable
until the user manually called ln_connect again. This is the same gap
that left an LN channel offline after a recent reboot even though both
nodes were healthy.

Add a persistent_peers config field on LightningConfig listing peers
the node should keep connected (pubkey@host:port). On startup, after
the LDK background processor is running, spawn a reconnector that
ticks every 60s, walks the peer list, and dials any persistent peer
not currently in peer_manager().list_peers(). Hostnames are resolved
on each tick so DHCP/DNS changes on the LAN don't permanently break
reconnection.

Also document service management since users without an AI assistant
need to know how to start and stop the node:

- README gains a Stop section (Ctrl+C, RPC stop, kill, dashboard
  Settings page) and Auto-Start sections for macOS launchd and Linux
  systemd.
- A template launchd plist lands in config/com.bitcoinwolfe.node.plist
  with placeholder paths for the user to fill in. The plist uses
  KeepAlive with SuccessfulExit=false so launchd restarts the node on
  crashes but respects intentional shutdowns.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 27, 2026 07:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a Lightning “persistent peers” feature to automatically re-establish configured LN peer connections, and expands the README with service-management guidance (launchd/systemd) plus a launchd plist template.

Changes:

  • Add [lightning].persistent_peers config and default it to empty.
  • Spawn a periodic Lightning peer reconnector task that dials configured peers not currently connected.
  • Add service-management documentation (stop + auto-start) and include a macOS launchd plist template.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
crates/wolfe-types/src/config.rs Adds persistent_peers to LightningConfig and defaults it.
crates/wolfe-node/src/main.rs Implements the periodic LN peer reconnector and adds parse_ln_peer.
config/com.bitcoinwolfe.node.plist Adds a launchd template for running the node as a macOS user service.
README.md Documents stop methods and auto-start setup for macOS (launchd) and Linux (systemd).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread config/com.bitcoinwolfe.node.plist Outdated
Comment thread crates/wolfe-types/src/config.rs Outdated
Comment thread crates/wolfe-node/src/main.rs Outdated
Comment thread crates/wolfe-node/src/main.rs Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md
refined-element and others added 3 commits April 28, 2026 21:31
- Handle SIGTERM alongside SIGINT/Ctrl+C so kill, systemctl stop, and
  launchctl unload all exit through the same graceful shutdown path.
- Resolve persistent peer hostnames with tokio::net::lookup_host to keep
  blocking DNS off the runtime workers.
- Validate persistent_peers pubkeys once at startup; invalid entries are
  logged once and skipped instead of warning every 60s.
- Move the launchd plist log path out of data/ so a fresh install doesn't
  fail before the binary creates that directory.
- README: document SIGTERM as a graceful stop, correct LaunchAgents to
  run on login (not boot) with a LaunchDaemons pointer, and add
  TimeoutStopSec=30 to the systemd example so Lightning state can persist.
- Update the persistent_peers doc comment to reflect the ongoing
  reconnect behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Threads a `picture` field through NostrConfig and the NostrBridge so it
shows up in the published kind-0 metadata event. Invalid URLs are warned
once and skipped rather than failing the whole metadata publish.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
cargo fmt --check on the prior commits flagged two long error!() calls
and clippy was hitting too_many_arguments after the picture field was
added to NostrBridge::new (8 args, default threshold is 7).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@refined-element refined-element merged commit e2e1043 into main Apr 29, 2026
1 check failed
@refined-element refined-element deleted the feature/persistent-ln-peers-and-service-management branch April 29, 2026 01:42
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.

2 participants