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.
|
||||
msg lnwire.FailureMessage
|
||||
|
||||
// FailureDetail enriches the wire error with additional information.
|
||||
FailureDetail
|
||||
// OutgoingFailure enriches the wire error with additional information.
|
||||
OutgoingFailure
|
||||
}
|
||||
|
||||
// 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
|
||||
// a failure detail.
|
||||
func NewDetailedLinkError(msg lnwire.FailureMessage,
|
||||
detail FailureDetail) *LinkError {
|
||||
detail OutgoingFailure) *LinkError {
|
||||
|
||||
return &LinkError{
|
||||
msg: msg,
|
||||
FailureDetail: detail,
|
||||
OutgoingFailure: detail,
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,11 +72,11 @@ func (l *LinkError) WireMessage() lnwire.FailureMessage {
|
||||
func (l *LinkError) Error() string {
|
||||
// If the link error has no failure detail, return the wire message's
|
||||
// error.
|
||||
if l.FailureDetail == FailureDetailNone {
|
||||
if l.OutgoingFailure == OutgoingFailureNone {
|
||||
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
|
||||
|
@ -1,63 +1,63 @@
|
||||
package htlcswitch
|
||||
|
||||
// FailureDetail is an enum which is used to enrich failures with
|
||||
// additional information.
|
||||
type FailureDetail int
|
||||
// OutgoingFailure is an enum which is used to enrich failures which occur in
|
||||
// the switch or on our outgoing link with additional metadata.
|
||||
type OutgoingFailure int
|
||||
|
||||
const (
|
||||
// FailureDetailNone is returned when the wire message contains
|
||||
// OutgoingFailureNone is returned when the wire message contains
|
||||
// sufficient information.
|
||||
FailureDetailNone = iota
|
||||
OutgoingFailureNone OutgoingFailure = iota
|
||||
|
||||
// FailureDetailOnionDecode indicates that we could not decode an
|
||||
// onion error.
|
||||
FailureDetailOnionDecode
|
||||
// OutgoingFailureDecodeError indicates that we could not decode the
|
||||
// failure reason provided for a failed payment.
|
||||
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.
|
||||
FailureDetailLinkNotEligible
|
||||
OutgoingFailureLinkNotEligible
|
||||
|
||||
// FailureDetailOnChainTimeout indicates that a payment had to be timed
|
||||
// out on chain before it got past the first hop by us or the remote
|
||||
// party.
|
||||
FailureDetailOnChainTimeout
|
||||
// OutgoingFailureOnChainTimeout indicates that a payment had to be
|
||||
// timed out on chain before it got past the first hop by us or the
|
||||
// remote party.
|
||||
OutgoingFailureOnChainTimeout
|
||||
|
||||
// FailureDetailHTLCExceedsMax is returned when a htlc exceeds our
|
||||
// OutgoingFailureHTLCExceedsMax is returned when a htlc exceeds our
|
||||
// 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.
|
||||
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
|
||||
// same channel.
|
||||
FailureDetailCircularRoute
|
||||
OutgoingFailureCircularRoute
|
||||
)
|
||||
|
||||
// String returns the string representation of a failure detail.
|
||||
func (fd FailureDetail) String() string {
|
||||
func (fd OutgoingFailure) String() string {
|
||||
switch fd {
|
||||
case FailureDetailNone:
|
||||
case OutgoingFailureNone:
|
||||
return "no failure detail"
|
||||
|
||||
case FailureDetailOnionDecode:
|
||||
return "could not decode onion"
|
||||
case OutgoingFailureDecodeError:
|
||||
return "could not decode wire failure"
|
||||
|
||||
case FailureDetailLinkNotEligible:
|
||||
case OutgoingFailureLinkNotEligible:
|
||||
return "link not eligible"
|
||||
|
||||
case FailureDetailOnChainTimeout:
|
||||
case OutgoingFailureOnChainTimeout:
|
||||
return "payment was resolved on-chain, then canceled back"
|
||||
|
||||
case FailureDetailHTLCExceedsMax:
|
||||
case OutgoingFailureHTLCExceedsMax:
|
||||
return "htlc exceeds maximum policy amount"
|
||||
|
||||
case FailureDetailInsufficientBalance:
|
||||
case OutgoingFailureInsufficientBalance:
|
||||
return "insufficient bandwidth to route htlc"
|
||||
|
||||
case FailureDetailCircularRoute:
|
||||
case OutgoingFailureCircularRoute:
|
||||
return "same incoming and outgoing channel"
|
||||
|
||||
default:
|
||||
|
@ -2284,7 +2284,7 @@ func (l *channelLink) canSendHtlc(policy ForwardingPolicy,
|
||||
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
|
||||
@ -2319,7 +2319,7 @@ func (l *channelLink) canSendHtlc(policy ForwardingPolicy,
|
||||
},
|
||||
)
|
||||
return NewDetailedLinkError(
|
||||
failure, FailureDetailInsufficientBalance,
|
||||
failure, OutgoingFailureInsufficientBalance,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -771,7 +771,7 @@ func (s *Switch) handleLocalDispatch(pkt *htlcPacket) error {
|
||||
// will be returned back to the router.
|
||||
return NewDetailedLinkError(
|
||||
lnwire.NewTemporaryChannelFailure(nil),
|
||||
FailureDetailLinkNotEligible,
|
||||
OutgoingFailureLinkNotEligible,
|
||||
)
|
||||
}
|
||||
|
||||
@ -919,11 +919,11 @@ func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
|
||||
// need to apply an update here since it goes
|
||||
// directly to the router.
|
||||
lnwire.NewTemporaryChannelFailure(nil),
|
||||
FailureDetailOnionDecode,
|
||||
OutgoingFailureDecodeError,
|
||||
)
|
||||
|
||||
log.Errorf("%v: (hash=%v, pid=%d): %v",
|
||||
linkError.FailureDetail, paymentHash, paymentID,
|
||||
linkError.OutgoingFailure, paymentHash, paymentID,
|
||||
err)
|
||||
|
||||
return linkError
|
||||
@ -939,10 +939,10 @@ func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
|
||||
case isResolution && htlc.Reason == nil:
|
||||
linkError := NewDetailedLinkError(
|
||||
&lnwire.FailPermanentChannelFailure{},
|
||||
FailureDetailOnChainTimeout,
|
||||
OutgoingFailureOnChainTimeout,
|
||||
)
|
||||
|
||||
log.Info("%v: hash=%v, pid=%d", linkError.FailureDetail,
|
||||
log.Info("%v: hash=%v, pid=%d", linkError.OutgoingFailure,
|
||||
paymentHash, paymentID)
|
||||
|
||||
return linkError
|
||||
@ -1041,7 +1041,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
||||
if !link.EligibleToForward() {
|
||||
failure = NewDetailedLinkError(
|
||||
&lnwire.FailUnknownNextPeer{},
|
||||
FailureDetailLinkNotEligible,
|
||||
OutgoingFailureLinkNotEligible,
|
||||
)
|
||||
} else {
|
||||
// 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.
|
||||
return NewDetailedLinkError(
|
||||
lnwire.NewTemporaryChannelFailure(nil),
|
||||
FailureDetailCircularRoute,
|
||||
OutgoingFailureCircularRoute,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1348,7 +1348,7 @@ func TestCircularForwards(t *testing.T) {
|
||||
allowCircularPayment: false,
|
||||
expectedErr: NewDetailedLinkError(
|
||||
lnwire.NewTemporaryChannelFailure(nil),
|
||||
FailureDetailCircularRoute,
|
||||
OutgoingFailureCircularRoute,
|
||||
),
|
||||
},
|
||||
}
|
||||
@ -1465,7 +1465,7 @@ func TestCheckCircularForward(t *testing.T) {
|
||||
outgoingLink: lnwire.NewShortChanIDFromInt(123),
|
||||
expectedErr: NewDetailedLinkError(
|
||||
lnwire.NewTemporaryChannelFailure(nil),
|
||||
FailureDetailCircularRoute,
|
||||
OutgoingFailureCircularRoute,
|
||||
),
|
||||
},
|
||||
}
|
||||
@ -1527,7 +1527,7 @@ func TestSkipIneligibleLinksMultiHopForward(t *testing.T) {
|
||||
eligible1: true,
|
||||
failure1: NewDetailedLinkError(
|
||||
lnwire.NewTemporaryChannelFailure(nil),
|
||||
FailureDetailInsufficientBalance,
|
||||
OutgoingFailureInsufficientBalance,
|
||||
),
|
||||
eligible2: true,
|
||||
failure2: NewLinkError(
|
||||
|
Loading…
Reference in New Issue
Block a user