multi: thread context through SettleAttempt
This commit is contained in:
9 files changed
+37
-28
No files matched your search
@@ -86,7 +86,8 @@ type PaymentControl interface {
|
||||
// error to prevent us from making duplicate payments to the same
|
||||
// payment hash. The provided preimage is atomically saved to the DB
|
||||
// for record keeping.
|
||||
SettleAttempt(lntypes.Hash, uint64, *HTLCSettleInfo) (*MPPayment, error)
|
||||
SettleAttempt(context.Context, lntypes.Hash, uint64,
|
||||
*HTLCSettleInfo) (*MPPayment, error)
|
||||
|
||||
// FailAttempt marks the given payment attempt failed.
|
||||
FailAttempt(lntypes.Hash, uint64, *HTLCFailInfo) (*MPPayment, error)
|
||||
|
||||
@@ -430,7 +430,7 @@ func (p *KVStore) RegisterAttempt(_ context.Context, paymentHash lntypes.Hash,
|
||||
// After invoking this method, InitPayment should always return an error to
|
||||
// prevent us from making duplicate payments to the same payment hash. The
|
||||
// provided preimage is atomically saved to the DB for record keeping.
|
||||
func (p *KVStore) SettleAttempt(hash lntypes.Hash,
|
||||
func (p *KVStore) SettleAttempt(_ context.Context, hash lntypes.Hash,
|
||||
attemptID uint64, settleInfo *HTLCSettleInfo) (*MPPayment, error) {
|
||||
|
||||
var b bytes.Buffer
|
||||
|
||||
@@ -133,7 +133,7 @@ func TestKVStoreDeleteNonInFlight(t *testing.T) {
|
||||
case p.success:
|
||||
// Verifies that status was changed to StatusSucceeded.
|
||||
_, err := paymentDB.SettleAttempt(
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
ctx, info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
|
||||
@@ -198,7 +198,7 @@ func createTestPayments(t *testing.T, p DB, payments []*payment) {
|
||||
// Settle the attempt
|
||||
case StatusSucceeded:
|
||||
_, err := p.SettleAttempt(
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
ctx, info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@@ -1643,6 +1643,7 @@ func TestSuccessesWithoutInFlight(t *testing.T) {
|
||||
|
||||
// Attempt to complete the payment should fail.
|
||||
_, err = paymentDB.SettleAttempt(
|
||||
t.Context(),
|
||||
info.PaymentIdentifier, 0,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
@@ -1790,7 +1791,7 @@ func TestSwitchDoubleSend(t *testing.T) {
|
||||
|
||||
// After settling, the error should be ErrAlreadyPaid.
|
||||
_, err = paymentDB.SettleAttempt(
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
ctx, info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@@ -1926,7 +1927,7 @@ func TestSwitchFail(t *testing.T) {
|
||||
// Settle the attempt and verify that status was changed to
|
||||
// StatusSucceeded.
|
||||
payment, err = paymentDB.SettleAttempt(
|
||||
info.PaymentIdentifier, attempt.AttemptID,
|
||||
ctx, info.PaymentIdentifier, attempt.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@@ -2099,7 +2100,7 @@ func TestMultiShard(t *testing.T) {
|
||||
var firstFailReason *FailureReason
|
||||
if test.settleFirst {
|
||||
_, err := paymentDB.SettleAttempt(
|
||||
info.PaymentIdentifier, a.AttemptID,
|
||||
ctx, info.PaymentIdentifier, a.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@@ -2193,7 +2194,7 @@ func TestMultiShard(t *testing.T) {
|
||||
if test.settleLast {
|
||||
// Settle the last outstanding attempt.
|
||||
_, err = paymentDB.SettleAttempt(
|
||||
info.PaymentIdentifier, a.AttemptID,
|
||||
ctx, info.PaymentIdentifier, a.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
@@ -2683,7 +2684,7 @@ func TestQueryPayments(t *testing.T) {
|
||||
copy(preimg[:], rev[:])
|
||||
|
||||
_, err = paymentDB.SettleAttempt(
|
||||
lastPaymentInfo.PaymentIdentifier,
|
||||
ctx, lastPaymentInfo.PaymentIdentifier,
|
||||
attempt.AttemptID,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
@@ -2813,7 +2814,7 @@ func TestFetchInFlightPayments(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = paymentDB.SettleAttempt(
|
||||
payments[2].id, 5,
|
||||
ctx, payments[2].id, 5,
|
||||
&HTLCSettleInfo{
|
||||
Preimage: preimg,
|
||||
},
|
||||
|
||||
@@ -1496,8 +1496,9 @@ func (s *SQLStore) insertRouteHops(ctx context.Context, db SQLQueries,
|
||||
// the PaymentWriter interface and ultimately the DB interface. It represents
|
||||
// step 2 in the payment lifecycle control flow, called after InitPayment and
|
||||
// potentially multiple times for multi-path payments.
|
||||
func (s *SQLStore) RegisterAttempt(ctx context.Context, paymentHash lntypes.Hash,
|
||||
attempt *HTLCAttemptInfo) (*MPPayment, error) {
|
||||
func (s *SQLStore) RegisterAttempt(ctx context.Context,
|
||||
paymentHash lntypes.Hash, attempt *HTLCAttemptInfo) (*MPPayment,
|
||||
error) {
|
||||
|
||||
var mpPayment *MPPayment
|
||||
|
||||
@@ -1621,11 +1622,9 @@ func (s *SQLStore) RegisterAttempt(ctx context.Context, paymentHash lntypes.Hash
|
||||
// the PaymentWriter interface and ultimately the DB interface. It represents
|
||||
// step 3a in the payment lifecycle control flow (step 3b is FailAttempt),
|
||||
// called after RegisterAttempt when an HTLC successfully completes.
|
||||
func (s *SQLStore) SettleAttempt(paymentHash lntypes.Hash,
|
||||
func (s *SQLStore) SettleAttempt(ctx context.Context, paymentHash lntypes.Hash,
|
||||
attemptID uint64, settleInfo *HTLCSettleInfo) (*MPPayment, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
var mpPayment *MPPayment
|
||||
|
||||
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
|
||||
|
||||
Reference in new issue
Block a user