Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,646 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,105 @@ | ||
package htlcswitch | ||
|
||
// FailureDetail is an enum which is used to enrich failures with | ||
// additional information. | ||
type FailureDetail int | ||
import "github.com/lightningnetwork/lnd/invoices" | ||
|
||
// 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 | ||
} | ||
|
||
// 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 | ||
// OutgoingFailureOnionDecode indicates that we could not decode an | ||
// onion error. | ||
FailureDetailOnionDecode | ||
OutgoingFailureOnionDecode | ||
|
||
// 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 | ||
|
||
// 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 | ||
) | ||
|
||
// String returns the string representation of a failure detail. | ||
func (fd FailureDetail) String() string { | ||
// FailureString returns the string representation of a failure detail. | ||
// | ||
// Note: it is part of the FailureDetail interface. | ||
func (fd OutgoingFailure) FailureString() string { | ||
switch fd { | ||
case FailureDetailNone: | ||
case OutgoingFailureNone: | ||
return "no failure detail" | ||
|
||
case FailureDetailOnionDecode: | ||
case OutgoingFailureOnionDecode: | ||
return "could not decode onion" | ||
|
||
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 OutgoingFailureIncompleteForward: | ||
return "incomplete forward" | ||
|
||
case OutgoingFailureDownstreamHtlcAdd: | ||
return "could not add downstream htlc" | ||
|
||
default: | ||
return "unknown failure detail" | ||
} | ||
} | ||
|
||
// invoiceFailure is an implementation of the failure detail interface | ||
// for failures related to our own invoices. It wraps a failure resolution | ||
// result, since the reasons for failure are already enumerated in the | ||
// invoices package. | ||
type invoiceFailure struct { | ||
failureResolution invoices.FailureResolutionResult | ||
} | ||
|
||
// FailureString returns the string representation of a failure detail. | ||
// | ||
// Note: it is part of the FailureDetail interface. | ||
func (i *invoiceFailure) FailureString() string { | ||
return i.failureResolution.ResultString() | ||
} | ||
|
||
// newInvoiceFailure returns an invoice failure which wraps the | ||
// failure resolution provided for use as a failure detail. | ||
func newInvoiceFailure(result invoices.FailureResolutionResult) *invoiceFailure { | ||
return &invoiceFailure{failureResolution: result} | ||
} |
Oops, something went wrong.