routing: add context to reloadInflightAttempts
What changed, and why it matters
This commit is a small code-quality cleanup. It changes one internal function so it accepts a context parameter from its caller instead of creating a blank placeholder context internally. There is no security fix here and no behavior change visible to users.
No security action required. Treat as normal maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors paymentLifecycle.reloadInflightAttempts to take a context.Context argument rather than using context.TODO() inside the function. The caller in resumePayment now passes its existing ctx, and the test passes t.Context(). This is a propagation of cancellation/timeout context through the call stack, not a vulnerability remediation.
Changed components
routing/payment_lifecycle.gorouting/payment_lifecycle_test.goInspect captured patch +4 / −6
diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go
index c6f6154..763cf43 100644
--- a/routing/payment_lifecycle.go
+++ b/routing/payment_lifecycle.go
@@ -209,7 +209,7 @@ func (p *paymentLifecycle) resumePayment(ctx context.Context) ([32]byte,
// If we had any existing attempts outstanding, we'll start by spinning
// up goroutines that'll collect their results and deliver them to the
// lifecycle loop below.
- payment, err := p.reloadInflightAttempts()
+ payment, err := p.reloadInflightAttempts(ctx)
if err != nil {
return [32]byte{}, nil, err
}
@@ -1138,10 +1138,8 @@ func (p *paymentLifecycle) patchLegacyPaymentHash(
// reloadInflightAttempts is called when the payment lifecycle is resumed after
// a restart. It reloads all inflight attempts from the control tower and
// collects the results of the attempts that have been sent before.
-func (p *paymentLifecycle) reloadInflightAttempts() (paymentsdb.DBMPPayment,
- error) {
-
- ctx := context.TODO()
+func (p *paymentLifecycle) reloadInflightAttempts(
+ ctx context.Context) (paymentsdb.DBMPPayment, error) {
payment, err := p.router.cfg.Control.FetchPayment(ctx, p.identifier)
if err != nil {
diff --git a/routing/payment_lifecycle_test.go b/routing/payment_lifecycle_test.go
index 61ae83a..82e2f80 100644
--- a/routing/payment_lifecycle_test.go
+++ b/routing/payment_lifecycle_test.go
@@ -1850,7 +1850,7 @@ func TestReloadInflightAttemptsLegacy(t *testing.T) {
})
// Now call the method under test.
- payment, err := p.reloadInflightAttempts()
+ payment, err := p.reloadInflightAttempts(t.Context())
require.NoError(t, err)
require.Equal(t, m.payment, payment)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.