diff --git a/routing/control_tower.go b/routing/control_tower.go index 9f95bb252..a0c5b1df7 100644 --- a/routing/control_tower.go +++ b/routing/control_tower.go @@ -46,13 +46,13 @@ type ControlTower interface { // hash. FetchPayment(paymentHash lntypes.Hash) (*channeldb.MPPayment, error) - // Fail transitions a payment into the Failed state, and records the - // ultimate reason the payment failed. Note that this should only be - // called when all active active attempts are already failed. After + // FailPayment transitions a payment into the Failed state, and records + // the ultimate reason the payment failed. Note that this should only + // be called when all active attempts are already failed. After // invoking this method, InitPayment should return nil on its next call // for this payment hash, allowing the user to make a subsequent // payment. - Fail(lntypes.Hash, channeldb.FailureReason) error + FailPayment(lntypes.Hash, channeldb.FailureReason) error // FetchInFlightPayments returns all payments with status InFlight. FetchInFlightPayments() ([]*channeldb.MPPayment, error) @@ -229,11 +229,11 @@ func (p *controlTower) FetchPayment(paymentHash lntypes.Hash) ( return p.db.FetchPayment(paymentHash) } -// Fail transitions a payment into the Failed state, and records the reason the -// payment failed. After invoking this method, InitPayment should return nil on -// its next call for this payment hash, allowing the switch to make a -// subsequent payment. -func (p *controlTower) Fail(paymentHash lntypes.Hash, +// FailPayment transitions a payment into the Failed state, and records the +// reason the payment failed. After invoking this method, InitPayment should +// return nil on its next call for this payment hash, allowing the switch to +// make a subsequent payment. +func (p *controlTower) FailPayment(paymentHash lntypes.Hash, reason channeldb.FailureReason) error { p.paymentsMtx.Lock(paymentHash) diff --git a/routing/control_tower_test.go b/routing/control_tower_test.go index 3dd2c5234..05f049fa2 100644 --- a/routing/control_tower_test.go +++ b/routing/control_tower_test.go @@ -457,7 +457,10 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt, } // Mark the payment as failed. - if err := pControl.Fail(info.PaymentIdentifier, channeldb.FailureReasonTimeout); err != nil { + err = pControl.FailPayment( + info.PaymentIdentifier, channeldb.FailureReasonTimeout, + ) + if err != nil { t.Fatal(err) } diff --git a/routing/mock_test.go b/routing/mock_test.go index b0a9ba4ff..c321db3db 100644 --- a/routing/mock_test.go +++ b/routing/mock_test.go @@ -469,7 +469,7 @@ func (m *mockControlTowerOld) FailAttempt(phash lntypes.Hash, pid uint64, return nil, fmt.Errorf("pid not found") } -func (m *mockControlTowerOld) Fail(phash lntypes.Hash, +func (m *mockControlTowerOld) FailPayment(phash lntypes.Hash, reason channeldb.FailureReason) error { m.Lock() @@ -733,7 +733,7 @@ func (m *mockControlTower) FailAttempt(phash lntypes.Hash, pid uint64, return args.Get(0).(*channeldb.HTLCAttempt), args.Error(1) } -func (m *mockControlTower) Fail(phash lntypes.Hash, +func (m *mockControlTower) FailPayment(phash lntypes.Hash, reason channeldb.FailureReason) error { m.Lock() diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go index 8cf7354c4..cd3ab81f3 100644 --- a/routing/payment_lifecycle.go +++ b/routing/payment_lifecycle.go @@ -233,7 +233,7 @@ lifecycle: // tower, no further shards will be launched and we'll // return with an error the moment all active shards // have finished. - saveErr := p.router.cfg.Control.Fail( + saveErr := p.router.cfg.Control.FailPayment( p.identifier, channeldb.FailureReasonTimeout, ) if saveErr != nil { @@ -273,7 +273,7 @@ lifecycle: "failed with no route: %v", p.identifier, failureCode) - saveErr := p.router.cfg.Control.Fail( + saveErr := p.router.cfg.Control.FailPayment( p.identifier, failureCode, ) if saveErr != nil { @@ -784,7 +784,7 @@ func (p *shardHandler) handleSendError(attempt *channeldb.HTLCAttemptInfo, p.identifier, *reason, sendErr) // Fail the payment via control tower. - if err := p.router.cfg.Control.Fail( + if err := p.router.cfg.Control.FailPayment( p.identifier, *reason, ); err != nil { log.Errorf("unable to report failure to control "+ diff --git a/routing/router.go b/routing/router.go index cf6357c68..7d7ceb7b1 100644 --- a/routing/router.go +++ b/routing/router.go @@ -2253,7 +2253,7 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route, log.Debugf("Invalid route provided for payment %x: %v", paymentIdentifier, err) - controlErr := r.cfg.Control.Fail( + controlErr := r.cfg.Control.FailPayment( paymentIdentifier, channeldb.FailureReasonError, ) if controlErr != nil { @@ -2301,14 +2301,16 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route, // If a non-terminal error is returned and `skipTempErr` is false, then // we'll use the normal no route error. case err == nil && !skipTempErr: - err = r.cfg.Control.Fail( + err = r.cfg.Control.FailPayment( paymentIdentifier, channeldb.FailureReasonNoRoute, ) // If this is a failure reason, then we'll apply the failure directly // to the control tower, and return the normal response to the caller. case goErrors.As(err, &failureReason): - err = r.cfg.Control.Fail(paymentIdentifier, *failureReason) + err = r.cfg.Control.FailPayment( + paymentIdentifier, *failureReason, + ) } if err != nil { return nil, err diff --git a/routing/router_test.go b/routing/router_test.go index a3f832b82..a63149c6c 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -3896,7 +3896,7 @@ func TestSendMPPaymentFailed(t *testing.T) { }) // Simple mocking the rest. - controlTower.On("Fail", identifier, failureReason).Return(nil) + controlTower.On("FailPayment", identifier, failureReason).Return(nil) payer.On("SendHTLC", mock.Anything, mock.Anything, mock.Anything, ).Return(nil) @@ -4091,7 +4091,7 @@ func TestSendMPPaymentFailedWithShardsInFlight(t *testing.T) { // Simple mocking the rest. cntFail := 0 - controlTower.On("Fail", identifier, failureReason).Return(nil) + controlTower.On("FailPayment", identifier, failureReason).Return(nil) payer.On("SendHTLC", mock.Anything, mock.Anything, mock.Anything, ).Return(nil).Run(func(args mock.Arguments) { @@ -4412,7 +4412,7 @@ func TestSendToRouteSkipTempErrPermanentFailure(t *testing.T) { ).Return(testAttempt, nil) // Expect the payment to be failed. - controlTower.On("Fail", payHash, mock.Anything).Return(nil) + controlTower.On("FailPayment", payHash, mock.Anything).Return(nil) payer.On("SendHTLC", mock.Anything, mock.Anything, mock.Anything, @@ -4501,7 +4501,7 @@ func TestSendToRouteTempFailure(t *testing.T) { ).Return(testAttempt, nil) // Expect the payment to be failed. - controlTower.On("Fail", payHash, mock.Anything).Return(nil) + controlTower.On("FailPayment", payHash, mock.Anything).Return(nil) payer.On("SendHTLC", mock.Anything, mock.Anything, mock.Anything,