multi: thread context through Fail payment functions
This commit is contained in:
10 files changed
+41
-23
No files matched your search
@@ -66,7 +66,8 @@ type ControlTower interface {
|
||||
// payment.
|
||||
//
|
||||
// NOTE: Subscribers should be notified by the new state of the payment.
|
||||
FailPayment(lntypes.Hash, paymentsdb.FailureReason) error
|
||||
FailPayment(context.Context, lntypes.Hash,
|
||||
paymentsdb.FailureReason) error
|
||||
|
||||
// FetchInFlightPayments returns all payments with status InFlight.
|
||||
FetchInFlightPayments(ctx context.Context) ([]*paymentsdb.MPPayment,
|
||||
@@ -272,13 +273,13 @@ func (p *controlTower) FetchPayment(ctx context.Context,
|
||||
//
|
||||
// NOTE: This method will overwrite the failure reason if the payment is already
|
||||
// failed.
|
||||
func (p *controlTower) FailPayment(paymentHash lntypes.Hash,
|
||||
reason paymentsdb.FailureReason) error {
|
||||
func (p *controlTower) FailPayment(ctx context.Context,
|
||||
paymentHash lntypes.Hash, reason paymentsdb.FailureReason) error {
|
||||
|
||||
p.paymentsMtx.Lock(paymentHash)
|
||||
defer p.paymentsMtx.Unlock(paymentHash)
|
||||
|
||||
payment, err := p.db.Fail(paymentHash, reason)
|
||||
payment, err := p.db.Fail(ctx, paymentHash, reason)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -516,7 +516,8 @@ func testKVStoreSubscribeFail(t *testing.T, registerAttempt,
|
||||
|
||||
// Mark the payment as failed.
|
||||
err = pControl.FailPayment(
|
||||
info.PaymentIdentifier, paymentsdb.FailureReasonTimeout,
|
||||
t.Context(), info.PaymentIdentifier,
|
||||
paymentsdb.FailureReasonTimeout,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -491,7 +491,7 @@ func (m *mockControlTowerOld) FailAttempt(_ context.Context, phash lntypes.Hash,
|
||||
return nil, fmt.Errorf("pid not found")
|
||||
}
|
||||
|
||||
func (m *mockControlTowerOld) FailPayment(phash lntypes.Hash,
|
||||
func (m *mockControlTowerOld) FailPayment(_ context.Context, phash lntypes.Hash,
|
||||
reason paymentsdb.FailureReason) error {
|
||||
|
||||
m.Lock()
|
||||
@@ -782,7 +782,7 @@ func (m *mockControlTower) FailAttempt(_ context.Context, phash lntypes.Hash,
|
||||
return attempt.(*paymentsdb.HTLCAttempt), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *mockControlTower) FailPayment(phash lntypes.Hash,
|
||||
func (m *mockControlTower) FailPayment(_ context.Context, phash lntypes.Hash,
|
||||
reason paymentsdb.FailureReason) error {
|
||||
|
||||
args := m.Called(phash, reason)
|
||||
|
||||
@@ -364,11 +364,18 @@ func (p *paymentLifecycle) checkContext(ctx context.Context) error {
|
||||
p.identifier.String())
|
||||
}
|
||||
|
||||
// The context is already cancelled at this point, so we create
|
||||
// a new context so the payment can successfully be marked as
|
||||
// failed.
|
||||
cleanupCtx := context.WithoutCancel(ctx)
|
||||
|
||||
// By marking the payment failed, depending on whether it has
|
||||
// inflight HTLCs or not, its status will now either be
|
||||
// `StatusInflight` or `StatusFailed`. In either case, no more
|
||||
// HTLCs will be attempted.
|
||||
err := p.router.cfg.Control.FailPayment(p.identifier, reason)
|
||||
err := p.router.cfg.Control.FailPayment(
|
||||
cleanupCtx, p.identifier, reason,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("FailPayment got %w", err)
|
||||
}
|
||||
@@ -389,6 +396,8 @@ func (p *paymentLifecycle) checkContext(ctx context.Context) error {
|
||||
func (p *paymentLifecycle) requestRoute(
|
||||
ps *paymentsdb.MPPaymentState) (*route.Route, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
remainingFees := p.calcFeeBudget(ps.FeesPaid)
|
||||
|
||||
// Query our payment session to construct a route.
|
||||
@@ -430,7 +439,9 @@ func (p *paymentLifecycle) requestRoute(
|
||||
log.Warnf("Marking payment %v permanently failed with no route: %v",
|
||||
p.identifier, failureCode)
|
||||
|
||||
err = p.router.cfg.Control.FailPayment(p.identifier, failureCode)
|
||||
err = p.router.cfg.Control.FailPayment(
|
||||
ctx, p.identifier, failureCode,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FailPayment got: %w", err)
|
||||
}
|
||||
@@ -800,6 +811,8 @@ func (p *paymentLifecycle) failPaymentAndAttempt(
|
||||
attemptID uint64, reason *paymentsdb.FailureReason,
|
||||
sendErr error) (*attemptResult, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
log.Errorf("Payment %v failed: final_outcome=%v, raw_err=%v",
|
||||
p.identifier, *reason, sendErr)
|
||||
|
||||
@@ -808,7 +821,9 @@ func (p *paymentLifecycle) failPaymentAndAttempt(
|
||||
// NOTE: we must fail the payment first before failing the attempt.
|
||||
// Otherwise, once the attempt is marked as failed, another goroutine
|
||||
// might make another attempt while we are failing the payment.
|
||||
err := p.router.cfg.Control.FailPayment(p.identifier, *reason)
|
||||
err := p.router.cfg.Control.FailPayment(
|
||||
ctx, p.identifier, *reason,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Unable to fail payment: %v", err)
|
||||
return nil, err
|
||||
|
||||
+3
-1
@@ -1088,7 +1088,9 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
|
||||
return nil
|
||||
}
|
||||
|
||||
return r.cfg.Control.FailPayment(paymentIdentifier, reason)
|
||||
return r.cfg.Control.FailPayment(
|
||||
ctx, paymentIdentifier, reason,
|
||||
)
|
||||
}
|
||||
|
||||
log.Debugf("SendToRoute for payment %v with skipTempErr=%v",
|
||||
|
||||
Reference in new issue
Block a user