From 4485e8261f1eb8e1daa64b9c8d83f4674e824528 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 1 Apr 2020 00:13:23 +0200 Subject: [PATCH] routing/payment_lifecycle: move Fail call to payment loop In our quest to move calls to the ControlTower into the main payment lifecycle loop, we move the edge case of a too long route out of createNewPaymentAttempt. --- routing/payment_lifecycle.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go index 7ef02eeb..f2c533ec 100644 --- a/routing/payment_lifecycle.go +++ b/routing/payment_lifecycle.go @@ -117,9 +117,27 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) { firstHop, htlcAdd, attempt, err := p.createNewPaymentAttempt( rt, ) + // With SendToRoute, it can happen that the route exceeds protocol + // constraints. Mark the payment as failed with an internal error. + if err == route.ErrMaxRouteHopsExceeded || + err == sphinx.ErrMaxRoutingInfoSizeExceeded { + + log.Debugf("Invalid route provided for payment %x: %v", + p.paymentHash, err) + + controlErr := p.router.cfg.Control.Fail( + p.paymentHash, channeldb.FailureReasonError, + ) + if controlErr != nil { + return [32]byte{}, nil, controlErr + } + } + + // In any case, don't continue if there is an error. if err != nil { return [32]byte{}, nil, err } + p.attempt = attempt // Before sending this HTLC to the switch, we checkpoint the @@ -326,24 +344,6 @@ func (p *paymentLifecycle) createNewPaymentAttempt(rt *route.Route) ( onionBlob, c, err := generateSphinxPacket( rt, p.paymentHash[:], sessionKey, ) - - // With SendToRoute, it can happen that the route exceeds protocol - // constraints. Mark the payment as failed with an internal error. - if err == route.ErrMaxRouteHopsExceeded || - err == sphinx.ErrMaxRoutingInfoSizeExceeded { - - log.Debugf("Invalid route provided for payment %x: %v", - p.paymentHash, err) - - controlErr := p.router.cfg.Control.Fail( - p.paymentHash, channeldb.FailureReasonError, - ) - if controlErr != nil { - return lnwire.ShortChannelID{}, nil, nil, controlErr - } - } - - // In any case, don't continue if there is an error. if err != nil { return lnwire.ShortChannelID{}, nil, nil, err }