multi: thread context through FailAttempt
This commit is contained in:
10 files changed
+33
-26
No files matched your search
@@ -50,8 +50,8 @@ type ControlTower interface {
|
||||
// FailAttempt marks the given payment attempt failed.
|
||||
//
|
||||
// NOTE: Subscribers should be notified by the new state of the payment.
|
||||
FailAttempt(lntypes.Hash, uint64, *paymentsdb.HTLCFailInfo) (
|
||||
*paymentsdb.HTLCAttempt, error)
|
||||
FailAttempt(context.Context, lntypes.Hash, uint64,
|
||||
*paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt, error)
|
||||
|
||||
// FetchPayment fetches the payment corresponding to the given payment
|
||||
// hash.
|
||||
@@ -239,14 +239,14 @@ func (p *controlTower) SettleAttempt(ctx context.Context,
|
||||
}
|
||||
|
||||
// FailAttempt marks the given payment attempt failed.
|
||||
func (p *controlTower) FailAttempt(paymentHash lntypes.Hash,
|
||||
attemptID uint64, failInfo *paymentsdb.HTLCFailInfo) (
|
||||
*paymentsdb.HTLCAttempt, error) {
|
||||
func (p *controlTower) FailAttempt(ctx context.Context,
|
||||
paymentHash lntypes.Hash, attemptID uint64,
|
||||
failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt, error) {
|
||||
|
||||
p.paymentsMtx.Lock(paymentHash)
|
||||
defer p.paymentsMtx.Unlock(paymentHash)
|
||||
|
||||
payment, err := p.db.FailAttempt(paymentHash, attemptID, failInfo)
|
||||
payment, err := p.db.FailAttempt(ctx, paymentHash, attemptID, failInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -448,7 +448,8 @@ func TestKVStoreUnsubscribeSuccess(t *testing.T) {
|
||||
Reason: paymentsdb.HTLCFailInternal,
|
||||
}
|
||||
_, err = pControl.FailAttempt(
|
||||
info.PaymentIdentifier, attempt.AttemptID, &failInfo,
|
||||
t.Context(), info.PaymentIdentifier, attempt.AttemptID,
|
||||
&failInfo,
|
||||
)
|
||||
require.NoError(t, err, "unable to fail htlc")
|
||||
|
||||
@@ -502,7 +503,8 @@ func testKVStoreSubscribeFail(t *testing.T, registerAttempt,
|
||||
Reason: paymentsdb.HTLCFailInternal,
|
||||
}
|
||||
htlcAttempt, err := pControl.FailAttempt(
|
||||
info.PaymentIdentifier, attempt.AttemptID, &failInfo,
|
||||
t.Context(), info.PaymentIdentifier, attempt.AttemptID,
|
||||
&failInfo,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fail htlc: %v", err)
|
||||
|
||||
@@ -451,8 +451,9 @@ func (m *mockControlTowerOld) SettleAttempt(_ context.Context,
|
||||
return nil, fmt.Errorf("pid not found")
|
||||
}
|
||||
|
||||
func (m *mockControlTowerOld) FailAttempt(phash lntypes.Hash, pid uint64,
|
||||
failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt, error) {
|
||||
func (m *mockControlTowerOld) FailAttempt(_ context.Context, phash lntypes.Hash,
|
||||
pid uint64, failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt,
|
||||
error) {
|
||||
|
||||
if m.failAttempt != nil {
|
||||
m.failAttempt <- failAttemptArgs{failInfo}
|
||||
@@ -767,8 +768,9 @@ func (m *mockControlTower) SettleAttempt(_ context.Context, phash lntypes.Hash,
|
||||
return attempt.(*paymentsdb.HTLCAttempt), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *mockControlTower) FailAttempt(phash lntypes.Hash, pid uint64,
|
||||
failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt, error) {
|
||||
func (m *mockControlTower) FailAttempt(_ context.Context, phash lntypes.Hash,
|
||||
pid uint64, failInfo *paymentsdb.HTLCFailInfo) (*paymentsdb.HTLCAttempt,
|
||||
error) {
|
||||
|
||||
args := m.Called(phash, pid, failInfo)
|
||||
|
||||
|
||||
@@ -1003,6 +1003,8 @@ func (p *paymentLifecycle) handleFailureMessage(rt *route.Route,
|
||||
func (p *paymentLifecycle) failAttempt(attemptID uint64,
|
||||
sendError error) (*attemptResult, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
log.Warnf("Attempt %v for payment %v failed: %v", attemptID,
|
||||
p.identifier, sendError)
|
||||
|
||||
@@ -1019,7 +1021,7 @@ func (p *paymentLifecycle) failAttempt(attemptID uint64,
|
||||
}
|
||||
|
||||
attempt, err := p.router.cfg.Control.FailAttempt(
|
||||
p.identifier, attemptID, failInfo,
|
||||
ctx, p.identifier, attemptID, failInfo,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+3
-1
@@ -1531,6 +1531,8 @@ func (r *ChannelRouter) resumePayments() error {
|
||||
func (r *ChannelRouter) failStaleAttempt(a paymentsdb.HTLCAttempt,
|
||||
payHash lntypes.Hash) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
// We can only fail inflight HTLCs so we skip the settled/failed ones.
|
||||
if a.Failure != nil || a.Settle != nil {
|
||||
return
|
||||
@@ -1614,7 +1616,7 @@ func (r *ChannelRouter) failStaleAttempt(a paymentsdb.HTLCAttempt,
|
||||
Reason: paymentsdb.HTLCFailUnknown,
|
||||
FailTime: r.cfg.Clock.Now(),
|
||||
}
|
||||
_, err = r.cfg.Control.FailAttempt(payHash, a.AttemptID, failInfo)
|
||||
_, err = r.cfg.Control.FailAttempt(ctx, payHash, a.AttemptID, failInfo)
|
||||
if err != nil {
|
||||
log.Errorf("Fail attempt=%v got error: %v", a.AttemptID, err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user