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() localOut := chanCloser.LocalCloseOutput()
remoteOut := chanCloser.RemoteCloseOutput() remoteOut := chanCloser.RemoteCloseOutput()
auxOut := chanCloser.AuxOutputs() 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( // Determine the number of confirmations to wait before signaling a
chanCloser.NegotiationHeight(), notifier, errChan, // successful cooperative close, scaled by channel capacity (see
&chanPoint, &closingTxid, closingTx.TxOut[0].PkScript, numConfs, func() { // CloseConfsForCapacity). Check if we have a config override for
// Respond to the local subsystem which requested the // testing purposes.
// channel closure. chanCapacity := chanCloser.Channel().Capacity
if closeReq != nil { numConfs := p.cfg.ChannelCloseConfs.UnwrapOrFunc(func() uint32 {
closeReq.Updates <- &ChannelCloseUpdate{ // No override, use normal capacity-based scaling.
ClosingTxid: closingTxid[:], 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, Success: true,
LocalCloseOutput: localOut, LocalCloseOutput: localOut,
RemoteCloseOutput: remoteOut, 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 // finally the callback will be executed. If any error is encountered within
// the function, then it will be sent over the errChan. // the function, then it will be sent over the errChan.
func WaitForChanToClose(bestHeight uint32, notifier chainntnfs.ChainNotifier, func WaitForChanToClose(bestHeight uint32, notifier chainntnfs.ChainNotifier,
errChan chan error, chanPoint *wire.OutPoint, errChan chan error, chanPoint *wire.OutPoint,
closingTxID *chainhash.Hash, closeScript []byte, numConfs uint32, cb func()) { closingTxID *chainhash.Hash, closeScript []byte, numConfs uint32,
cb func()) {
peerLog.Infof("Waiting for confirmation of close of ChannelPoint(%v) "+ peerLog.Infof("Waiting for confirmation of close of ChannelPoint(%v) "+
"with txid: %v", chanPoint, closingTxID) "with txid: %v", chanPoint, closingTxID)
confNtfn, err := notifier.RegisterConfirmationsNtfn( confNtfn, err := notifier.RegisterConfirmationsNtfn(
closingTxID, closeScript, numConfs, bestHeight, closingTxID, closeScript, numConfs, bestHeight,
) )
if err != nil { if err != nil {
if errChan != nil { if errChan != nil {
errChan <- err errChan <- err