routing: new failure reason for cancelled payments
This commit is contained in:
4 files changed
+18
-9
No files matched your search
@@ -104,7 +104,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrNoSequenceNumber is returned if we lookup a payment which does
|
// ErrNoSequenceNumber is returned if we look up a payment which does
|
||||||
// not have a sequence number.
|
// not have a sequence number.
|
||||||
ErrNoSequenceNumber = errors.New("sequence number not found")
|
ErrNoSequenceNumber = errors.New("sequence number not found")
|
||||||
|
|
||||||
@@ -147,18 +147,20 @@ const (
|
|||||||
// balance to complete the payment.
|
// balance to complete the payment.
|
||||||
FailureReasonInsufficientBalance FailureReason = 4
|
FailureReasonInsufficientBalance FailureReason = 4
|
||||||
|
|
||||||
// TODO(halseth): cancel state.
|
// FailureReasonCanceled indicates that the payment was canceled by the
|
||||||
|
// user.
|
||||||
|
FailureReasonCanceled FailureReason = 5
|
||||||
|
|
||||||
// TODO(joostjager): Add failure reasons for:
|
// TODO(joostjager): Add failure reasons for:
|
||||||
// LocalLiquidityInsufficient, RemoteCapacityInsufficient.
|
// LocalLiquidityInsufficient, RemoteCapacityInsufficient.
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error returns a human readable error string for the FailureReason.
|
// Error returns a human-readable error string for the FailureReason.
|
||||||
func (r FailureReason) Error() string {
|
func (r FailureReason) Error() string {
|
||||||
return r.String()
|
return r.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a human readable FailureReason.
|
// String returns a human-readable FailureReason.
|
||||||
func (r FailureReason) String() string {
|
func (r FailureReason) String() string {
|
||||||
switch r {
|
switch r {
|
||||||
case FailureReasonTimeout:
|
case FailureReasonTimeout:
|
||||||
@@ -171,6 +173,8 @@ func (r FailureReason) String() string {
|
|||||||
return "incorrect_payment_details"
|
return "incorrect_payment_details"
|
||||||
case FailureReasonInsufficientBalance:
|
case FailureReasonInsufficientBalance:
|
||||||
return "insufficient_balance"
|
return "insufficient_balance"
|
||||||
|
case FailureReasonCanceled:
|
||||||
|
return "canceled"
|
||||||
}
|
}
|
||||||
|
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|||||||
@@ -1747,6 +1747,9 @@ func marshallPaymentFailureReason(reason *channeldb.FailureReason) (
|
|||||||
|
|
||||||
case channeldb.FailureReasonInsufficientBalance:
|
case channeldb.FailureReasonInsufficientBalance:
|
||||||
return lnrpc.PaymentFailureReason_FAILURE_REASON_INSUFFICIENT_BALANCE, nil
|
return lnrpc.PaymentFailureReason_FAILURE_REASON_INSUFFICIENT_BALANCE, nil
|
||||||
|
|
||||||
|
case channeldb.FailureReasonCanceled:
|
||||||
|
return lnrpc.PaymentFailureReason_FAILURE_REASON_CANCELED, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, errors.New("unknown failure reason")
|
return 0, errors.New("unknown failure reason")
|
||||||
|
|||||||
@@ -322,10 +322,13 @@ func (p *paymentLifecycle) checkContext(ctx context.Context) error {
|
|||||||
// user-provided timeout was reached, or the context was
|
// user-provided timeout was reached, or the context was
|
||||||
// canceled, either to a manual cancellation or due to an
|
// canceled, either to a manual cancellation or due to an
|
||||||
// unknown error.
|
// unknown error.
|
||||||
|
var reason channeldb.FailureReason
|
||||||
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
|
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
|
||||||
|
reason = channeldb.FailureReasonTimeout
|
||||||
log.Warnf("Payment attempt not completed before "+
|
log.Warnf("Payment attempt not completed before "+
|
||||||
"timeout, id=%s", p.identifier.String())
|
"timeout, id=%s", p.identifier.String())
|
||||||
} else {
|
} else {
|
||||||
|
reason = channeldb.FailureReasonCanceled
|
||||||
log.Warnf("Payment attempt context canceled, id=%s",
|
log.Warnf("Payment attempt context canceled, id=%s",
|
||||||
p.identifier.String())
|
p.identifier.String())
|
||||||
}
|
}
|
||||||
@@ -334,7 +337,6 @@ func (p *paymentLifecycle) checkContext(ctx context.Context) error {
|
|||||||
// inflight HTLCs or not, its status will now either be
|
// inflight HTLCs or not, its status will now either be
|
||||||
// `StatusInflight` or `StatusFailed`. In either case, no more
|
// `StatusInflight` or `StatusFailed`. In either case, no more
|
||||||
// HTLCs will be attempted.
|
// HTLCs will be attempted.
|
||||||
reason := channeldb.FailureReasonTimeout
|
|
||||||
err := p.router.cfg.Control.FailPayment(p.identifier, reason)
|
err := p.router.cfg.Control.FailPayment(p.identifier, reason)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("FailPayment got %w", err)
|
return fmt.Errorf("FailPayment got %w", err)
|
||||||
|
|||||||
@@ -772,17 +772,17 @@ func TestResumePaymentFailContextCancel(t *testing.T) {
|
|||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
m.control.On(
|
m.control.On(
|
||||||
"FailPayment", p.identifier, channeldb.FailureReasonTimeout,
|
"FailPayment", p.identifier, channeldb.FailureReasonCanceled,
|
||||||
).Return(nil).Once()
|
).Return(nil).Once()
|
||||||
|
|
||||||
// 5. decideNextStep now returns stepExit.
|
// 4. decideNextStep now returns stepExit.
|
||||||
m.payment.On("AllowMoreAttempts").Return(false, nil).Once().
|
m.payment.On("AllowMoreAttempts").Return(false, nil).Once().
|
||||||
On("NeedWaitAttempts").Return(false, nil).Once()
|
On("NeedWaitAttempts").Return(false, nil).Once()
|
||||||
|
|
||||||
// 6. Control tower deletes failed attempts.
|
// 5. Control tower deletes failed attempts.
|
||||||
m.control.On("DeleteFailedAttempts", p.identifier).Return(nil).Once()
|
m.control.On("DeleteFailedAttempts", p.identifier).Return(nil).Once()
|
||||||
|
|
||||||
// 7. We will observe FailureReasonError if the context was cancelled.
|
// 6. We will observe FailureReasonError if the context was cancelled.
|
||||||
reason := channeldb.FailureReasonError
|
reason := channeldb.FailureReasonError
|
||||||
m.payment.On("TerminalInfo").Return(nil, &reason)
|
m.payment.On("TerminalInfo").Return(nil, &reason)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user