multi: thread context through InitPayment
This commit is contained in:
9 files changed
+46
-39
No files matched your search
@@ -20,7 +20,8 @@ type ControlTower interface {
|
||||
// also notifies subscribers of the payment creation.
|
||||
//
|
||||
// NOTE: Subscribers should be notified by the new state of the payment.
|
||||
InitPayment(lntypes.Hash, *paymentsdb.PaymentCreationInfo) error
|
||||
InitPayment(context.Context, lntypes.Hash,
|
||||
*paymentsdb.PaymentCreationInfo) error
|
||||
|
||||
// DeleteFailedAttempts removes all failed HTLCs from the db. It should
|
||||
// be called for a given payment whenever all inflight htlcs are
|
||||
@@ -164,12 +165,10 @@ func NewControlTower(db paymentsdb.DB) ControlTower {
|
||||
// making sure it does not already exist as an in-flight payment. Then this
|
||||
// method returns successfully, the payment is guaranteed to be in the
|
||||
// Initiated state.
|
||||
func (p *controlTower) InitPayment(paymentHash lntypes.Hash,
|
||||
info *paymentsdb.PaymentCreationInfo) error {
|
||||
func (p *controlTower) InitPayment(ctx context.Context,
|
||||
paymentHash lntypes.Hash, info *paymentsdb.PaymentCreationInfo) error {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
err := p.db.InitPayment(paymentHash, info)
|
||||
err := p.db.InitPayment(ctx, paymentHash, info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
err = pControl.InitPayment(t.Context(), info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -212,7 +212,7 @@ func TestKVStoreSubscribeAllSuccess(t *testing.T) {
|
||||
info1, attempt1, preimg1, err := genInfo()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = pControl.InitPayment(info1.PaymentIdentifier, info1)
|
||||
err = pControl.InitPayment(t.Context(), info1.PaymentIdentifier, info1)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Subscription should succeed and immediately report the Initiated
|
||||
@@ -228,7 +228,7 @@ func TestKVStoreSubscribeAllSuccess(t *testing.T) {
|
||||
info2, attempt2, preimg2, err := genInfo()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = pControl.InitPayment(info2.PaymentIdentifier, info2)
|
||||
err = pControl.InitPayment(t.Context(), info2.PaymentIdentifier, info2)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Register an attempt on the second payment.
|
||||
@@ -337,7 +337,7 @@ func TestKVStoreSubscribeAllImmediate(t *testing.T) {
|
||||
info, attempt, _, err := genInfo()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
err = pControl.InitPayment(t.Context(), info.PaymentIdentifier, info)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Register a payment update.
|
||||
@@ -392,7 +392,7 @@ func TestKVStoreUnsubscribeSuccess(t *testing.T) {
|
||||
info, attempt, _, err := genInfo()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
err = pControl.InitPayment(t.Context(), info.PaymentIdentifier, info)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Assert all subscriptions receive the update.
|
||||
@@ -465,7 +465,7 @@ func testKVStoreSubscribeFail(t *testing.T, registerAttempt,
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = pControl.InitPayment(info.PaymentIdentifier, info)
|
||||
err = pControl.InitPayment(t.Context(), info.PaymentIdentifier, info)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -297,8 +297,8 @@ func makeMockControlTower() *mockControlTowerOld {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mockControlTowerOld) InitPayment(phash lntypes.Hash,
|
||||
c *paymentsdb.PaymentCreationInfo) error {
|
||||
func (m *mockControlTowerOld) InitPayment(_ context.Context,
|
||||
phash lntypes.Hash, c *paymentsdb.PaymentCreationInfo) error {
|
||||
|
||||
if m.init != nil {
|
||||
m.init <- initArgs{c}
|
||||
@@ -734,7 +734,7 @@ type mockControlTower struct {
|
||||
|
||||
var _ ControlTower = (*mockControlTower)(nil)
|
||||
|
||||
func (m *mockControlTower) InitPayment(phash lntypes.Hash,
|
||||
func (m *mockControlTower) InitPayment(_ context.Context, phash lntypes.Hash,
|
||||
c *paymentsdb.PaymentCreationInfo) error {
|
||||
|
||||
args := m.Called(phash, c)
|
||||
|
||||
+4
-2
@@ -967,6 +967,8 @@ func spewPayment(payment *LightningPayment) lnutils.LogClosure {
|
||||
func (r *ChannelRouter) PreparePayment(payment *LightningPayment) (
|
||||
PaymentSession, shards.ShardTracker, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
// Assemble any custom data we want to send to the first hop only.
|
||||
var firstHopData fn.Option[tlv.Blob]
|
||||
if len(payment.FirstHopCustomRecords) > 0 {
|
||||
@@ -1026,7 +1028,7 @@ func (r *ChannelRouter) PreparePayment(payment *LightningPayment) (
|
||||
)
|
||||
}
|
||||
|
||||
err = r.cfg.Control.InitPayment(payment.Identifier(), info)
|
||||
err = r.cfg.Control.InitPayment(ctx, payment.Identifier(), info)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -1131,7 +1133,7 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
|
||||
FirstHopCustomRecords: firstHopCustomRecords,
|
||||
}
|
||||
|
||||
err := r.cfg.Control.InitPayment(paymentIdentifier, info)
|
||||
err := r.cfg.Control.InitPayment(ctx, paymentIdentifier, info)
|
||||
switch {
|
||||
// If this is an MPP attempt and the hash is already registered with
|
||||
// the database, we can go on to launch the shard.
|
||||
|
||||
Reference in new issue
Block a user