Skip to content

Commit 8c064b8

Browse files
committed
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.
1 parent 972f57e commit 8c064b8

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

peer/brontide.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,12 +2990,12 @@ func (p *Brontide) handleLocalCloseReq(req *htlcswitch.ChanClose) {
29902990
return
29912991
}
29922992

2993-
link.OnCommitOnce(htlcswitch.Outgoing, func() {
2994-
if !link.DisableAdds(htlcswitch.Outgoing) {
2995-
p.log.Warnf("Outgoing link adds already "+
2996-
"disabled: %v", link.ChanID())
2997-
}
2993+
if !link.DisableAdds(htlcswitch.Outgoing) {
2994+
p.log.Warnf("Outgoing link adds already "+
2995+
"disabled: %v", link.ChanID())
2996+
}
29982997

2998+
link.OnCommitOnce(htlcswitch.Outgoing, func() {
29992999
p.queueMsg(shutdownMsg, nil)
30003000
})
30013001

@@ -3630,24 +3630,25 @@ func (p *Brontide) handleCloseMsg(msg *closeMsg) {
36303630
}
36313631

36323632
oShutdown.WhenSome(func(msg lnwire.Shutdown) {
3633-
// if the link is nil it means we can immediately queue
3633+
// If the link is nil it means we can immediately queue
36343634
// the Shutdown message since we don't have to wait for
36353635
// commitment transaction synchronization.
36363636
if link == nil {
36373637
p.queueMsg(&msg, nil)
36383638
return
36393639
}
36403640

3641+
// Immediately disallow any new HTLC's from being added
3642+
// in the outgoing direction.
3643+
if !link.DisableAdds(htlcswitch.Outgoing) {
3644+
p.log.Warnf("Outgoing link adds already "+
3645+
"disabled: %v", link.ChanID())
3646+
}
3647+
36413648
// When we have a Shutdown to send, we defer it till the
36423649
// next time we send a CommitSig to remain spec
36433650
// compliant.
36443651
link.OnCommitOnce(htlcswitch.Outgoing, func() {
3645-
if !link.DisableAdds(htlcswitch.Outgoing) {
3646-
p.log.Warnf("Outgoing link adds "+
3647-
"already disabled: %v",
3648-
link.ChanID())
3649-
}
3650-
36513652
p.queueMsg(&msg, nil)
36523653
})
36533654
})

0 commit comments

Comments
 (0)