multi: thread context through InitPayment

This commit is contained in:
ziggie committed 2026-02-25 08:02:23 +01:00
1 parent 10062ca9ac
commit 60026494b1
9 files changed
+46 -39

No files matched your search

+21 -13
View File
@@ -125,6 +125,8 @@ type payment struct {
func createTestPayments(t *testing.T, p DB, payments []*payment) {
t.Helper()
ctx := t.Context()
attemptID := uint64(0)
for i := 0; i < len(payments); i++ {
@@ -145,7 +147,7 @@ func createTestPayments(t *testing.T, p DB, payments []*payment) {
attemptID++
// Init the payment.
err = p.InitPayment(info.PaymentIdentifier, info)
err = p.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to send htlc message")
// Register and fail the first attempt for all payments.
@@ -559,6 +561,8 @@ func testDeleteFailedAttempts(t *testing.T, keepFailedPaymentAttempts bool) {
func TestMPPRecordValidation(t *testing.T) {
t.Parallel()
ctx := t.Context()
paymentDB, _ := NewTestDB(t)
preimg, err := genPreimage(t)
@@ -575,7 +579,7 @@ func TestMPPRecordValidation(t *testing.T) {
require.NoError(t, err, "unable to generate htlc message")
// Init the payment.
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to send htlc message")
// Create three unique attempts we'll use for the test, and
@@ -633,7 +637,7 @@ func TestMPPRecordValidation(t *testing.T) {
require.NoError(t, err, "unable to generate htlc message")
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to send htlc message")
attempt.Route.FinalHop().MPP = nil
@@ -1722,6 +1726,8 @@ func TestDeletePayments(t *testing.T) {
func TestSwitchDoubleSend(t *testing.T) {
t.Parallel()
ctx := t.Context()
paymentDB, harness := NewTestDB(t)
preimg, err := genPreimage(t)
@@ -1734,7 +1740,7 @@ func TestSwitchDoubleSend(t *testing.T) {
// Sends base htlc message which initiate base status and move it to
// StatusInFlight and verifies that it was changed.
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to send htlc message")
harness.AssertPaymentIndex(t, info.PaymentIdentifier)
@@ -1748,7 +1754,7 @@ func TestSwitchDoubleSend(t *testing.T) {
// Try to initiate double sending of htlc message with the same
// payment hash, should result in error indicating that payment has
// already been sent.
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.ErrorIs(t, err, ErrPaymentExists)
// Record an attempt.
@@ -1766,7 +1772,7 @@ func TestSwitchDoubleSend(t *testing.T) {
)
// Sends base htlc message which initiate StatusInFlight.
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
if !errors.Is(err, ErrPaymentInFlight) {
t.Fatalf("payment control wrong behaviour: " +
"double sending must trigger ErrPaymentInFlight error")
@@ -1789,7 +1795,7 @@ func TestSwitchDoubleSend(t *testing.T) {
t, paymentDB, info.PaymentIdentifier, info, nil, htlc,
)
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
if !errors.Is(err, ErrAlreadyPaid) {
t.Fatalf("unable to send htlc message: %v", err)
}
@@ -1813,7 +1819,7 @@ func TestSwitchFail(t *testing.T) {
require.NoError(t, err)
// Sends base htlc message which initiate StatusInFlight.
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to send htlc message")
harness.AssertPaymentIndex(t, info.PaymentIdentifier)
@@ -1845,7 +1851,7 @@ func TestSwitchFail(t *testing.T) {
// Sends the htlc again, which should succeed since the prior payment
// failed.
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err, "unable to send htlc message")
// Check that our index has been updated, and the old index has been
@@ -1940,7 +1946,7 @@ func TestSwitchFail(t *testing.T) {
// Attempt a final payment, which should now fail since the prior
// payment succeed.
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
if !errors.Is(err, ErrAlreadyPaid) {
t.Fatalf("unable to send htlc message: %v", err)
}
@@ -1951,6 +1957,8 @@ func TestSwitchFail(t *testing.T) {
func TestMultiShard(t *testing.T) {
t.Parallel()
ctx := t.Context()
// We will register three HTLC attempts, and always fail the second
// one. We'll generate all combinations of settling/failing the first
// and third HTLC, and assert that the payment status end up as we
@@ -1977,7 +1985,7 @@ func TestMultiShard(t *testing.T) {
info := genPaymentCreationInfo(t, rhash)
// Init the payment, moving it to the StatusInFlight state.
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err)
harness.AssertPaymentIndex(t, info.PaymentIdentifier)
@@ -2607,7 +2615,7 @@ func TestQueryPayments(t *testing.T) {
// Create a new payment entry in the database.
err = paymentDB.InitPayment(
info.PaymentIdentifier, info,
ctx, info.PaymentIdentifier, info,
)
require.NoError(t, err)
}
@@ -2826,7 +2834,7 @@ func TestFetchInFlightPaymentsMultipleAttempts(t *testing.T) {
// Init payment with double the amount to allow two attempts.
info.Value *= 2
err = paymentDB.InitPayment(info.PaymentIdentifier, info)
err = paymentDB.InitPayment(ctx, info.PaymentIdentifier, info)
require.NoError(t, err)
// Register two attempts for the same payment.