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.
This commit is contained in:
Johan T. Halseth 2020-04-01 00:13:23 +02:00
parent 3620721391
commit 4485e8261f
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -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
}