routing: rename Fail to FailPayment

This commit renames the method `Fail` to be `FailPayment` to explicitly
address its purpose.
This commit is contained in:
yyforyongyu 2022-06-10 00:50:54 +08:00
parent 2fd4c1e318
commit d1611c999a
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
6 changed files with 27 additions and 22 deletions

View File

@ -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)

View File

@ -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)
}

View File

@ -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()

View File

@ -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 "+

View File

@ -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

View File

@ -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,