Skip to content

Commit 6b88d04

Browse files
committed
multi: thread context through FailAttempt
1 parent 4a27dbc commit 6b88d04

File tree

10 files changed

+33
-26
lines changed

10 files changed

+33
-26
lines changed

payments/db/interface.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ type PaymentControl interface {
7979
*HTLCSettleInfo) (*MPPayment, error)
8080

8181
// FailAttempt marks the given payment attempt failed.
82-
FailAttempt(lntypes.Hash, uint64, *HTLCFailInfo) (*MPPayment, error)
82+
FailAttempt(context.Context, lntypes.Hash, uint64,
83+
*HTLCFailInfo) (*MPPayment, error)
8384

8485
// Fail transitions a payment into the Failed state, and records
8586
// the ultimate reason the payment failed. Note that this should only

payments/db/kv_store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func (p *KVStore) SettleAttempt(_ context.Context, hash lntypes.Hash,
443443
}
444444

445445
// FailAttempt marks the given payment attempt failed.
446-
func (p *KVStore) FailAttempt(hash lntypes.Hash,
446+
func (p *KVStore) FailAttempt(_ context.Context, hash lntypes.Hash,
447447
attemptID uint64, failInfo *HTLCFailInfo) (*MPPayment, error) {
448448

449449
var b bytes.Buffer

payments/db/kv_store_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestKVStoreDeleteNonInFlight(t *testing.T) {
9595
// Fail the payment attempt.
9696
htlcFailure := HTLCFailUnreadable
9797
_, err := paymentDB.FailAttempt(
98-
info.PaymentIdentifier, attempt.AttemptID,
98+
ctx, info.PaymentIdentifier, attempt.AttemptID,
9999
&HTLCFailInfo{
100100
Reason: htlcFailure,
101101
},

payments/db/payment_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func createTestPayments(t *testing.T, p DB, payments []*payment) {
148148

149149
htlcFailure := HTLCFailUnreadable
150150
_, err = p.FailAttempt(
151-
info.PaymentIdentifier, attempt.AttemptID,
151+
ctx, info.PaymentIdentifier, attempt.AttemptID,
152152
&HTLCFailInfo{
153153
Reason: htlcFailure,
154154
},
@@ -175,7 +175,7 @@ func createTestPayments(t *testing.T, p DB, payments []*payment) {
175175
case StatusFailed:
176176
htlcFailure := HTLCFailUnreadable
177177
_, err = p.FailAttempt(
178-
info.PaymentIdentifier, attempt.AttemptID,
178+
ctx, info.PaymentIdentifier, attempt.AttemptID,
179179
&HTLCFailInfo{
180180
Reason: htlcFailure,
181181
},
@@ -1579,7 +1579,7 @@ func TestSwitchFail(t *testing.T) {
15791579

15801580
htlcReason := HTLCFailUnreadable
15811581
_, err = paymentDB.FailAttempt(
1582-
info.PaymentIdentifier, attempt.AttemptID,
1582+
ctx, info.PaymentIdentifier, attempt.AttemptID,
15831583
&HTLCFailInfo{
15841584
Reason: htlcReason,
15851585
},
@@ -1763,7 +1763,7 @@ func TestMultiShard(t *testing.T) {
17631763
a := attempts[1]
17641764
htlcFail := HTLCFailUnreadable
17651765
_, err = paymentDB.FailAttempt(
1766-
info.PaymentIdentifier, a.AttemptID,
1766+
ctx, info.PaymentIdentifier, a.AttemptID,
17671767
&HTLCFailInfo{
17681768
Reason: htlcFail,
17691769
},
@@ -1812,7 +1812,7 @@ func TestMultiShard(t *testing.T) {
18121812
)
18131813
} else {
18141814
_, err := paymentDB.FailAttempt(
1815-
info.PaymentIdentifier, a.AttemptID,
1815+
ctx, info.PaymentIdentifier, a.AttemptID,
18161816
&HTLCFailInfo{
18171817
Reason: htlcFail,
18181818
},
@@ -1903,7 +1903,7 @@ func TestMultiShard(t *testing.T) {
19031903
} else {
19041904
// Fail the attempt.
19051905
_, err := paymentDB.FailAttempt(
1906-
info.PaymentIdentifier, a.AttemptID,
1906+
ctx, info.PaymentIdentifier, a.AttemptID,
19071907
&HTLCFailInfo{
19081908
Reason: htlcFail,
19091909
},

payments/db/sql_store.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,11 +1037,9 @@ func (s *SQLStore) SettleAttempt(ctx context.Context, paymentHash lntypes.Hash,
10371037
}
10381038

10391039
// FailAttempt marks the given attempt failed.
1040-
func (s *SQLStore) FailAttempt(paymentHash lntypes.Hash,
1040+
func (s *SQLStore) FailAttempt(ctx context.Context, paymentHash lntypes.Hash,
10411041
attemptID uint64, failInfo *HTLCFailInfo) (*MPPayment, error) {
10421042

1043-
ctx := context.TODO()
1044-
10451043
var mpPayment *MPPayment
10461044

10471045
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {

routing/control_tower.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ type ControlTower interface {
5050
// FailAttempt marks the given payment attempt failed.
5151
//
5252
// NOTE: Subscribers should be notified by the new state of the payment.
53-
FailAttempt(lntypes.Hash, uint64, *paymentsdb.HTLCFailInfo) (
54-
*paymentsdb.HTLCAttempt, error)
53+
FailAttempt(context.Context, lntypes.Hash, uint64,
54+
*paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt, error)
5555

5656
// FetchPayment fetches the payment corresponding to the given payment
5757
// hash.
@@ -239,14 +239,14 @@ func (p *controlTower) SettleAttempt(ctx context.Context,
239239
}
240240

241241
// FailAttempt marks the given payment attempt failed.
242-
func (p *controlTower) FailAttempt(paymentHash lntypes.Hash,
243-
attemptID uint64, failInfo *paymentsdb.HTLCFailInfo) (
244-
*paymentsdb.HTLCAttempt, error) {
242+
func (p *controlTower) FailAttempt(ctx context.Context,
243+
paymentHash lntypes.Hash, attemptID uint64,
244+
failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt, error) {
245245

246246
p.paymentsMtx.Lock(paymentHash)
247247
defer p.paymentsMtx.Unlock(paymentHash)
248248

249-
payment, err := p.db.FailAttempt(paymentHash, attemptID, failInfo)
249+
payment, err := p.db.FailAttempt(ctx, paymentHash, attemptID, failInfo)
250250
if err != nil {
251251
return nil, err
252252
}

routing/control_tower_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,8 @@ func TestKVStoreUnsubscribeSuccess(t *testing.T) {
448448
Reason: paymentsdb.HTLCFailInternal,
449449
}
450450
_, err = pControl.FailAttempt(
451-
info.PaymentIdentifier, attempt.AttemptID, &failInfo,
451+
t.Context(), info.PaymentIdentifier, attempt.AttemptID,
452+
&failInfo,
452453
)
453454
require.NoError(t, err, "unable to fail htlc")
454455

@@ -502,7 +503,8 @@ func testKVStoreSubscribeFail(t *testing.T, registerAttempt,
502503
Reason: paymentsdb.HTLCFailInternal,
503504
}
504505
htlcAttempt, err := pControl.FailAttempt(
505-
info.PaymentIdentifier, attempt.AttemptID, &failInfo,
506+
t.Context(), info.PaymentIdentifier, attempt.AttemptID,
507+
&failInfo,
506508
)
507509
if err != nil {
508510
t.Fatalf("unable to fail htlc: %v", err)

routing/mock_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,9 @@ func (m *mockControlTowerOld) SettleAttempt(_ context.Context,
451451
return nil, fmt.Errorf("pid not found")
452452
}
453453

454-
func (m *mockControlTowerOld) FailAttempt(phash lntypes.Hash, pid uint64,
455-
failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt, error) {
454+
func (m *mockControlTowerOld) FailAttempt(_ context.Context, phash lntypes.Hash,
455+
pid uint64, failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt,
456+
error) {
456457

457458
if m.failAttempt != nil {
458459
m.failAttempt <- failAttemptArgs{failInfo}
@@ -767,8 +768,9 @@ func (m *mockControlTower) SettleAttempt(_ context.Context, phash lntypes.Hash,
767768
return attempt.(*paymentsdb.HTLCAttempt), args.Error(1)
768769
}
769770

770-
func (m *mockControlTower) FailAttempt(phash lntypes.Hash, pid uint64,
771-
failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt, error) {
771+
func (m *mockControlTower) FailAttempt(_ context.Context, phash lntypes.Hash,
772+
pid uint64, failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt,
773+
error) {
772774

773775
args := m.Called(phash, pid, failInfo)
774776

routing/payment_lifecycle.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ func (p *paymentLifecycle) handleFailureMessage(rt *route.Route,
10031003
func (p *paymentLifecycle) failAttempt(attemptID uint64,
10041004
sendError error) (*attemptResult, error) {
10051005

1006+
ctx := context.TODO()
1007+
10061008
log.Warnf("Attempt %v for payment %v failed: %v", attemptID,
10071009
p.identifier, sendError)
10081010

@@ -1019,7 +1021,7 @@ func (p *paymentLifecycle) failAttempt(attemptID uint64,
10191021
}
10201022

10211023
attempt, err := p.router.cfg.Control.FailAttempt(
1022-
p.identifier, attemptID, failInfo,
1024+
ctx, p.identifier, attemptID, failInfo,
10231025
)
10241026
if err != nil {
10251027
return nil, err

routing/router.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,8 @@ func (r *ChannelRouter) resumePayments() error {
15311531
func (r *ChannelRouter) failStaleAttempt(a paymentsdb.HTLCAttempt,
15321532
payHash lntypes.Hash) {
15331533

1534+
ctx := context.TODO()
1535+
15341536
// We can only fail inflight HTLCs so we skip the settled/failed ones.
15351537
if a.Failure != nil || a.Settle != nil {
15361538
return
@@ -1614,7 +1616,7 @@ func (r *ChannelRouter) failStaleAttempt(a paymentsdb.HTLCAttempt,
16141616
Reason: paymentsdb.HTLCFailUnknown,
16151617
FailTime: r.cfg.Clock.Now(),
16161618
}
1617-
_, err = r.cfg.Control.FailAttempt(payHash, a.AttemptID, failInfo)
1619+
_, err = r.cfg.Control.FailAttempt(ctx, payHash, a.AttemptID, failInfo)
16181620
if err != nil {
16191621
log.Errorf("Fail attempt=%v got error: %v", a.AttemptID, err)
16201622
}

0 commit comments

Comments
 (0)