routing: move ErrMaxRouteHopsExceeded check

Now that SendToRoute is no longer using the payment lifecycle, we move
the max hop check out of the payment shard's launch() method, and return
the error directly, such that it can be handled in SendToRoute.
This commit is contained in:
Johan T. Halseth 2020-04-01 00:13:24 +02:00
parent a979b91b27
commit 4509c4f3a9
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 22 additions and 22 deletions

@ -139,24 +139,6 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
// With the route in hand, launch a new shard. // With the route in hand, launch a new shard.
var outcome *launchOutcome var outcome *launchOutcome
attempt, outcome, err = shardHandler.launchShard(rt) attempt, outcome, err = shardHandler.launchShard(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 { if err != nil {
return [32]byte{}, nil, err return [32]byte{}, nil, err
} }

@ -1731,11 +1731,11 @@ func (r *ChannelRouter) preparePayment(payment *LightningPayment) (
// SendToRoute attempts to send a payment with the given hash through the // SendToRoute attempts to send a payment with the given hash through the
// provided route. This function is blocking and will return the obtained // provided route. This function is blocking and will return the obtained
// preimage if the payment is successful or the full error in case of a failure. // preimage if the payment is successful or the full error in case of a failure.
func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, route *route.Route) ( func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, rt *route.Route) (
lntypes.Preimage, error) { lntypes.Preimage, error) {
// Calculate amount paid to receiver. // Calculate amount paid to receiver.
amt := route.ReceiverAmt() amt := rt.ReceiverAmt()
// Record this payment hash with the ControlTower, ensuring it is not // Record this payment hash with the ControlTower, ensuring it is not
// already in-flight. // already in-flight.
@ -1753,7 +1753,7 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, route *route.Route) (
log.Tracef("Dispatching SendToRoute for hash %v: %v", log.Tracef("Dispatching SendToRoute for hash %v: %v",
hash, newLogClosure(func() string { hash, newLogClosure(func() string {
return spew.Sdump(route) return spew.Sdump(rt)
}), }),
) )
@ -1764,7 +1764,25 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, route *route.Route) (
} }
var shardError error var shardError error
attempt, outcome, err := sh.launchShard(route) attempt, outcome, err := sh.launchShard(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",
hash, err)
controlErr := r.cfg.Control.Fail(
hash, channeldb.FailureReasonError,
)
if controlErr != nil {
return [32]byte{}, controlErr
}
}
// In any case, don't continue if there is an error.
if err != nil { if err != nil {
return lntypes.Preimage{}, err return lntypes.Preimage{}, err
} }