From 6a83b06ab7f0575cf12384a32e56fb8543e10ec1 Mon Sep 17 00:00:00 2001 From: carla Date: Tue, 14 Jan 2020 15:07:41 +0200 Subject: [PATCH] htlcswitch: add LinkError implementation of ClearTextError This change introduces a LinkError implementation of the ClearTextError interface. This error is intended to represent failures which occur on our incoming and outgoing link when sending, receiving and forwarding htlcs. Paired with ForwardingError, which is represents failures that did not occur at our node, this error covers all non-opaque errors that the switch experiences. --- htlcswitch/failure.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/htlcswitch/failure.go b/htlcswitch/failure.go index 1f8e8f6ee..20ba6d018 100644 --- a/htlcswitch/failure.go +++ b/htlcswitch/failure.go @@ -25,6 +25,40 @@ type ClearTextError interface { WireMessage() lnwire.FailureMessage } +// LinkError is an implementation of the ClearTextError interface which +// represents failures that occur on our incoming or outgoing link. +type LinkError struct { + // msg returns the wire failure associated with the error. + // This value should *not* be nil, because we should always + // know the failure type for failures which occur at our own + // node. + msg lnwire.FailureMessage +} + +// NewLinkError returns a LinkError with the failure message provided. +// The failure message provided should *not* be nil, because we should +// always know the failure type for failures which occur at our own node. +func NewLinkError(msg lnwire.FailureMessage) *LinkError { + return &LinkError{msg: msg} +} + +// 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, +// because we are the ones failing the htlc. +// +// Note this is part of the ClearTextError interface. +func (l *LinkError) WireMessage() lnwire.FailureMessage { + return l.msg +} + +// Error returns the string representation of a link error. +// +// Note this is part of the ClearTextError interface. +func (l *LinkError) Error() string { + return l.msg.Error() +} + // ForwardingError wraps an lnwire.FailureMessage in a struct that also // includes the source of the error. type ForwardingError struct {