peer+htlcswitch: update Enable/DisableAdds API
In this commit, the `ChannelUpdateHandler`'s `EnableAdds` and `DisableAdds` methods are adjusted to return booleans instead of errors. This is done becuase currently, any error returned by these methods is treated by just logging the error since today all it means is that the proposed update has already been done. And so all we do today is log the error. But in future, if these methods are updated to return actual errors that need to be handled, then we might forget to handle them correctly at the various call sights. So we instead change the signature of the function to just return a boolean. In future, if we do need to return any error, we will have to go inspect every call sight in any case to fix compliation & then we can be sure we are handling the errors correctly.
This commit is contained in:
6 files changed
+45
-80
No files matched your search
+10
-12
@@ -2991,9 +2991,8 @@ func (p *Brontide) handleLocalCloseReq(req *htlcswitch.ChanClose) {
|
||||
}
|
||||
|
||||
link.OnCommitOnce(htlcswitch.Outgoing, func() {
|
||||
err := link.DisableAdds(htlcswitch.Outgoing)
|
||||
if err != nil {
|
||||
p.log.Warnf("outgoing link adds already "+
|
||||
if !link.DisableAdds(htlcswitch.Outgoing) {
|
||||
p.log.Warnf("Outgoing link adds already "+
|
||||
"disabled: %v", link.ChanID())
|
||||
}
|
||||
|
||||
@@ -3619,12 +3618,9 @@ func (p *Brontide) handleCloseMsg(msg *closeMsg) {
|
||||
switch typed := msg.msg.(type) {
|
||||
case *lnwire.Shutdown:
|
||||
// Disable incoming adds immediately.
|
||||
if link != nil {
|
||||
err := link.DisableAdds(htlcswitch.Incoming)
|
||||
if err != nil {
|
||||
p.log.Warnf("incoming link adds already "+
|
||||
"disabled: %v", link.ChanID())
|
||||
}
|
||||
if link != nil && !link.DisableAdds(htlcswitch.Incoming) {
|
||||
p.log.Warnf("Incoming link adds already disabled: %v",
|
||||
link.ChanID())
|
||||
}
|
||||
|
||||
oShutdown, err := chanCloser.ReceiveShutdown(*typed)
|
||||
@@ -3646,10 +3642,12 @@ func (p *Brontide) handleCloseMsg(msg *closeMsg) {
|
||||
// next time we send a CommitSig to remain spec
|
||||
// compliant.
|
||||
link.OnCommitOnce(htlcswitch.Outgoing, func() {
|
||||
err := link.DisableAdds(htlcswitch.Outgoing)
|
||||
if err != nil {
|
||||
p.log.Warn(err.Error())
|
||||
if !link.DisableAdds(htlcswitch.Outgoing) {
|
||||
p.log.Warnf("Outgoing link adds "+
|
||||
"already disabled: %v",
|
||||
link.ChanID())
|
||||
}
|
||||
|
||||
p.queueMsg(&msg, nil)
|
||||
})
|
||||
})
|
||||
|
||||
+8
-23
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
crand "crypto/rand"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net"
|
||||
@@ -510,34 +509,20 @@ type mockMessageConn struct {
|
||||
readRaceDetectingCounter int
|
||||
}
|
||||
|
||||
func (m *mockUpdateHandler) EnableAdds(dir htlcswitch.LinkDirection) error {
|
||||
switch dir {
|
||||
case htlcswitch.Outgoing:
|
||||
if !m.isOutgoingAddBlocked.Swap(false) {
|
||||
return fmt.Errorf("%v adds already enabled", dir)
|
||||
}
|
||||
case htlcswitch.Incoming:
|
||||
if !m.isIncomingAddBlocked.Swap(false) {
|
||||
return fmt.Errorf("%v adds already enabled", dir)
|
||||
}
|
||||
func (m *mockUpdateHandler) EnableAdds(dir htlcswitch.LinkDirection) bool {
|
||||
if dir == htlcswitch.Outgoing {
|
||||
return m.isOutgoingAddBlocked.Swap(false)
|
||||
}
|
||||
|
||||
return nil
|
||||
return m.isIncomingAddBlocked.Swap(false)
|
||||
}
|
||||
|
||||
func (m *mockUpdateHandler) DisableAdds(dir htlcswitch.LinkDirection) error {
|
||||
switch dir {
|
||||
case htlcswitch.Outgoing:
|
||||
if m.isOutgoingAddBlocked.Swap(true) {
|
||||
return fmt.Errorf("%v adds already disabled", dir)
|
||||
}
|
||||
case htlcswitch.Incoming:
|
||||
if m.isIncomingAddBlocked.Swap(true) {
|
||||
return fmt.Errorf("%v adds already disabled", dir)
|
||||
}
|
||||
func (m *mockUpdateHandler) DisableAdds(dir htlcswitch.LinkDirection) bool {
|
||||
if dir == htlcswitch.Outgoing {
|
||||
return !m.isOutgoingAddBlocked.Swap(true)
|
||||
}
|
||||
|
||||
return nil
|
||||
return !m.isIncomingAddBlocked.Swap(true)
|
||||
}
|
||||
|
||||
func (m *mockUpdateHandler) IsFlushing(dir htlcswitch.LinkDirection) bool {
|
||||
|
||||
Reference in new issue
Block a user