htlcswitch: rename FailureDetail to OutgoingFailure
Rename FailureDetail in a separate commit so that a FailureDetail interface can be introduced in the following commit. OutgoingFailureOnionDecode is renamed to OutgoingFailureDecodeError to specifically indicate that we could not decode the wire failure that our payment experienced.
This commit is contained in:
parent
8cbed23f26
commit
bdd9411bbd
@ -34,8 +34,8 @@ type LinkError struct {
|
|||||||
// node.
|
// node.
|
||||||
msg lnwire.FailureMessage
|
msg lnwire.FailureMessage
|
||||||
|
|
||||||
// FailureDetail enriches the wire error with additional information.
|
// OutgoingFailure enriches the wire error with additional information.
|
||||||
FailureDetail
|
OutgoingFailure
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLinkError returns a LinkError with the failure message provided.
|
// NewLinkError returns a LinkError with the failure message provided.
|
||||||
@ -48,11 +48,11 @@ func NewLinkError(msg lnwire.FailureMessage) *LinkError {
|
|||||||
// NewDetailedLinkError returns a link error that enriches a wire message with
|
// NewDetailedLinkError returns a link error that enriches a wire message with
|
||||||
// a failure detail.
|
// a failure detail.
|
||||||
func NewDetailedLinkError(msg lnwire.FailureMessage,
|
func NewDetailedLinkError(msg lnwire.FailureMessage,
|
||||||
detail FailureDetail) *LinkError {
|
detail OutgoingFailure) *LinkError {
|
||||||
|
|
||||||
return &LinkError{
|
return &LinkError{
|
||||||
msg: msg,
|
msg: msg,
|
||||||
FailureDetail: detail,
|
OutgoingFailure: detail,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,11 +72,11 @@ func (l *LinkError) WireMessage() lnwire.FailureMessage {
|
|||||||
func (l *LinkError) Error() string {
|
func (l *LinkError) Error() string {
|
||||||
// If the link error has no failure detail, return the wire message's
|
// If the link error has no failure detail, return the wire message's
|
||||||
// error.
|
// error.
|
||||||
if l.FailureDetail == FailureDetailNone {
|
if l.OutgoingFailure == OutgoingFailureNone {
|
||||||
return l.msg.Error()
|
return l.msg.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%v: %v", l.msg.Error(), l.FailureDetail)
|
return fmt.Sprintf("%v: %v", l.msg.Error(), l.OutgoingFailure)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForwardingError wraps an lnwire.FailureMessage in a struct that also
|
// ForwardingError wraps an lnwire.FailureMessage in a struct that also
|
||||||
|
@ -1,63 +1,63 @@
|
|||||||
package htlcswitch
|
package htlcswitch
|
||||||
|
|
||||||
// FailureDetail is an enum which is used to enrich failures with
|
// OutgoingFailure is an enum which is used to enrich failures which occur in
|
||||||
// additional information.
|
// the switch or on our outgoing link with additional metadata.
|
||||||
type FailureDetail int
|
type OutgoingFailure int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// FailureDetailNone is returned when the wire message contains
|
// OutgoingFailureNone is returned when the wire message contains
|
||||||
// sufficient information.
|
// sufficient information.
|
||||||
FailureDetailNone = iota
|
OutgoingFailureNone OutgoingFailure = iota
|
||||||
|
|
||||||
// FailureDetailOnionDecode indicates that we could not decode an
|
// OutgoingFailureDecodeError indicates that we could not decode the
|
||||||
// onion error.
|
// failure reason provided for a failed payment.
|
||||||
FailureDetailOnionDecode
|
OutgoingFailureDecodeError
|
||||||
|
|
||||||
// FailureDetailLinkNotEligible indicates that a routing attempt was
|
// OutgoingFailureLinkNotEligible indicates that a routing attempt was
|
||||||
// made over a link that is not eligible for routing.
|
// made over a link that is not eligible for routing.
|
||||||
FailureDetailLinkNotEligible
|
OutgoingFailureLinkNotEligible
|
||||||
|
|
||||||
// FailureDetailOnChainTimeout indicates that a payment had to be timed
|
// OutgoingFailureOnChainTimeout indicates that a payment had to be
|
||||||
// out on chain before it got past the first hop by us or the remote
|
// timed out on chain before it got past the first hop by us or the
|
||||||
// party.
|
// remote party.
|
||||||
FailureDetailOnChainTimeout
|
OutgoingFailureOnChainTimeout
|
||||||
|
|
||||||
// FailureDetailHTLCExceedsMax is returned when a htlc exceeds our
|
// OutgoingFailureHTLCExceedsMax is returned when a htlc exceeds our
|
||||||
// policy's maximum htlc amount.
|
// policy's maximum htlc amount.
|
||||||
FailureDetailHTLCExceedsMax
|
OutgoingFailureHTLCExceedsMax
|
||||||
|
|
||||||
// FailureDetailInsufficientBalance is returned when we cannot route a
|
// OutgoingFailureInsufficientBalance is returned when we cannot route a
|
||||||
// htlc due to insufficient outgoing capacity.
|
// htlc due to insufficient outgoing capacity.
|
||||||
FailureDetailInsufficientBalance
|
OutgoingFailureInsufficientBalance
|
||||||
|
|
||||||
// FailureDetailCircularRoute is returned when an attempt is made
|
// OutgoingFailureCircularRoute is returned when an attempt is made
|
||||||
// to forward a htlc through our node which arrives and leaves on the
|
// to forward a htlc through our node which arrives and leaves on the
|
||||||
// same channel.
|
// same channel.
|
||||||
FailureDetailCircularRoute
|
OutgoingFailureCircularRoute
|
||||||
)
|
)
|
||||||
|
|
||||||
// String returns the string representation of a failure detail.
|
// String returns the string representation of a failure detail.
|
||||||
func (fd FailureDetail) String() string {
|
func (fd OutgoingFailure) String() string {
|
||||||
switch fd {
|
switch fd {
|
||||||
case FailureDetailNone:
|
case OutgoingFailureNone:
|
||||||
return "no failure detail"
|
return "no failure detail"
|
||||||
|
|
||||||
case FailureDetailOnionDecode:
|
case OutgoingFailureDecodeError:
|
||||||
return "could not decode onion"
|
return "could not decode wire failure"
|
||||||
|
|
||||||
case FailureDetailLinkNotEligible:
|
case OutgoingFailureLinkNotEligible:
|
||||||
return "link not eligible"
|
return "link not eligible"
|
||||||
|
|
||||||
case FailureDetailOnChainTimeout:
|
case OutgoingFailureOnChainTimeout:
|
||||||
return "payment was resolved on-chain, then canceled back"
|
return "payment was resolved on-chain, then canceled back"
|
||||||
|
|
||||||
case FailureDetailHTLCExceedsMax:
|
case OutgoingFailureHTLCExceedsMax:
|
||||||
return "htlc exceeds maximum policy amount"
|
return "htlc exceeds maximum policy amount"
|
||||||
|
|
||||||
case FailureDetailInsufficientBalance:
|
case OutgoingFailureInsufficientBalance:
|
||||||
return "insufficient bandwidth to route htlc"
|
return "insufficient bandwidth to route htlc"
|
||||||
|
|
||||||
case FailureDetailCircularRoute:
|
case OutgoingFailureCircularRoute:
|
||||||
return "same incoming and outgoing channel"
|
return "same incoming and outgoing channel"
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -2284,7 +2284,7 @@ func (l *channelLink) canSendHtlc(policy ForwardingPolicy,
|
|||||||
return lnwire.NewTemporaryChannelFailure(upd)
|
return lnwire.NewTemporaryChannelFailure(upd)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return NewDetailedLinkError(failure, FailureDetailHTLCExceedsMax)
|
return NewDetailedLinkError(failure, OutgoingFailureHTLCExceedsMax)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to avoid offering an HTLC which will expire in the near
|
// We want to avoid offering an HTLC which will expire in the near
|
||||||
@ -2319,7 +2319,7 @@ func (l *channelLink) canSendHtlc(policy ForwardingPolicy,
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
return NewDetailedLinkError(
|
return NewDetailedLinkError(
|
||||||
failure, FailureDetailInsufficientBalance,
|
failure, OutgoingFailureInsufficientBalance,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -771,7 +771,7 @@ func (s *Switch) handleLocalDispatch(pkt *htlcPacket) error {
|
|||||||
// will be returned back to the router.
|
// will be returned back to the router.
|
||||||
return NewDetailedLinkError(
|
return NewDetailedLinkError(
|
||||||
lnwire.NewTemporaryChannelFailure(nil),
|
lnwire.NewTemporaryChannelFailure(nil),
|
||||||
FailureDetailLinkNotEligible,
|
OutgoingFailureLinkNotEligible,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -919,11 +919,11 @@ func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
|
|||||||
// need to apply an update here since it goes
|
// need to apply an update here since it goes
|
||||||
// directly to the router.
|
// directly to the router.
|
||||||
lnwire.NewTemporaryChannelFailure(nil),
|
lnwire.NewTemporaryChannelFailure(nil),
|
||||||
FailureDetailOnionDecode,
|
OutgoingFailureDecodeError,
|
||||||
)
|
)
|
||||||
|
|
||||||
log.Errorf("%v: (hash=%v, pid=%d): %v",
|
log.Errorf("%v: (hash=%v, pid=%d): %v",
|
||||||
linkError.FailureDetail, paymentHash, paymentID,
|
linkError.OutgoingFailure, paymentHash, paymentID,
|
||||||
err)
|
err)
|
||||||
|
|
||||||
return linkError
|
return linkError
|
||||||
@ -939,10 +939,10 @@ func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
|
|||||||
case isResolution && htlc.Reason == nil:
|
case isResolution && htlc.Reason == nil:
|
||||||
linkError := NewDetailedLinkError(
|
linkError := NewDetailedLinkError(
|
||||||
&lnwire.FailPermanentChannelFailure{},
|
&lnwire.FailPermanentChannelFailure{},
|
||||||
FailureDetailOnChainTimeout,
|
OutgoingFailureOnChainTimeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
log.Info("%v: hash=%v, pid=%d", linkError.FailureDetail,
|
log.Info("%v: hash=%v, pid=%d", linkError.OutgoingFailure,
|
||||||
paymentHash, paymentID)
|
paymentHash, paymentID)
|
||||||
|
|
||||||
return linkError
|
return linkError
|
||||||
@ -1041,7 +1041,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
|||||||
if !link.EligibleToForward() {
|
if !link.EligibleToForward() {
|
||||||
failure = NewDetailedLinkError(
|
failure = NewDetailedLinkError(
|
||||||
&lnwire.FailUnknownNextPeer{},
|
&lnwire.FailUnknownNextPeer{},
|
||||||
FailureDetailLinkNotEligible,
|
OutgoingFailureLinkNotEligible,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// We'll ensure that the HTLC satisfies the
|
// We'll ensure that the HTLC satisfies the
|
||||||
@ -1217,7 +1217,7 @@ func checkCircularForward(incoming, outgoing lnwire.ShortChannelID,
|
|||||||
// node, so we do not include a channel update.
|
// node, so we do not include a channel update.
|
||||||
return NewDetailedLinkError(
|
return NewDetailedLinkError(
|
||||||
lnwire.NewTemporaryChannelFailure(nil),
|
lnwire.NewTemporaryChannelFailure(nil),
|
||||||
FailureDetailCircularRoute,
|
OutgoingFailureCircularRoute,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1348,7 +1348,7 @@ func TestCircularForwards(t *testing.T) {
|
|||||||
allowCircularPayment: false,
|
allowCircularPayment: false,
|
||||||
expectedErr: NewDetailedLinkError(
|
expectedErr: NewDetailedLinkError(
|
||||||
lnwire.NewTemporaryChannelFailure(nil),
|
lnwire.NewTemporaryChannelFailure(nil),
|
||||||
FailureDetailCircularRoute,
|
OutgoingFailureCircularRoute,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1465,7 +1465,7 @@ func TestCheckCircularForward(t *testing.T) {
|
|||||||
outgoingLink: lnwire.NewShortChanIDFromInt(123),
|
outgoingLink: lnwire.NewShortChanIDFromInt(123),
|
||||||
expectedErr: NewDetailedLinkError(
|
expectedErr: NewDetailedLinkError(
|
||||||
lnwire.NewTemporaryChannelFailure(nil),
|
lnwire.NewTemporaryChannelFailure(nil),
|
||||||
FailureDetailCircularRoute,
|
OutgoingFailureCircularRoute,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1527,7 +1527,7 @@ func TestSkipIneligibleLinksMultiHopForward(t *testing.T) {
|
|||||||
eligible1: true,
|
eligible1: true,
|
||||||
failure1: NewDetailedLinkError(
|
failure1: NewDetailedLinkError(
|
||||||
lnwire.NewTemporaryChannelFailure(nil),
|
lnwire.NewTemporaryChannelFailure(nil),
|
||||||
FailureDetailInsufficientBalance,
|
OutgoingFailureInsufficientBalance,
|
||||||
),
|
),
|
||||||
eligible2: true,
|
eligible2: true,
|
||||||
failure2: NewLinkError(
|
failure2: NewLinkError(
|
||||||
|
Loading…
Reference in New Issue
Block a user