htlcswitch: use LinkError for internal errors

Update the ChannelLink interface to specifically
return the LinkError struct. This error implements
the ClearTextError interface, so will be picked
up as a routing realted error by the router.

With LinkErrors implemented, the switch now
returns a LinkError for all failures on our
incoming/outgoing link and ForwardingError when
the failure occurs down the line.
This commit is contained in:
carla
2020-01-14 15:07:42 +02:00
parent b5a2d75465
commit f430fd50c5
8 changed files with 185 additions and 79 deletions

View File

@@ -33,6 +33,9 @@ type LinkError struct {
// know the failure type for failures which occur at our own
// node.
msg lnwire.FailureMessage
// FailureDetail enriches the wire error with additional information.
FailureDetail
}
// NewLinkError returns a LinkError with the failure message provided.
@@ -42,6 +45,17 @@ func NewLinkError(msg lnwire.FailureMessage) *LinkError {
return &LinkError{msg: msg}
}
// NewDetailedLinkError returns a link error that enriches a wire message with
// a failure detail.
func NewDetailedLinkError(msg lnwire.FailureMessage,
detail FailureDetail) *LinkError {
return &LinkError{
msg: msg,
FailureDetail: detail,
}
}
// WireMessage extracts a valid wire failure message from an internal
// error which may contain additional metadata (which should not be
// exposed to the network). This value should never be nil for LinkErrors,
@@ -56,7 +70,13 @@ func (l *LinkError) WireMessage() lnwire.FailureMessage {
//
// Note this is part of the ClearTextError interface.
func (l *LinkError) Error() string {
return l.msg.Error()
// If the link error has no failure detail, return the wire message's
// error.
if l.FailureDetail == FailureDetailNone {
return l.msg.Error()
}
return fmt.Sprintf("%v: %v", l.msg.Error(), l.FailureDetail)
}
// ForwardingError wraps an lnwire.FailureMessage in a struct that also