Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions docs/release-notes/release-notes-0.17.11.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Release Notes

- [Lightning Terminal](#lightning-terminal)
- [Bug Fixes](#bug-fixes)
- [Functional Changes/Additions](#functional-changesadditions)
- [Technical and Architectural Updates](#technical-and-architectural-updates)
- [Integrated Binary Updates](#integrated-binary-updates)
- [LND](#lnd)
- [Loop](#loop)
- [Pool](#pool)
- [Faraday](#faraday)
- [Taproot Assets](#taproot-assets)
- [Contributors](#contributors-alphabetical-order)

## Lightning Terminal

### Bug Fixes

* [Fix integrated Loop and Pool closing LiT's shared lnd
connection](https://github.com/lightninglabs/lightning-terminal/pull/1459)
when they stop or hit a runtime error. Before, every other component
(macaroon service, tapd, faraday, accounts) then failed with `grpc: the
client connection is closing` even though lnd was healthy
([#1381](https://github.com/lightninglabs/lightning-terminal/issues/1381)).
Loop and Pool now only receive a non-closable view of the connection.

### Functional Changes/Additions

### Technical and Architectural Updates

* [Document the sub-server lnd connection ownership
model](https://github.com/lightninglabs/lightning-terminal/pull/1459) in
[`docs/subserver-connection-ownership.md`](../subserver-connection-ownership.md).

## RPC Updates

## Integrated Binary Updates

### LND

### Loop
* [PR](https://github.com/lightninglabs/lightning-terminal/pull/1459): Bump
`loop` to the connection-ownership fix
([loop#1272](https://github.com/lightninglabs/loop/pull/1272)).

### Pool
* [PR](https://github.com/lightninglabs/lightning-terminal/pull/1459): Bump
`pool` to the connection-ownership fix
([pool#528](https://github.com/lightninglabs/pool/pull/528)).

### Faraday

### Taproot Assets

# Contributors (Alphabetical Order)

126 changes: 126 additions & 0 deletions docs/subserver-connection-ownership.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Sub-server lnd connection ownership

This document describes how the single lnd connection inside `litd` is owned,
shared with the integrated sub-servers (Faraday, Loop, Pool, tapd), and shut
down. It is the authoritative reference for the connection-ownership model
that fixed the bug class reported in
[lightning-terminal#1381](https://github.com/lightninglabs/lightning-terminal/issues/1381#issuecomment-6530026672).

## The ownership model

`litd` creates exactly one `*lndclient.GrpcLndServices` (the shared lnd
connection) and is its sole owner. Only the owner may close it, and it does so
exactly once, in `shutdownSubServers` (`terminal.go`), after all sub-servers
have been stopped.

Integrated sub-servers never receive the closable wrapper. They receive a
**borrowed, non-closable view** (`*lndclient.LndServices`) through
`StartAsSubserver` and must never close it — with the type-level fix in
[loop#1272](https://github.com/lightninglabs/loop/pull/1272) and
[pool#528](https://github.com/lightninglabs/pool/pull/528), they cannot close
it even accidentally, because the `Close` method only exists on the wrapper,
which they never see. On the `litd` side, `subservers/loop.go` and
`subservers/pool.go` hand over that view as `&lndGrpc.LndServices`.

```mermaid
flowchart TD
subgraph LIT["lightning-terminal (litd) — OWNER"]
CREATE["setupFullLNDClient()<br/>creates the single shared<br/><b>*lndclient.GrpcLndServices</b><br/>(closable wrapper)"]
SHUTDOWN["shutdownSubServers()<br/>stops all sub-servers first,<br/>then closes the shared conn<br/><b>exactly once</b>"]
end

subgraph SUBSERVERS["integrated sub-servers — BORROWERS"]
FARADAY["Faraday<br/>reference model:<br/>lndOwned tracking"]
LOOP["Loop<br/>StartAsSubserver(<br/>*lndclient.LndServices)"]
POOL["Pool<br/>StartAsSubserver(<br/>*lndclient.LndServices)"]
TAPD["tapd<br/>never receives the wrapper"]
end

LND[("remote or integrated lnd")]

CREATE -- "gRPC conn + subserver clients" --> LND
CREATE -- "borrowed non-closable view<br/>(*lndclient.LndServices)" --> LOOP
CREATE -- "borrowed non-closable view" --> POOL
CREATE -- "borrowed view<br/>(lndOwned=false)" --> FARADAY
CREATE -- "services only" --> TAPD

LOOP -. "must never close<br/>(type-level: no Close in scope)" .-> LND
POOL -. "must never close<br/>(type-level: no Close in scope)" .-> LND
SHUTDOWN -- "the ONLY Close()<br/>on the shared conn" --> LND
```

## Lifecycle and failure mode

```mermaid
stateDiagram-v2
[*] --> ConnAlive: litd creates shared GrpcLndServices
ConnAlive --> SubserversRunning: litd injects borrowed view<br/>via StartAsSubserver
SubserversRunning --> SubserverStopped: a sub-server stops<br/>(graceful or runtime error)
SubserverStopped --> SubserversRunning: other sub-servers keep<br/>using the SAME conn
SubserversRunning --> ConnClosed: litd shutdownSubServers()<br/>after ALL sub-servers stopped
ConnClosed --> [*]

note right of SubserverStopped
INVARIANT: a sub-server stopping
must NOT close the shared conn.
Pre-fix, loop/pool violated this:
every other component then failed
with "grpc: the client connection
is closing" while remote lnd
stayed healthy.
end note
```

### The bug that motivated this model

Before the fix, an embedded Loop daemon closed the shared connection on
**any** shutdown — graceful `Stop()` or a runtime error — and an embedded Pool
server did the same in `Server.Stop()`. The moment one sub-server stopped, the
connection every other component depends on was torn down: the LiT macaroon
service (`signrpc.DeriveSharedKey`), tapd, faraday and accounts all failed
with `grpc: the client connection is closing`, while the remote lnd itself was
perfectly healthy. In the reported incident (litd v0.17.8, remote lnd
v0.21.4-beta), this happened 12ms after "Starting LiT macaroon service".

### Historical note: Faraday's `lndOwned` flag

Faraday was the reference model for the first layer of the fix: it tracks
whether it created the connection itself (`lndOwned`, set in `Start`) and only
closes the connection when it owns it. Loop and Pool now go one step further
with **type-level prevention**: instead of a runtime flag, they hold the
closable wrapper only in a dedicated owner field (`lndOwner`, non-nil only in
standalone mode), and their `StartAsSubserver` entry points accept only the
non-closable `*lndclient.LndServices` view. Borrowed-ness is thereby
unrepresentable — enforced by the type checker, not by convention.

## The rules

1. `litd` owns the shared `GrpcLndServices` and closes it exactly once, in
`shutdownSubServers`, after all sub-servers are stopped.
2. Sub-servers receive a borrowed, non-closable view via `StartAsSubserver`.
They must never close the connection — and cannot, by construction.
3. Standalone daemons (loopd, poold, faraday running alone, or the loop
`view` command) create their own connection and close it when done.
4. A sub-server that needs to signal a fatal error reports it to the parent
(e.g. Loop's `ErrChan`) — it never "cleans up" shared state itself.

## Verification

The ownership model is enforced mechanically on three levels, so this bug
class cannot silently recur:

- **Type level (compile time):** `StartAsSubserver` in Loop and Pool accepts
only the non-closable `*lndclient.LndServices`. The closable wrapper exists
in the sub-server packages only as the `lndOwner` field, set solely on the
standalone path. Judge: the type checker.
- **Regression tests:** `loopd/daemon_ownership_test.go` and
`server_ownership_test.go` (pool) start an embedded daemon/server against a
real (bufconn) gRPC connection and assert the injected `grpc.ClientConn`
does not enter `Shutdown` state after a graceful stop or a runtime-error
stop. Both tests were demonstrated to fail on the pre-fix code.
- **Static guard:** `loopd/ownership_guard_test.go` and
`server_ownership_guard_test.go` (pool) parse the package AST in CI (as
ordinary unit tests) and fail if any `.Close()` call targets an lnd
connection handle outside the whitelisted owner sites, or if
`StartAsSubserver` ever accepts the closable wrapper again. Both guards were
demonstrated to fail on the pre-fix code.
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,9 @@ tool github.com/lightninglabs/taproot-assets/cmd/tapcli

// Use the locally patched TLV module until the upstream fix is released.
replace github.com/lightningnetwork/lnd/tlv => ./third_party/lnd/tlv

// NOTE: drop these and bump to tagged releases once loop#1272 and
// pool#528 are merged and tagged. Until then, pin the connection-ownership fix
// backported onto the currently pinned loop v0.35.2-beta / pool v0.7.2-beta.
replace github.com/lightninglabs/loop => github.com/litbot-9000/loop v0.32.1-beta.0.20261030222623-d72d75fb1ca1
replace github.com/lightninglabs/pool => github.com/litbot-9000/pool v0.7.2-beta.0.20261030222405-5b777bbd9744
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,6 @@ github.com/lightninglabs/lightning-node-connect/mailbox v1.0.2-0.20260727084653-
github.com/lightninglabs/lightning-node-connect/mailbox v1.0.2-0.20260727084653-785ec57e5d1d/go.mod h1:7VXY4plpd6U+0wJa47OsaGg1bTXVdWO6NLHY8olKHwQ=
github.com/lightninglabs/lndclient v0.21.0-2 h1:gA1utFMoKV6OZfHpYAQ1TX0wVs5cAtgTORRVavHR/ls=
github.com/lightninglabs/lndclient v0.21.0-2/go.mod h1:RUIcfPr82HrvZr3pu9f8nbD5v6VFbm+KgExqNNp5bE4=
github.com/lightninglabs/loop v0.35.2-beta h1:kPDn4e7PwMd0FuB8iNm0lrqB1KFc3YA67p8rSMTtv80=
github.com/lightninglabs/loop v0.35.2-beta/go.mod h1:1kM8+JiLhR2SpMIFM8TzhdNWvYrv9an2zp2zike1GTw=
github.com/lightninglabs/loop/looprpc v1.0.17 h1:FblJqdD+S0+Toc5U16AWlgBuxmgIXOO5WbJpFHrDj1g=
github.com/lightninglabs/loop/looprpc v1.0.17/go.mod h1:MGG6KZumEQMTIFWmLiOu5EEZSi8VGYnRuH6emEJoAfk=
github.com/lightninglabs/loop/swapserverrpc v1.0.22 h1:NT6MLJ6ZryFzYPboFoJePX0fSw9Uvr3PmA/frB++o34=
Expand All @@ -1161,8 +1159,6 @@ github.com/lightninglabs/neutrino v0.17.1 h1:lNhgq7ix/N81R6oATroP/kHMzH1qzVVF2dE
github.com/lightninglabs/neutrino v0.17.1/go.mod h1:tcwCgRTGWcaua0L/xzdwllW8eslHDbux4XkiYsivvHE=
github.com/lightninglabs/neutrino/cache v1.1.3 h1:rgnabC41W+XaPuBTQrdeFjFCCAVKh1yctAgmb3Se9zA=
github.com/lightninglabs/neutrino/cache v1.1.3/go.mod h1:qxkJb+pUxR5p84jl5uIGFCR4dGdFkhNUwMSxw3EUWls=
github.com/lightninglabs/pool v0.7.2-beta h1:aI6FG/sfpx2XQIZdHve5+bX9ZeMNz4InmiBZfc/uHWw=
github.com/lightninglabs/pool v0.7.2-beta/go.mod h1:Ttiqa41jcABQp8CmEVpcib+o5PJdaQov8o3Nqj4ZTDE=
github.com/lightninglabs/pool/auctioneerrpc v1.1.3 h1:Di5Nf8Gll9wl6tbXsusGXj9e4yNsHvoJ0ssgoHyFXqY=
github.com/lightninglabs/pool/auctioneerrpc v1.1.3/go.mod h1:N/X9SxrBCjquK8XkwSgk4qvGC2g8Dra9uiw5sXWmEl0=
github.com/lightninglabs/pool/poolrpc v1.0.1 h1:XbNx28TYwEj/PVsnnF9TnveVCMCYfS1vVkcwz29vPmM=
Expand Down Expand Up @@ -1201,6 +1197,10 @@ github.com/lightningnetwork/lnd/ticker v1.1.1 h1:J/b6N2hibFtC7JLV77ULQp++QLtCwT6
github.com/lightningnetwork/lnd/ticker v1.1.1/go.mod h1:waPTRAAcwtu7Ji3+3k+u/xH5GHovTsCoSVpho0KDvdA=
github.com/lightningnetwork/lnd/tor v1.1.7 h1:BfY1KQGz3LVaeaAGI4XYGYCwDQR1ADFD1P/uXsS2dQc=
github.com/lightningnetwork/lnd/tor v1.1.7/go.mod h1:DANQ6QCQBiR+CqrM+mKudgkMy6CR/RS4ALDbjb2W4FU=
github.com/litbot-9000/loop v0.32.1-beta.0.20261030222623-d72d75fb1ca1 h1:RJlFNjmnHryY8uE+tXrcvWHhOgOS4mHQytF/mrzrcoo=
github.com/litbot-9000/loop v0.32.1-beta.0.20261030222623-d72d75fb1ca1/go.mod h1:1kM8+JiLhR2SpMIFM8TzhdNWvYrv9an2zp2zike1GTw=
github.com/litbot-9000/pool v0.7.2-beta.0.20261030222405-5b777bbd9744 h1:/89AVeNYg8dxDZT3RgsmFuB/Yu85p1h+b8z0Icx7j8o=
github.com/litbot-9000/pool v0.7.2-beta.0.20261030222405-5b777bbd9744/go.mod h1:Ttiqa41jcABQp8CmEVpcib+o5PJdaQov8o3Nqj4ZTDE=
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 h1:sjOGyegMIhvgfq5oaue6Td+hxZuf3tDC8lAPrFldqFw=
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796/go.mod h1:3p7ZTf9V1sNPI5H8P3NkTFF4LuwMdPl2DodF60qAKqY=
github.com/ltcsuite/ltcutil v0.0.0-20181217130922-17f3b04680b6/go.mod h1:8Vg/LTOO0KYa/vlHWJ6XZAevPQThGH5sufO0Hrou/lA=
Expand Down
4 changes: 3 additions & 1 deletion subservers/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func (l *loopSubServer) RemoteConfig() *RemoteDaemonConfig {
func (l *loopSubServer) Start(_ lnrpc.LightningClient,
lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool) error {

return l.StartAsSubserver(lndGrpc, withMacaroonService)
// Loop only borrows the shared lnd connection, so it gets the
// non-closable view. LiT owns the connection and closes it on shutdown.
return l.StartAsSubserver(&lndGrpc.LndServices, withMacaroonService)
}

// Stop stops the sub-server in integrated mode.
Expand Down
6 changes: 5 additions & 1 deletion subservers/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ func (p *poolSubServer) RemoteConfig() *RemoteDaemonConfig {
func (p *poolSubServer) Start(lnClient lnrpc.LightningClient,
lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool) error {

return p.StartAsSubserver(lnClient, lndGrpc, withMacaroonService)
// Pool only borrows the shared lnd connection, so it gets the
// non-closable view. LiT owns the connection and closes it on shutdown.
return p.StartAsSubserver(
lnClient, &lndGrpc.LndServices, withMacaroonService,
)
}

// RegisterGrpcService must register the sub-server's GRPC server with the given
Expand Down
Loading