From 8c064b86f182b1d1f88c9632fac2fcd3f5a27306 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 7 Feb 2024 12:45:33 +0200 Subject: [PATCH] peer: call DisableAdds before link.OnCommitOnce This commit moves calls to link.DisableAdds to outside link.OnCommitOnce call backs. This is done so that if a user requests shutdown, then we can immediately block any new outgoing HTLCs. It's only the sending of the Shutdown message that needs to wait until after any pending CommitSig message is sent. --- peer/brontide.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/peer/brontide.go b/peer/brontide.go index 22841df11..c15845d93 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -2990,12 +2990,12 @@ func (p *Brontide) handleLocalCloseReq(req *htlcswitch.ChanClose) { return } - link.OnCommitOnce(htlcswitch.Outgoing, func() { - if !link.DisableAdds(htlcswitch.Outgoing) { - p.log.Warnf("Outgoing link adds already "+ - "disabled: %v", link.ChanID()) - } + if !link.DisableAdds(htlcswitch.Outgoing) { + p.log.Warnf("Outgoing link adds already "+ + "disabled: %v", link.ChanID()) + } + link.OnCommitOnce(htlcswitch.Outgoing, func() { p.queueMsg(shutdownMsg, nil) }) @@ -3630,7 +3630,7 @@ func (p *Brontide) handleCloseMsg(msg *closeMsg) { } oShutdown.WhenSome(func(msg lnwire.Shutdown) { - // if the link is nil it means we can immediately queue + // If the link is nil it means we can immediately queue // the Shutdown message since we don't have to wait for // commitment transaction synchronization. if link == nil { @@ -3638,16 +3638,17 @@ func (p *Brontide) handleCloseMsg(msg *closeMsg) { return } + // Immediately disallow any new HTLC's from being added + // in the outgoing direction. + if !link.DisableAdds(htlcswitch.Outgoing) { + p.log.Warnf("Outgoing link adds already "+ + "disabled: %v", link.ChanID()) + } + // When we have a Shutdown to send, we defer it till the // next time we send a CommitSig to remain spec // compliant. link.OnCommitOnce(htlcswitch.Outgoing, func() { - if !link.DisableAdds(htlcswitch.Outgoing) { - p.log.Warnf("Outgoing link adds "+ - "already disabled: %v", - link.ChanID()) - } - p.queueMsg(&msg, nil) }) })