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.
This commit is contained in:
Elle Mouton 2024-02-07 12:45:33 +02:00
parent 972f57e9a7
commit 8c064b86f1
No known key found for this signature in database
GPG key ID: D7D916376026F177

View file

@ -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)
})
})