multi: thread context through FailAttempt
This commit is contained in:
10 files changed
+33
-26
No files matched your search
@@ -90,7 +90,8 @@ type PaymentControl interface {
|
||||
*HTLCSettleInfo) (*MPPayment, error)
|
||||
|
||||
// FailAttempt marks the given payment attempt failed.
|
||||
FailAttempt(lntypes.Hash, uint64, *HTLCFailInfo) (*MPPayment, error)
|
||||
FailAttempt(context.Context, lntypes.Hash, uint64,
|
||||
*HTLCFailInfo) (*MPPayment, error)
|
||||
|
||||
// Fail transitions a payment into the Failed state, and records
|
||||
// the ultimate reason the payment failed. Note that this should only
|
||||
|
||||
@@ -443,7 +443,7 @@ func (p *KVStore) SettleAttempt(_ context.Context, hash lntypes.Hash,
|
||||
}
|
||||
|
||||
// FailAttempt marks the given payment attempt failed.
|
||||
func (p *KVStore) FailAttempt(hash lntypes.Hash,
|
||||
func (p *KVStore) FailAttempt(_ context.Context, hash lntypes.Hash,
|
||||
attemptID uint64, failInfo *HTLCFailInfo) (*MPPayment, error) {
|
||||
|
||||
var b bytes.Buffer
|
||||
|
||||
@@ -100,7 +100,7 @@ func TestKVStoreDeleteNonInFlight(t *testing.T) {
|
||||
// Fail the payment attempt.
|
||||
htlcFailure := HTLCFailUnreadable
|
||||
_, err := paymentDB.FailAttempt(
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
ctx, info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFailure,
|
||||
},
|
||||
|
||||
@@ -156,7 +156,7 @@ func createTestPayments(t *testing.T, p DB, payments []*payment) {
|
||||
|
||||
htlcFailure := HTLCFailUnreadable
|
||||
_, err = p.FailAttempt(
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
ctx, info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFailure,
|
||||
},
|
||||
@@ -183,7 +183,7 @@ func createTestPayments(t *testing.T, p DB, payments []*payment) {
|
||||
case StatusFailed:
|
||||
htlcFailure := HTLCFailUnreadable
|
||||
_, err = p.FailAttempt(
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
ctx, info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFailure,
|
||||
},
|
||||
@@ -1885,7 +1885,7 @@ func TestSwitchFail(t *testing.T) {
|
||||
|
||||
htlcReason := HTLCFailUnreadable
|
||||
_, err = paymentDB.FailAttempt(
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
ctx, info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcReason,
|
||||
},
|
||||
@@ -2069,7 +2069,7 @@ func TestMultiShard(t *testing.T) {
|
||||
a := attempts[1]
|
||||
htlcFail := HTLCFailUnreadable
|
||||
_, err = paymentDB.FailAttempt(
|
||||
info.PaymentIdentifier, a.AttemptID,
|
||||
ctx, info.PaymentIdentifier, a.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFail,
|
||||
},
|
||||
@@ -2118,7 +2118,7 @@ func TestMultiShard(t *testing.T) {
|
||||
)
|
||||
} else {
|
||||
_, err := paymentDB.FailAttempt(
|
||||
info.PaymentIdentifier, a.AttemptID,
|
||||
ctx, info.PaymentIdentifier, a.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFail,
|
||||
},
|
||||
@@ -2209,7 +2209,7 @@ func TestMultiShard(t *testing.T) {
|
||||
} else {
|
||||
// Fail the attempt.
|
||||
_, err := paymentDB.FailAttempt(
|
||||
info.PaymentIdentifier, a.AttemptID,
|
||||
ctx, info.PaymentIdentifier, a.AttemptID,
|
||||
&HTLCFailInfo{
|
||||
Reason: htlcFail,
|
||||
},
|
||||
|
||||
@@ -1695,11 +1695,9 @@ func (s *SQLStore) SettleAttempt(ctx context.Context, paymentHash lntypes.Hash,
|
||||
// the PaymentWriter interface and ultimately the DB interface. It represents
|
||||
// step 3b in the payment lifecycle control flow (step 3a is SettleAttempt),
|
||||
// called after RegisterAttempt when an HTLC fails.
|
||||
func (s *SQLStore) FailAttempt(paymentHash lntypes.Hash,
|
||||
func (s *SQLStore) FailAttempt(ctx context.Context, paymentHash lntypes.Hash,
|
||||
attemptID uint64, failInfo *HTLCFailInfo) (*MPPayment, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
var mpPayment *MPPayment
|
||||
|
||||
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
|
||||
|
||||
@@ -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