multi: thread context through FetchInflightPayments
This commit is contained in:
7 files changed
+25
-16
No files matched your search
@@ -25,7 +25,7 @@ type PaymentReader interface {
|
||||
paymentHash lntypes.Hash) (*MPPayment, error)
|
||||
|
||||
// FetchInFlightPayments returns all payments with status InFlight.
|
||||
FetchInFlightPayments() ([]*MPPayment, error)
|
||||
FetchInFlightPayments(ctx context.Context) ([]*MPPayment, error)
|
||||
}
|
||||
|
||||
// PaymentWriter represents the interface to write operations to the payments
|
||||
|
||||
@@ -741,7 +741,9 @@ func fetchPaymentStatus(bucket kvdb.RBucket) (PaymentStatus, error) {
|
||||
}
|
||||
|
||||
// FetchInFlightPayments returns all payments with status InFlight.
|
||||
func (p *KVStore) FetchInFlightPayments() ([]*MPPayment, error) {
|
||||
func (p *KVStore) FetchInFlightPayments(_ context.Context) ([]*MPPayment,
|
||||
error) {
|
||||
|
||||
var (
|
||||
inFlights []*MPPayment
|
||||
start = time.Now()
|
||||
|
||||
@@ -2740,6 +2740,8 @@ func TestQueryPayments(t *testing.T) {
|
||||
func TestFetchInFlightPayments(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := t.Context()
|
||||
|
||||
paymentDB, _ := NewTestDB(t)
|
||||
|
||||
// Register payments with different statuses:
|
||||
@@ -2765,7 +2767,7 @@ func TestFetchInFlightPayments(t *testing.T) {
|
||||
assertDBPayments(t, paymentDB, payments)
|
||||
|
||||
// Fetch in-flight payments.
|
||||
inFlightPayments, err := paymentDB.FetchInFlightPayments()
|
||||
inFlightPayments, err := paymentDB.FetchInFlightPayments(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
// We should only get the two in-flight payments.
|
||||
@@ -2795,7 +2797,7 @@ func TestFetchInFlightPayments(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Fetch in-flight payments again.
|
||||
inFlightPayments, err = paymentDB.FetchInFlightPayments()
|
||||
inFlightPayments, err = paymentDB.FetchInFlightPayments(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
// We should now only get one in-flight payment.
|
||||
@@ -2812,6 +2814,8 @@ func TestFetchInFlightPayments(t *testing.T) {
|
||||
func TestFetchInFlightPaymentsMultipleAttempts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := t.Context()
|
||||
|
||||
paymentDB, _ := NewTestDB(t)
|
||||
|
||||
preimg, err := genPreimage(t)
|
||||
@@ -2843,7 +2847,7 @@ func TestFetchInFlightPaymentsMultipleAttempts(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Both attempts are in-flight. Fetch in-flight payments.
|
||||
inFlightPayments, err := paymentDB.FetchInFlightPayments()
|
||||
inFlightPayments, err := paymentDB.FetchInFlightPayments(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
// We should only get one payment even though it has 2 in-flight
|
||||
|
||||
@@ -972,11 +972,9 @@ func (s *SQLStore) FetchPayment(ctx context.Context,
|
||||
// While inflight payments are typically a small subset, this would improve
|
||||
// memory efficiency for nodes with unusually high numbers of concurrent
|
||||
// payments and would better leverage the existing pagination infrastructure.
|
||||
func (s *SQLStore) FetchInFlightPayments() ([]*MPPayment,
|
||||
func (s *SQLStore) FetchInFlightPayments(ctx context.Context) ([]*MPPayment,
|
||||
error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
var mpPayments []*MPPayment
|
||||
|
||||
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||
|
||||
Reference in new issue
Block a user