Introducing a new way to review your PRs.

Read the announcement

jamaljsr / polar

One-click Bitcoin Lightning networks for local app development & testing

View on GitHub

19 documents · Updated Oct 19, 2026

docs / lightning-service-capabilities

Lightning service capabilities

The Lightning service layer gives the rest of the application one way to work with LND, litd, c-lightning, and Eclair nodes. Each backend adapter calls the node's own service API and maps its reply to shared data. This keeps node details, peers, channels, invoices, and payments consistent for the network store and the designer.

Service selection

The service layer selects one adapter for each Lightning node. The selected adapter owns the backend call and hides differences in transport, authentication, response shape, and channel state names.

Adapter routing

The factory in home/…/lightningFactory.ts maps the node implementation to a service. LND and litd use the LND service because litd exposes the LND node interface used here. c-lightning and Eclair use their own services. A node must reach the adapter that matches its implementation.

References: src/…/lightningFactory.ts• L7-33 src/…/types.ts• L23-28 src/…/index.ts• L206-212

Common service boundary

The LightningService contract defines the operations that the network store can request without knowing the backend type. The contract covers node readiness, node and wallet data, peer links, channel actions, invoice actions, and channel event streams.

CapabilityShared result or inputSystem use
Node detailsIdentity, alias, chain state, block height, and channel countsShow node health and build peer addresses
Wallet dataTotal, confirmed, and unconfirmed balancesShow funds and support channel funding
Peer linksPublic key and addressConnect nodes before channel actions
ChannelsState, point, capacity, balances, peer, and privacyShow channels and calculate balance changes
Channel actionsChannel point for opening; success for closingChange the network graph
Invoices and paymentsBOLT11 invoice or payment receiptMove Lightning funds between nodes
EventsOpen, pending, closed, or unknown channel eventRefresh the network view

References: src/…/index.ts• L168-204 src/…/types.ts• L6-81

Shared data mapping

The adapters turn backend replies into the shared Lightning model. This mapping is the main boundary that lets higher layers use one set of names and states.

Node and wallet views

Each adapter returns the same node detail shape. It provides a public key, alias, public connection URL, chain sync state, block height, and active, pending, and inactive channel counts. Balance values use shared string fields for total, confirmed, and unconfirmed funds.

The balance source differs by backend. LND reads its wallet balance. c-lightning sums confirmed and unconfirmed outputs from its funds view. Eclair reads the wallet data from the Bitcoin service linked to the node and adds immature funds to the unconfirmed value. This difference matters when a caller requests a balance for Eclair.

References: src/…/types.ts• L6-25 src/…/lndService.ts• L12-37 src/…/clightningService.ts• L53-85 src/…/eclairService.ts• L34-63

Peer and channel views

Peer data is reduced to a public key and address. The adapters do not expose each backend's feature flags or peer state in the shared view. c-lightning returns only connected peers. LND and Eclair map the peers returned by their APIs.

Channel data uses one shared status set even though each backend reports different states. The adapters keep channels opened by the local node and omit closed channels from the active channel view. They return the channel point, peer key, capacity, local and remote balances, pending flag, and privacy flag.

The channel identifier used by the designer is a short, stable value derived from the backend channel point. The full channel point stays available for close actions. LND also reads optional TAP asset data from custom channel data and maps each asset to an ID, name, group key, capacity, two balances, and decimal count. c-lightning and Eclair return the base channel view without this asset data.

BackendChannel source ruleState mapping
LND and litdOpen channels plus locally opened pending channelsOpen, Opening, Closing, Force Closing, or Waiting to Close
c-lightningLocally opened channels that are not closedOpening, Open, Closing, Waiting to Close, Force Closing, or Closed
EclairLocally opened channels that are not closedOpening, Open, Closing, Closed, or Error

References: src/…/types.ts• L27-55 src/…/lndService.ts• L39-71 src/…/mappers.ts• L7-35 src/…/mappers.ts• L81-138 src/…/clightningService.ts• L34-45 src/…/clightningService.ts• L97-129 src/…/eclairService.ts• L11-31 src/…/eclairService.ts• L70-122

Backend adapters

Each adapter keeps backend access local to its service. The common model above is the product-facing view; the transport and auth choices below explain why the adapters are separate.

LND and litd adapter

The LND adapter uses an IPC proxy to reach LND operations and event streams. It supports the full common service boundary, including invoice decoding and optional TAP invoice data. Its channel mapper combines open and pending channel replies so the caller sees one channel list.

For an asset invoice, the adapter adds a route hint for the private asset channel. It first finds the asset channel and its policy, then includes that route data in the invoice request. This connects Lightning payment behavior to the TAP asset flow described in TAP asset services.

References: src/…/lndService.ts• L11-23 src/…/lndService.ts• L39-71 src/…/lndService.ts• L142-219 src/…/lndService.ts• L266-305 src/…/lndProxyClient.ts• L15-119

c-lightning adapter

The c-lightning adapter calls the local REST service with a rune in the request header. If the node has no rune, the readiness check creates one through the node's Docker container before normal requests continue. REST replies are converted from snake case to the shared property style.

The adapter uses a Socket.IO connection for channel events. It creates the connection from the same REST endpoint and caches it by REST port. Invoice decoding is not available through this adapter, so a decode request returns an explicit unsupported-operation error.

References: src/…/clightningApi.ts• L15-71 src/…/clightningApi.ts• L73-109 src/…/clightningService.ts• L121-145 src/…/clightningService.ts• L218-242 src/…/clightningService.ts• L293-342

Eclair adapter

The Eclair adapter sends authenticated REST requests through the application IPC HTTP path. It uses a WebSocket for channel events. Its channel mapping reads several Eclair response layouts so the same view works across supported Eclair versions.

Eclair does not expose a Lightning wallet balance through this service path. The adapter therefore requires the linked Bitcoin node and translates that wallet's balance into the common Lightning balance shape. Payment submission is asynchronous in Eclair, so the adapter checks payment status until it succeeds or reports the backend failure. Invoice decoding is not available through this adapter.

References: src/…/eclairApi.ts• L10-54 src/…/eclairApi.ts• L56-105 src/…/eclairService.ts• L51-68 src/…/eclairService.ts• L91-121 src/…/eclairService.ts• L201-249

Common operations

The network store calls the factory for each operation. The service handles the backend request, while the store coordinates Bitcoin confirmation, node wait time, chart refresh, and shared state updates.

Peer and channel lifecycle

Peer connection is a preparation step for opening a channel. Each adapter compares known peer keys with the requested node URLs and attempts only new connections. An open request then returns a transaction ID and output index as a common channel point. A close request receives the full channel point.

The store can fund the source node before opening a channel. After open or close, it mines confirmation blocks, waits for the affected nodes, and refreshes the designer graph. The adapter does not own this wider network sequence.

This diagram shows how a channel request crosses the common service boundary and then returns to shared network state.

sequenceDiagram
    participant Store as Lightning store
    participant Factory as Service factory
    participant Adapter as Backend adapter
    participant Node as Lightning node API
    participant Chain as Bitcoin network
    Store->>Factory: Select service for node implementation
    Factory->>Adapter: Open or close channel
    Adapter->>Node: Connect peer when needed
    Adapter->>Node: Send channel action
    Node-->>Adapter: Return channel point or result
    Adapter-->>Store: Return shared result
    Store->>Chain: Mine confirmation blocks when needed
    Store->>Adapter: Read channels again
    Adapter-->>Store: Return normalized channels
    Store->>Store: Refresh network graph

References: src/…/lndService.ts• L81-139 src/…/clightningService.ts• L131-179 src/…/eclairService.ts• L132-182 src/…/lightning.ts• L186-274

Invoice and payment lifecycle

Invoice creation accepts an amount in satoshis and returns a serialized BOLT11 invoice. Adapters convert the amount to the unit required by the backend. Payment returns a common receipt with the preimage, amount, and destination. An optional amount supports invoices that do not carry a fixed amount.

LND can decode an invoice before payment and can carry custom records for asset payments. c-lightning and Eclair can create and pay invoices but do not implement the shared decode operation. Eclair also needs a status check after it starts a payment because its payment call does not wait for completion.

After a successful payment, the store waits for Lightning nodes and refreshes the designer graph. The same invoice and payment operations support channel balance changes: the store creates an invoice on the target side and pays it from the source side.

This diagram shows the shared payment path and the backend-specific completion step.

sequenceDiagram
    participant Caller as Network store
    participant Adapter as Selected adapter
    participant Node as Lightning node API
    Caller->>Adapter: Create invoice
    Adapter->>Node: Request invoice in backend format
    Node-->>Adapter: Return BOLT11 invoice
    Adapter-->>Caller: Return invoice
    Caller->>Adapter: Pay invoice
    Adapter->>Node: Send payment
    alt Eclair
        Adapter->>Node: Poll payment status
    end
    Node-->>Adapter: Return payment result
    Adapter-->>Caller: Return receipt

References: src/…/index.ts• L181-197 src/…/lndService.ts• L142-219 src/…/clightningService.ts• L181-220 src/…/eclairService.ts• L185-245 src/…/lightning.ts• L276-297 src/…/lightning.ts• L450-493

Readiness and channel events

Readiness uses repeated info requests until the node responds or the wait limit ends. c-lightning also prepares its rune during this check. The store adds listeners for started network nodes and maps backend events to the shared Open, Pending, and Closed event types.

When a channel event arrives, the store waits for the node and throttles chart refreshes. Listener cleanup is part of node and network shutdown so cached sockets or event streams do not remain active.

References: src/…/lndService.ts• L221-264 src/…/clightningService.ts• L226-277 src/…/eclairService.ts• L251-301 src/…/lightning.ts• L316-377

Change checklist

When these files or sections are changed, remember to consider these:

  • Add a backend to LightningNode['implementation'], the factory map, and the service boundary together. A missing map entry can return no adapter even when the node type is accepted.
  • When a backend changes channel states or channel IDs, update its status map and the shared channel identifier used by channelsInfo and designer links.
  • When channel custom data changes, keep the LND asset mapper aligned with the TAP channel data version and the shared asset fields.
  • When invoice amount or payment options change, keep satoshi-to-millisatoshi conversion and optional invoice amounts aligned across all adapters.
  • When a backend changes its event transport, update listener setup, listener cleanup, and the store's channel-event refresh path as one change.
  • When Eclair balance behavior changes, keep the linked Bitcoin backend requirement and the common confirmed and unconfirmed balance meaning aligned.

Important failure modes

TriggerConsequenceGuard
A node implementation has no factory mappingStore calls cannot obtain a Lightning serviceAdd the implementation to the shared node type and LightningFactory map
A service receives a node for another backendThe adapter rejects the request instead of making a backend callSelect the service from the node implementation and preserve the adapter type check
c-lightning has no rune when a request startsREST calls cannot authenticateRun the c-lightning readiness path so it creates and saves the rune
Eclair balance lookup has no Bitcoin backendBalance retrieval fails before wallet data is returnedPass the node's linked Bitcoin backend to getBalances
Eclair payment never reaches a sent state within the poll limitPayment fails with the backend failure messageTreat the bounded status check as part of payment completion
A caller asks c-lightning or Eclair to decode an invoiceThe operation fails as unsupportedUse LND for decode or avoid this operation for those backends
An LND asset invoice has no matching asset channel or policyInvoice creation cannot build a route hintEnsure the asset channel and channel policy are available before creating the invoice

Key files

FileWhy to read it
src/…/index.tsDefines the common LightningService boundary used by the store and all adapters
src/…/lightningFactory.tsShows how a node implementation selects its adapter
src/…/types.tsDefines the shared node, balance, channel, peer, payment, and event shapes
src/…/lightning.tsShows how common operations become network actions and chart updates
src/…/lndService.tsShows the LND and litd capability set, including asset invoice support
src/…/mappers.tsShows how LND channel replies and TAP asset data become shared channel data
src/…/lndProxyClient.tsShows the LND request and event boundary
src/…/clightningService.tsShows c-lightning data mapping, channel operations, rune setup, and events
src/…/clightningApi.tsShows c-lightning REST auth and Socket.IO access
src/…/eclairService.tsShows Eclair data mapping, Bitcoin-backed balances, and payment polling
src/…/eclairApi.tsShows Eclair REST auth and WebSocket access