multi: thread context through DeleteFailedAttempts
This commit is contained in:
7 files changed
+44
-18
No files matched your search
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user