multi: thread context through DeleteFailedAttempts

This commit is contained in:
ziggie committed 2026-02-25 08:02:24 +01:00
1 parent 635a67c94a
commit 7f2df4b088
7 files changed
+44 -18

No files matched your search

+5 -3
View File
@@ -26,7 +26,7 @@ type ControlTower interface {
// DeleteFailedAttempts removes all failed HTLCs from the db. It should
// be called for a given payment whenever all inflight htlcs are
// completed, and the payment has reached a final settled state.
DeleteFailedAttempts(lntypes.Hash) error
DeleteFailedAttempts(context.Context, lntypes.Hash) error
// RegisterAttempt atomically records the provided HTLCAttemptInfo.
//
@@ -192,8 +192,10 @@ func (p *controlTower) InitPayment(ctx context.Context,
// DeleteFailedAttempts deletes all failed htlcs if the payment was
// successfully settled.
func (p *controlTower) DeleteFailedAttempts(paymentHash lntypes.Hash) error {
return p.db.DeleteFailedAttempts(paymentHash)
func (p *controlTower) DeleteFailedAttempts(ctx context.Context,
paymentHash lntypes.Hash) error {
return p.db.DeleteFailedAttempts(ctx, paymentHash)
}
// RegisterAttempt atomically records the provided HTLCAttemptInfo to the
+6 -2
View File
@@ -328,7 +328,9 @@ func (m *mockControlTowerOld) InitPayment(_ context.Context,
return nil
}
func (m *mockControlTowerOld) DeleteFailedAttempts(phash lntypes.Hash) error {
func (m *mockControlTowerOld) DeleteFailedAttempts(_ context.Context,
phash lntypes.Hash) error {
p, ok := m.payments[phash]
if !ok {
return paymentsdb.ErrPaymentNotInitiated
@@ -742,7 +744,9 @@ func (m *mockControlTower) InitPayment(_ context.Context, phash lntypes.Hash,
return args.Error(0)
}
func (m *mockControlTower) DeleteFailedAttempts(phash lntypes.Hash) error {
func (m *mockControlTower) DeleteFailedAttempts(_ context.Context,
phash lntypes.Hash) error {
args := m.Called(phash)
return args.Error(0)
}
+7 -1
View File
@@ -190,6 +190,10 @@ func (p *paymentLifecycle) decideNextStep(
func (p *paymentLifecycle) resumePayment(ctx context.Context) ([32]byte,
*route.Route, error) {
// We need to make sure we can still do db operations after the context
// is cancelled.
cleanupCtx := context.WithoutCancel(ctx)
// When the payment lifecycle loop exits, we make sure to signal any
// sub goroutine of the HTLC attempt to exit, then wait for them to
// return.
@@ -328,7 +332,9 @@ lifecycle:
// Optionally delete the failed attempts from the database. Depends on
// the database options deleting attempts is not allowed so this will
// just be a no-op.
err = p.router.cfg.Control.DeleteFailedAttempts(p.identifier)
err = p.router.cfg.Control.DeleteFailedAttempts(
cleanupCtx, p.identifier,
)
if err != nil {
log.Errorf("Error deleting failed htlc attempts for payment "+
"%v: %v", p.identifier, err)