routing+channeldb: add more failure reasons

This commit is contained in:
Joost Jager
2019-06-04 11:22:23 +02:00
parent d6d87e12fe
commit ae46fb00cb
7 changed files with 241 additions and 167 deletions

View File

@@ -338,39 +338,41 @@ func (p *paymentLifecycle) sendPaymentAttempt(firstHop lnwire.ShortChannelID,
// handleSendError inspects the given error from the Switch and determines
// whether we should make another payment attempt.
func (p *paymentLifecycle) handleSendError(sendErr error) error {
var finalOutcome bool
var reason channeldb.FailureReason
// If an internal, non-forwarding error occurred, we can stop trying.
fErr, ok := sendErr.(*htlcswitch.ForwardingError)
if !ok {
finalOutcome = true
reason = channeldb.FailureReasonError
} else {
finalOutcome = p.router.processSendError(
var final bool
final, reason = p.router.processSendError(
p.paySession, &p.attempt.Route, fErr,
)
// Save the forwarding error so it can be returned if this turns
// out to be the last attempt.
p.lastError = fErr
}
if !final {
// Save the forwarding error so it can be returned if
// this turns out to be the last attempt.
p.lastError = fErr
if finalOutcome {
log.Errorf("Payment %x failed with final outcome: %v",
p.payment.PaymentHash, sendErr)
// Mark the payment failed with no route.
// TODO(halseth): make payment codes for the actual reason we
// don't continue path finding.
err := p.router.cfg.Control.Fail(
p.payment.PaymentHash, channeldb.FailureReasonNoRoute,
)
if err != nil {
return err
return nil
}
// Terminal state, return the error we encountered.
return sendErr
}
return nil
log.Debugf("Payment %x failed: final_outcome=%v, raw_err=%v",
p.payment.PaymentHash, reason, sendErr)
// Mark the payment failed with no route.
//
// TODO(halseth): make payment codes for the actual reason we don't
// continue path finding.
err := p.router.cfg.Control.Fail(
p.payment.PaymentHash, reason,
)
if err != nil {
return err
}
// Terminal state, return the error we encountered.
return sendErr
}