mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-29 18:52:41 +02:00
routing: add SendToRouteSkipTempErr
to skip temp error failure
This commit adds a new method `SendToRouteSkipTempErr` that skips failing the payment unless a terminal error occurred. This is accomplished by demoting the original `SendToRoute` to a private method and creating two new methods on top of it to minimize code change.
This commit is contained in:
@@ -2155,13 +2155,30 @@ func (r *ChannelRouter) preparePayment(payment *LightningPayment) (
|
|||||||
return paySession, shardTracker, nil
|
return paySession, shardTracker, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendToRoute attempts to send a payment with the given hash through the
|
// SendToRoute sends a payment using the provided route and fails the payment
|
||||||
|
// when an error is returned from the attempt.
|
||||||
|
func (r *ChannelRouter) SendToRoute(htlcHash lntypes.Hash,
|
||||||
|
rt *route.Route) (*channeldb.HTLCAttempt, error) {
|
||||||
|
|
||||||
|
return r.sendToRoute(htlcHash, rt, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendToRouteSkipTempErr sends a payment using the provided route and fails
|
||||||
|
// the payment ONLY when a terminal error is returned from the attempt.
|
||||||
|
func (r *ChannelRouter) SendToRouteSkipTempErr(htlcHash lntypes.Hash,
|
||||||
|
rt *route.Route) (*channeldb.HTLCAttempt, error) {
|
||||||
|
|
||||||
|
return r.sendToRoute(htlcHash, rt, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sendToRoute attempts to send a payment with the given hash through the
|
||||||
// provided route. This function is blocking and will return the attempt
|
// provided route. This function is blocking and will return the attempt
|
||||||
// information as it is stored in the database. For a successful htlc, this
|
// information as it is stored in the database. For a successful htlc, this
|
||||||
// information will contain the preimage. If an error occurs after the attempt
|
// information will contain the preimage. If an error occurs after the attempt
|
||||||
// was initiated, both return values will be non-nil.
|
// was initiated, both return values will be non-nil. If skipTempErr is true,
|
||||||
func (r *ChannelRouter) SendToRoute(htlcHash lntypes.Hash, rt *route.Route) (
|
// the payment won't be failed unless a terminal error has occurred.
|
||||||
*channeldb.HTLCAttempt, error) {
|
func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
|
||||||
|
skipTempErr bool) (*channeldb.HTLCAttempt, error) {
|
||||||
|
|
||||||
// Calculate amount paid to receiver.
|
// Calculate amount paid to receiver.
|
||||||
amt := rt.ReceiverAmt()
|
amt := rt.ReceiverAmt()
|
||||||
@@ -2281,10 +2298,9 @@ func (r *ChannelRouter) SendToRoute(htlcHash lntypes.Hash, rt *route.Route) (
|
|||||||
err = sh.handleSendError(attempt, shardError)
|
err = sh.handleSendError(attempt, shardError)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
// If we weren't able to extract a proper failure reason (which can
|
// If a non-terminal error is returned and `skipTempErr` is false, then
|
||||||
// happen if the second chance logic is triggered), then we'll use the
|
// we'll use the normal no route error.
|
||||||
// normal no route error.
|
case err == nil && !skipTempErr:
|
||||||
case err == nil:
|
|
||||||
err = r.cfg.Control.Fail(
|
err = r.cfg.Control.Fail(
|
||||||
paymentIdentifier, channeldb.FailureReasonNoRoute,
|
paymentIdentifier, channeldb.FailureReasonNoRoute,
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user