peer: send out a notification after the 1st conf, then wait for the rest

We wnt to add better handling, but not break any UIs or wallets. So
we'll continue to send out a notification after a single confirmation,
then send another after things are fully confirmed.
This commit is contained in:
Olaoluwa Osuntokun committed 2026-01-15 16:22:26 -08:00
1 parent c0f48d23b4
commit 6553b61aa4
1 file changed
+26 -17
+26 -17
View File
@@ -4471,19 +4471,27 @@ func (p *Brontide) finalizeChanClosure(chanCloser *chancloser.ChanCloser) {
localOut := chanCloser.LocalCloseOutput()
remoteOut := chanCloser.RemoteCloseOutput()
auxOut := chanCloser.AuxOutputs()
// Determine the number of confirmations to wait before
// signaling a successful cooperative close, scaled by
// channel capacity (see CloseConfsForCapacity).
numConfs := lnwallet.CloseConfsForCapacity(chanCloser.Channel().Capacity)
go WaitForChanToClose(
chanCloser.NegotiationHeight(), notifier, errChan,
&chanPoint, &closingTxid, closingTx.TxOut[0].PkScript, numConfs, func() {
// Respond to the local subsystem which requested the
// channel closure.
if closeReq != nil {
closeReq.Updates <- &ChannelCloseUpdate{
ClosingTxid: closingTxid[:],
// Determine the number of confirmations to wait before signaling a
// successful cooperative close, scaled by channel capacity (see
// CloseConfsForCapacity). Check if we have a config override for
// testing purposes.
chanCapacity := chanCloser.Channel().Capacity
numConfs := p.cfg.ChannelCloseConfs.UnwrapOrFunc(func() uint32 {
// No override, use normal capacity-based scaling.
return lnwallet.CloseConfsForCapacity(chanCapacity)
})
// Register for full confirmation to send the final update.
closeScript := closingTx.TxOut[0].PkScript
go WaitForChanToClose(
chanCloser.NegotiationHeight(), notifier, errChan,
&chanPoint, &closingTxid, closeScript, numConfs, func() {
// Respond to the local subsystem which requested the
// channel closure.
if closeReq != nil {
closeReq.Updates <- &ChannelCloseUpdate{
ClosingTxid: closingTxid[:],
Success: true,
LocalCloseOutput: localOut,
RemoteCloseOutput: remoteOut,
@@ -4500,15 +4508,16 @@ func (p *Brontide) finalizeChanClosure(chanCloser *chancloser.ChanCloser) {
// finally the callback will be executed. If any error is encountered within
// the function, then it will be sent over the errChan.
func WaitForChanToClose(bestHeight uint32, notifier chainntnfs.ChainNotifier,
errChan chan error, chanPoint *wire.OutPoint,
closingTxID *chainhash.Hash, closeScript []byte, numConfs uint32, cb func()) {
errChan chan error, chanPoint *wire.OutPoint,
closingTxID *chainhash.Hash, closeScript []byte, numConfs uint32,
cb func()) {
peerLog.Infof("Waiting for confirmation of close of ChannelPoint(%v) "+
"with txid: %v", chanPoint, closingTxID)
confNtfn, err := notifier.RegisterConfirmationsNtfn(
closingTxID, closeScript, numConfs, bestHeight,
)
confNtfn, err := notifier.RegisterConfirmationsNtfn(
closingTxID, closeScript, numConfs, bestHeight,
)
if err != nil {
if errChan != nil {
errChan <- err