lnd/peer
Olaoluwa Osuntokun e5e134ddac peer+lnwallet/chancloser: advance the legacy closer from one goroutine
In this commit, we give the legacy ChanCloser a single owner, rather than
letting two goroutines advance it. The peer's channelManager drives the state
machine for the Shutdown and ClosingSigned messages that come off the wire, and
for local close requests. The link drives it as well: while we wait for the
channel to drain we register a flush hook, and the link invokes that hook from
its own goroutine, where it called BeginNegotiation directly. Nothing kept the
two apart, so the state field, the priorFeeOffers map, and the signing step
could all be touched at once. Under `go test -race` this shows up as a data race
on the state field.

Rather than reach for a lock, we route the flush through the channelManager. The
hook now only reports the channel ID over a new chanCloseFlushed channel, and
handleChanFlushed picks it up next to the close messages. Every transition, the
cached offer processing, the fee map, and the signing then happen on the one
goroutine, so the closer needs no synchronization of its own. We spell that out
on the type, since it's an invariant a new caller can break from the outside.

The report goes out from a fresh goroutine, which matters more than it looks.
The link may well be holding its own lock while it invokes the hook, and
channelManager reaches for that same lock in DisableAdds, so blocking on the
handoff would trade the race for a deadlock. The `go` in front of RemoveLink
just above it is there for the same reason.

We look the closer up with a plain map load rather than through
fetchActiveChanCloser, as that one builds a fresh closer when it doesn't find
an existing one, and a flush that lands after the negotiation was torn down has
no business starting a new negotiation.

One behavior change falls out of the move: the flush path now runs the same
finalization tail as the message path. It skipped that before, so a responder
that drained a cached offer would reach closeFinished and broadcast, but nothing
ran finalizeChanClosure until the next close message showed up, and having
already sent its final signature, there may not be one. The link == nil path
already ran the tail, so this makes all three paths agree.

The new test drives a close with a link that hands us the flush hook instead of
running it inline, so we can check that negotiation waits on the report, and
that a report for a channel we have no closer for is dropped.
2026-08-05 12:22:56 -07:00
..
brontide.go peer+lnwallet/chancloser: advance the legacy closer from one goroutine 2026-08-05 12:22:56 -07:00
brontide_test.go peer+lnwallet/chancloser: advance the legacy closer from one goroutine 2026-08-05 12:22:56 -07:00
chan_observer.go multi: upgrade to btcd v2 modules 2026-06-24 10:58:36 -07:00
daemon_adapters.go multi: upgrade to btcd v2 modules 2026-06-24 10:58:36 -07:00
interfaces.go peer+lnwire: move LinkUpdater to lnwire 2024-03-06 11:59:19 -08:00
log.go multi: start updating various loggers to use the new v2 type 2024-10-22 17:03:55 +02:00
musig_chan_closer.go multi: add custom nonce rand support to MuSig2 sessions 2026-04-13 12:21:42 -07:00
musig_nonce_order_test.go multi: upgrade to btcd v2 modules 2026-06-24 10:58:36 -07:00
onion_ratelimit.go lncfg+peer+server: add protocol.onion-msg-relay-all to bypass channel gate 2026-04-15 13:23:50 -07:00
onion_ratelimit_log_test.go peer: gate onion message ingress on having an open channel 2026-04-15 13:23:50 -07:00
onion_ratelimit_test.go lncfg+peer+server: add protocol.onion-msg-relay-all to bypass channel gate 2026-04-15 13:23:50 -07:00
ping_manager.go peer+lnd: add new CLI option to control if we D/C on slow pongs 2025-05-15 16:36:38 +02:00
ping_manager_test.go peer+lnd: add new CLI option to control if we D/C on slow pongs 2025-05-15 16:36:38 +02:00
rbf_close_wrapper_actor.go peer: never use RBF coop close for aux channels 2026-07-14 13:24:33 -02:30
rbf_close_wrapper_actor_test.go multi: upgrade to btcd v2 modules 2026-06-24 10:58:36 -07:00
setup_test.go multi: use MakeTestGraph everywhere for test graph creation 2025-05-22 14:14:42 +02:00
test_utils.go peer+lnwallet/chancloser: advance the legacy closer from one goroutine 2026-08-05 12:22:56 -07:00