Repository navigation
Conversation
In this commit, we add a Done() method to StateMachine that returns its internal quit channel. Downstream observers and lifecycle sentinels can now select on Done() so they exit promptly when the state machine stops instead of waiting on a peer disconnect.
In this commit, we add LocalCloseReq and CancelPendingOffer events to the RBF cooperative close state machine so local close and fee bump requests are valid in every state without out-of-band state polling. Requests arriving in ShutdownPending or ChannelFlushing are buffered as PendingBump and applied as soon as ChannelFlushed fires, ensuring explicit fee bumps that exceed local balance transition into CloseErr rather than silently skipping. Requests arriving while LocalOfferSent awaits the remote party's signature are buffered as PendingOffer and emitted immediately after LocalSigReceived completes the round and refreshes any taproot closee nonce. If a caller cancels before a buffered bump starts, CancelPendingOffer retracts only the matching sequence.
In this commit, we remove waitUntilRbfCoastClear and the CurrentState switch from startRbfChanCloser, sending LocalCloseReq directly into the RBF state machine so the peer's channelManager goroutine never blocks on a remote-controlled close state or ignores caller cancellation (fixing lightningnetwork#11571). We also generalize chanFlushEventSentinel into rbfCloserLifecycleSentinel, registered before the state machine starts, so every RBF closer tears down its router endpoint, RBF actor, activeChannels entry, and switch link once CloseFin is reached for both local and remote-initiated closes (fixing lightningnetwork#11488).
In this commit, we have maybeNotifyTxBroadcast return whether it reported a CloseErr so observeRbfCloseUpdatesWithSeq exits immediately instead of lingering until RPC cancel and emitting a late CancelPendingOffer. We also extract shared helpers for pending close buffering and LocalCloseStart transitions.
In this commit, we update chanErrorReporter.ReportError to retire the failed closer from activeChanCloses and abort any callers in activeCloseReqs with the FSM error before re-initializing a replacement closer, preventing waiting RPC callers from hanging when observeRbfCloseUpdatesWithSeq exits on Done(). We also check closer pointer identity and liveness in startRbfChanCloser's post-add recheck so a caller cannot bind to a stopped or replaced closer.
In this commit, we add the release note fragment for PR lightningnetwork#11575 covering the RBF cooperative close bump buffering and CloseFin teardown fixes.
litbot-9000
left a comment
There was a problem hiding this comment.
/gateway review
Approve. This is a substantial FSM/concurrency change and it holds up under close reading. The two core problems are genuinely gone, by construction rather than by patch-over:
- No more channelManager stall:
waitUntilRbfCoastClearand the out-of-bandCurrentState()switch are deleted outright.LocalCloseReqis now a first-class event valid in every state, so a bump in ShutdownPending/ChannelFlushing buffers as a Seq-taggedPendingBump(applied onChannelFlushed, preferred over the ideal fee rate), a bump in LocalOfferSent buffers asPendingOffer(emitted as an internalSendOfferEventright afterLocalSigReceivedcompletes the round), and LocalCloseStart/ClosePending/CloseErr act immediately. - Unified CloseFin teardown: the lifecycle sentinel retires the closer from
activeChanCloses, delivers success, thenWipeChannels — in that order, so a concurrent caller can't register after takeAll and strand. The newprotofsm.StateMachine.Done()plusp.cg.Done()give the sentinel clean exits, and the flush hook is registered with the peer-lifetime context (consistent with the hook lifetime semantics from #11483).
Edges I checked specifically: taproot RemoteCloseeNonce is updated from the completing round's ClosingSig before a buffered offer is emitted, so the next offer uses the fresh nonce; CancelPendingOffer retracts only a Seq-matching unstarted bump; ReportError captures the chanPoint and aborts waiting callers with the FSM error before re-initializing, and isSameLiveRbfCloser prevents binding to a stopped/replaced closer.
Verified by execution: go test -race -count=1 ./protofsm/... ./lnwallet/chancloser/... ./peer/... — all green with the race detector. The nine new tests map to the PR's claims (buffering across states, restored-shutdown bump, channelManager staying free, caller-cancel retraction, CloseFin teardown, CloseErr no-leak, ReportError answering callers, identity guard). Mutation check: disabling the PendingBump buffering fails TestRbfLocalCloseReqBuffering, so the coverage bites. gofmt/vet clean; the long lines are all nolint:ll-approved. Release note present.
Not verified: itests (no Docker here) — the two make itest cases in the PR's test plan are CI-covered.
Note: the failing "CI result" check is the ci-hold label on this PR, not the code.
— claudell ⚡ (OpenClaw dev agent; approval posts as litbot-9000 and does not count toward branch protection)
There was a problem hiding this comment.
Walked through the FSM transitions and peer lifecycle changes and ran go test -race -count=1 ./protofsm/... ./lnwallet/chancloser/... ./peer/... locally. The in-FSM buffering and CloseFin sentinel cleanup look really clean.
A few small questions on peer/brontide.go in case these edge cases matter:
startRbfChanCloser(peer/brontide.go:5069-5091): I seecoopCloseStates := rbfCloser.RegisterStateEvents()(L5050) is registered beforeSendEventso fast transitions aren't missed, which makes sense. Ifreq.Ctxis already cancelled whenstartRbfChanCloserruns, could spawningobserveRbfCloseUpdatesWithSeq(L5072) beforerbfCloser.SendEvent(sendCtx, &chancloser.LocalCloseReq{..., Seq: bumpSeq})(L5087) let the observer hit<-closeReq.Done()and sendCancelPendingOffer{Seq: bumpSeq}beforeSendEventruns? SinceStateMachine.SendEventselects betweens.events <- event(buffered size 1) and<-ctx.Done(), it looks likeSendEventcould still enqueueLocalCloseReqafterCancelPendingOfferwas already processed as a no-op.chanErrorReporter.ReportError(peer/brontide.go:4606-4646): PullingactiveChanCloses.LoadAndDelete(c.chanID)(L4607) up beforeabortRemainingCloseReqs(L4608) makes sense so concurrent callers can't bind to the failing closer while it's being retired. Sincec.chanIDis already removed fromactiveChanClosesatL4607, ifDisconnect()runs concurrently betweenLoadAndDeleteandinitRbfChanCloser(lnChan)(L4646),abandonChanCloserswon't see this channel, soinitRbfChanClosercould still start a new closer and callp.cg.WgAdd(1)afterp.cg.Quit(). Would it be worth guarding the re-init onc.peer.cg.Done()?observeRbfCloseUpdatesWithSeq(peer/brontide.go:4499-4505): I sawTestRbfCloseErrDoesNotLeakOnRetrycovers exiting the first observer onCloseErr(localDone) so its later cancellation doesn't re-emitClosingNegotiationand leakCloseErrto a retry caller. BecauseClosingNegotiationis a dual state andLocalstays in*chancloser.CloseErruntil a newLocalCloseReqarrives, what happens if a remoteOfferReceivedEventarrives after caller 2 registerscoopCloseStatesbut before caller 2'sLocalCloseReqis processed? It looks like that transition would still carryLocal: CloseErrand triggerlocalDoneon caller 2's observer (or on an earlier caller waiting for a broadcastClosePendingtx to confirm if a second caller's bump hitsCloseErr). Not sure if that's expected in practice or ifCloseErrshould only be consumed once.
Change Description
In this PR, we resolve #11571 and #11488 by moving RBF cooperative close bump serialization and buffering directly into the
RbfChanCloserstate machine and unifyingCloseFinchannel+link teardown under a single per-closer lifecycle observer.Previously,
startRbfChanCloserinspectedCurrentState()out of band and branched on it: bumps arriving inShutdownPendingorChannelFlushingfell through to a warning log and were silently dropped, while bumps inClosingNegotiationblocked the peer'schannelManagergoroutine insidewaitUntilRbfCoastClearusing the peer's lifetime context rather than the caller's, stalling other peer operations (and hanging forever inLocalCloseStart,CloseErr, orLocalOfferSentwithout a peer reply).We eliminate
waitUntilRbfCoastClearand theCurrentState()switch entirely. Instead,startRbfChanClosersends a single non-blockingLocalCloseReqevent into the state machine, which every state handles deterministically:ShutdownPendingandChannelFlushing, an incoming bump is buffered inPendingBumpand applied as soon asChannelFlushedfires (transitioning intoCloseErrif an explicit bump exceeds local balance, while preservingLocalCloseStartwhen an unpayable initial close waits for the remote party).LocalOfferSent, a bump is buffered inPendingOfferand emitted as an internalSendOfferEventright afterLocalSigReceivedcompletes the active round and updatesRemoteCloseeNoncefor taproot channels.LocalCloseStart,ClosePending, andCloseErr,LocalCloseReqtriggers a new offer right away.If an RPC caller cancels before a buffered bump starts,
observeRbfCloseUpdatesWithSeqemits a sequence-taggedCancelPendingOfferso only that unstarted request is retracted. WhenmaybeNotifyTxBroadcastreports aCloseErr, the observer exits right away instead of lingering until context cancellation. On fatal FSM errors,chanErrorReporter.ReportErrorretires the failed closer fromactiveChanClosesand aborts waiting callers inactiveCloseReqswith the FSM error before re-initializing, andstartRbfChanCloserchecks closer pointer identity and liveness (isSameLiveRbfCloser) so a caller cannot bind to a stopped or replaced closer.For #11488, we add
Done()onprotofsm.StateMachineand generalizechanFlushEventSentinelintorbfCloserLifecycleSentinel, registered before the state machine starts ininitRbfChanCloser. OnceCloseFinis reached (whether locally initiated, remote initiated, or restored), the sentinel retires the closer fromactiveChanCloses, delivers success to any waiting RPC callers, and callsWipeChannelto remove the channel fromactiveChannelsand stop its link in the switch.Steps to Test
Fixes #11571
Fixes #11488