From c15b0316a2c81114144d7fc3e3d2c96332897b01 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Thu, 21 Nov 2019 12:08:09 +0100 Subject: [PATCH] routing: use FailureReasonError for internal path finding errors --- routing/payment_lifecycle.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go index a8017eaa..3fb391eb 100644 --- a/routing/payment_lifecycle.go +++ b/routing/payment_lifecycle.go @@ -186,6 +186,19 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) { } +// errorToPaymentFailure takes a path finding error and converts it into a +// payment-level failure. +func errorToPaymentFailure(err error) channeldb.FailureReason { + switch err { + case errNoTlvPayload, errNoPathFound, errMaxHopsExceeded, + errPrebuiltRouteTried: + + return channeldb.FailureReasonNoRoute + } + + return channeldb.FailureReasonError +} + // createNewPaymentAttempt creates and stores a new payment attempt to the // database. func (p *paymentLifecycle) createNewPaymentAttempt() (lnwire.ShortChannelID, @@ -230,11 +243,14 @@ func (p *paymentLifecycle) createNewPaymentAttempt() (lnwire.ShortChannelID, log.Warnf("Failed to find route for payment %x: %v", p.payment.PaymentHash, err) + // Convert error to payment-level failure. + failure := errorToPaymentFailure(err) + // If we're unable to successfully make a payment using // any of the routes we've found, then mark the payment // as permanently failed. saveErr := p.router.cfg.Control.Fail( - p.payment.PaymentHash, channeldb.FailureReasonNoRoute, + p.payment.PaymentHash, failure, ) if saveErr != nil { return lnwire.ShortChannelID{}, nil, saveErr