multi: thread context through RegisterAttempt method
This commit is contained in:
9 files changed
+70
-42
No files matched your search
@@ -31,7 +31,8 @@ type ControlTower interface {
|
||||
// RegisterAttempt atomically records the provided HTLCAttemptInfo.
|
||||
//
|
||||
// NOTE: Subscribers should be notified by the new state of the payment.
|
||||
RegisterAttempt(lntypes.Hash, *paymentsdb.HTLCAttemptInfo) error
|
||||
RegisterAttempt(context.Context, lntypes.Hash,
|
||||
*paymentsdb.HTLCAttemptInfo) error
|
||||
|
||||
// SettleAttempt marks the given attempt settled with the preimage. If
|
||||
// this is a multi shard payment, this might implicitly mean the the
|
||||
@@ -196,13 +197,13 @@ func (p *controlTower) DeleteFailedAttempts(paymentHash lntypes.Hash) error {
|
||||
|
||||
// RegisterAttempt atomically records the provided HTLCAttemptInfo to the
|
||||
// DB.
|
||||
func (p *controlTower) RegisterAttempt(paymentHash lntypes.Hash,
|
||||
attempt *paymentsdb.HTLCAttemptInfo) error {
|
||||
func (p *controlTower) RegisterAttempt(ctx context.Context,
|
||||
paymentHash lntypes.Hash, attempt *paymentsdb.HTLCAttemptInfo) error {
|
||||
|
||||
p.paymentsMtx.Lock(paymentHash)
|
||||
defer p.paymentsMtx.Unlock(paymentHash)
|
||||
|
||||
payment, err := p.db.RegisterAttempt(paymentHash, attempt)
|
||||
payment, err := p.db.RegisterAttempt(ctx, paymentHash, attempt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -92,7 +92,9 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
|
||||
require.NoError(t, err, "expected subscribe to succeed, but got")
|
||||
|
||||
// Register an attempt.
|
||||
err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
err = pControl.RegisterAttempt(
|
||||
t.Context(), info.PaymentIdentifier, attempt,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -221,7 +223,9 @@ func TestKVStoreSubscribeAllSuccess(t *testing.T) {
|
||||
require.NoError(t, err, "expected subscribe to succeed, but got: %v")
|
||||
|
||||
// Register an attempt.
|
||||
err = pControl.RegisterAttempt(info1.PaymentIdentifier, attempt1)
|
||||
err = pControl.RegisterAttempt(
|
||||
t.Context(), info1.PaymentIdentifier, attempt1,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Initiate a second payment after the subscription is already active.
|
||||
@@ -232,7 +236,9 @@ func TestKVStoreSubscribeAllSuccess(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Register an attempt on the second payment.
|
||||
err = pControl.RegisterAttempt(info2.PaymentIdentifier, attempt2)
|
||||
err = pControl.RegisterAttempt(
|
||||
t.Context(), info2.PaymentIdentifier, attempt2,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Mark the first payment as successful.
|
||||
@@ -341,7 +347,9 @@ func TestKVStoreSubscribeAllImmediate(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Register a payment update.
|
||||
err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
err = pControl.RegisterAttempt(
|
||||
t.Context(), info.PaymentIdentifier, attempt,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
subscription, err := pControl.SubscribeAllPayments()
|
||||
@@ -414,7 +422,9 @@ func TestKVStoreUnsubscribeSuccess(t *testing.T) {
|
||||
subscription1.Close()
|
||||
|
||||
// Register a payment update.
|
||||
err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
err = pControl.RegisterAttempt(
|
||||
t.Context(), info.PaymentIdentifier, attempt,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Assert only subscription 2 receives the update.
|
||||
@@ -479,10 +489,10 @@ func testKVStoreSubscribeFail(t *testing.T, registerAttempt,
|
||||
// making any attempts at all.
|
||||
if registerAttempt {
|
||||
// Register an attempt.
|
||||
err = pControl.RegisterAttempt(info.PaymentIdentifier, attempt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = pControl.RegisterAttempt(
|
||||
t.Context(), info.PaymentIdentifier, attempt,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Fail the payment attempt.
|
||||
failInfo := paymentsdb.HTLCFailInfo{
|
||||
|
||||
@@ -354,8 +354,8 @@ func (m *mockControlTowerOld) DeleteFailedAttempts(phash lntypes.Hash) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockControlTowerOld) RegisterAttempt(phash lntypes.Hash,
|
||||
a *paymentsdb.HTLCAttemptInfo) error {
|
||||
func (m *mockControlTowerOld) RegisterAttempt(_ context.Context,
|
||||
phash lntypes.Hash, a *paymentsdb.HTLCAttemptInfo) error {
|
||||
|
||||
if m.registerAttempt != nil {
|
||||
m.registerAttempt <- registerAttemptArgs{a}
|
||||
@@ -746,8 +746,8 @@ func (m *mockControlTower) DeleteFailedAttempts(phash lntypes.Hash) error {
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
func (m *mockControlTower) RegisterAttempt(phash lntypes.Hash,
|
||||
a *paymentsdb.HTLCAttemptInfo) error {
|
||||
func (m *mockControlTower) RegisterAttempt(_ context.Context,
|
||||
phash lntypes.Hash, a *paymentsdb.HTLCAttemptInfo) error {
|
||||
|
||||
args := m.Called(phash, a)
|
||||
return args.Error(0)
|
||||
|
||||
@@ -584,6 +584,8 @@ func (p *paymentLifecycle) collectResult(
|
||||
func (p *paymentLifecycle) registerAttempt(rt *route.Route,
|
||||
remainingAmt lnwire.MilliSatoshi) (*paymentsdb.HTLCAttempt, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
// If this route will consume the last remaining amount to send
|
||||
// to the receiver, this will be our last shard (for now).
|
||||
isLastAttempt := rt.ReceiverAmt() == remainingAmt
|
||||
@@ -601,7 +603,7 @@ func (p *paymentLifecycle) registerAttempt(rt *route.Route,
|
||||
// Switch for its whereabouts. The route is needed to handle the result
|
||||
// when it eventually comes back.
|
||||
err = p.router.cfg.Control.RegisterAttempt(
|
||||
p.identifier, &attempt.HTLCAttemptInfo,
|
||||
ctx, p.identifier, &attempt.HTLCAttemptInfo,
|
||||
)
|
||||
|
||||
return attempt, err
|
||||
|
||||
Reference in new issue
Block a user