2020-01-14 14:07:42 +01:00
|
|
|
package htlcswitch
|
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
// FailureDetail is an interface implemented by failures that occur on
|
|
|
|
// our incoming or outgoing link, or within the switch itself.
|
|
|
|
type FailureDetail interface {
|
|
|
|
// FailureString returns the string representation of a failure
|
|
|
|
// detail.
|
|
|
|
FailureString() string
|
|
|
|
}
|
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
// 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
|
2020-01-14 14:07:42 +01:00
|
|
|
|
|
|
|
const (
|
2020-02-06 18:35:16 +01:00
|
|
|
// OutgoingFailureNone is returned when the wire message contains
|
2020-01-14 14:07:42 +01:00
|
|
|
// sufficient information.
|
2020-02-06 18:35:16 +01:00
|
|
|
OutgoingFailureNone OutgoingFailure = iota
|
2020-01-14 14:07:42 +01:00
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
// OutgoingFailureDecodeError indicates that we could not decode the
|
|
|
|
// failure reason provided for a failed payment.
|
|
|
|
OutgoingFailureDecodeError
|
2020-01-14 14:07:42 +01:00
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
// OutgoingFailureLinkNotEligible indicates that a routing attempt was
|
2020-01-14 14:07:42 +01:00
|
|
|
// made over a link that is not eligible for routing.
|
2020-02-06 18:35:16 +01:00
|
|
|
OutgoingFailureLinkNotEligible
|
2020-01-14 14:07:42 +01:00
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
// 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
|
2020-01-14 14:07:42 +01:00
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
// OutgoingFailureHTLCExceedsMax is returned when a htlc exceeds our
|
2020-01-14 14:07:42 +01:00
|
|
|
// policy's maximum htlc amount.
|
2020-02-06 18:35:16 +01:00
|
|
|
OutgoingFailureHTLCExceedsMax
|
2020-01-14 14:07:42 +01:00
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
// OutgoingFailureInsufficientBalance is returned when we cannot route a
|
2020-01-14 14:07:42 +01:00
|
|
|
// htlc due to insufficient outgoing capacity.
|
2020-02-06 18:35:16 +01:00
|
|
|
OutgoingFailureInsufficientBalance
|
2020-01-30 09:01:17 +01:00
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
// OutgoingFailureCircularRoute is returned when an attempt is made
|
2020-01-30 09:01:17 +01:00
|
|
|
// to forward a htlc through our node which arrives and leaves on the
|
|
|
|
// same channel.
|
2020-02-06 18:35:16 +01:00
|
|
|
OutgoingFailureCircularRoute
|
2020-02-06 18:35:17 +01:00
|
|
|
|
|
|
|
// OutgoingFailureIncompleteForward is returned when we cancel an incomplete
|
|
|
|
// forward.
|
|
|
|
OutgoingFailureIncompleteForward
|
|
|
|
|
|
|
|
// OutgoingFailureDownstreamHtlcAdd is returned when we fail to add a
|
|
|
|
// downstream htlc to our outgoing link.
|
|
|
|
OutgoingFailureDownstreamHtlcAdd
|
|
|
|
|
|
|
|
// OutgoingFailureForwardsDisabled is returned when the switch is
|
|
|
|
// configured to disallow forwards.
|
|
|
|
OutgoingFailureForwardsDisabled
|
2020-01-14 14:07:42 +01:00
|
|
|
)
|
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
// FailureString returns the string representation of a failure detail.
|
|
|
|
//
|
|
|
|
// Note: it is part of the FailureDetail interface.
|
|
|
|
func (fd OutgoingFailure) FailureString() string {
|
2020-01-14 14:07:42 +01:00
|
|
|
switch fd {
|
2020-02-06 18:35:16 +01:00
|
|
|
case OutgoingFailureNone:
|
2020-01-14 14:07:42 +01:00
|
|
|
return "no failure detail"
|
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
case OutgoingFailureDecodeError:
|
|
|
|
return "could not decode wire failure"
|
2020-01-14 14:07:42 +01:00
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
case OutgoingFailureLinkNotEligible:
|
2020-01-14 14:07:42 +01:00
|
|
|
return "link not eligible"
|
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
case OutgoingFailureOnChainTimeout:
|
2020-01-14 14:07:42 +01:00
|
|
|
return "payment was resolved on-chain, then canceled back"
|
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
case OutgoingFailureHTLCExceedsMax:
|
2020-01-14 14:07:42 +01:00
|
|
|
return "htlc exceeds maximum policy amount"
|
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
case OutgoingFailureInsufficientBalance:
|
2020-01-14 14:07:42 +01:00
|
|
|
return "insufficient bandwidth to route htlc"
|
|
|
|
|
2020-02-06 18:35:16 +01:00
|
|
|
case OutgoingFailureCircularRoute:
|
2020-01-30 09:01:17 +01:00
|
|
|
return "same incoming and outgoing channel"
|
|
|
|
|
2020-02-06 18:35:17 +01:00
|
|
|
case OutgoingFailureIncompleteForward:
|
|
|
|
return "failed after detecting incomplete forward"
|
|
|
|
|
|
|
|
case OutgoingFailureDownstreamHtlcAdd:
|
|
|
|
return "could not add downstream htlc"
|
|
|
|
|
|
|
|
case OutgoingFailureForwardsDisabled:
|
|
|
|
return "node configured to disallow forwards"
|
|
|
|
|
2020-01-14 14:07:42 +01:00
|
|
|
default:
|
|
|
|
return "unknown failure detail"
|
|
|
|
}
|
|
|
|
}
|