mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +01:00
routing: rename Fail
to FailPayment
This commit renames the method `Fail` to be `FailPayment` to explicitly address its purpose.
This commit is contained in:
parent
2fd4c1e318
commit
d1611c999a
@ -46,13 +46,13 @@ type ControlTower interface {
|
|||||||
// hash.
|
// hash.
|
||||||
FetchPayment(paymentHash lntypes.Hash) (*channeldb.MPPayment, error)
|
FetchPayment(paymentHash lntypes.Hash) (*channeldb.MPPayment, error)
|
||||||
|
|
||||||
// Fail transitions a payment into the Failed state, and records the
|
// FailPayment transitions a payment into the Failed state, and records
|
||||||
// ultimate reason the payment failed. Note that this should only be
|
// the ultimate reason the payment failed. Note that this should only
|
||||||
// called when all active active attempts are already failed. After
|
// be called when all active attempts are already failed. After
|
||||||
// invoking this method, InitPayment should return nil on its next call
|
// invoking this method, InitPayment should return nil on its next call
|
||||||
// for this payment hash, allowing the user to make a subsequent
|
// for this payment hash, allowing the user to make a subsequent
|
||||||
// payment.
|
// payment.
|
||||||
Fail(lntypes.Hash, channeldb.FailureReason) error
|
FailPayment(lntypes.Hash, channeldb.FailureReason) error
|
||||||
|
|
||||||
// FetchInFlightPayments returns all payments with status InFlight.
|
// FetchInFlightPayments returns all payments with status InFlight.
|
||||||
FetchInFlightPayments() ([]*channeldb.MPPayment, error)
|
FetchInFlightPayments() ([]*channeldb.MPPayment, error)
|
||||||
@ -229,11 +229,11 @@ func (p *controlTower) FetchPayment(paymentHash lntypes.Hash) (
|
|||||||
return p.db.FetchPayment(paymentHash)
|
return p.db.FetchPayment(paymentHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fail transitions a payment into the Failed state, and records the reason the
|
// FailPayment transitions a payment into the Failed state, and records the
|
||||||
// payment failed. After invoking this method, InitPayment should return nil on
|
// reason the payment failed. After invoking this method, InitPayment should
|
||||||
// its next call for this payment hash, allowing the switch to make a
|
// return nil on its next call for this payment hash, allowing the switch to
|
||||||
// subsequent payment.
|
// make a subsequent payment.
|
||||||
func (p *controlTower) Fail(paymentHash lntypes.Hash,
|
func (p *controlTower) FailPayment(paymentHash lntypes.Hash,
|
||||||
reason channeldb.FailureReason) error {
|
reason channeldb.FailureReason) error {
|
||||||
|
|
||||||
p.paymentsMtx.Lock(paymentHash)
|
p.paymentsMtx.Lock(paymentHash)
|
||||||
|
@ -457,7 +457,10 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mark the payment as failed.
|
// 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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,7 +469,7 @@ func (m *mockControlTowerOld) FailAttempt(phash lntypes.Hash, pid uint64,
|
|||||||
return nil, fmt.Errorf("pid not found")
|
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 {
|
reason channeldb.FailureReason) error {
|
||||||
|
|
||||||
m.Lock()
|
m.Lock()
|
||||||
@ -733,7 +733,7 @@ func (m *mockControlTower) FailAttempt(phash lntypes.Hash, pid uint64,
|
|||||||
return args.Get(0).(*channeldb.HTLCAttempt), args.Error(1)
|
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 {
|
reason channeldb.FailureReason) error {
|
||||||
|
|
||||||
m.Lock()
|
m.Lock()
|
||||||
|
@ -233,7 +233,7 @@ lifecycle:
|
|||||||
// tower, no further shards will be launched and we'll
|
// tower, no further shards will be launched and we'll
|
||||||
// return with an error the moment all active shards
|
// return with an error the moment all active shards
|
||||||
// have finished.
|
// have finished.
|
||||||
saveErr := p.router.cfg.Control.Fail(
|
saveErr := p.router.cfg.Control.FailPayment(
|
||||||
p.identifier, channeldb.FailureReasonTimeout,
|
p.identifier, channeldb.FailureReasonTimeout,
|
||||||
)
|
)
|
||||||
if saveErr != nil {
|
if saveErr != nil {
|
||||||
@ -273,7 +273,7 @@ lifecycle:
|
|||||||
"failed with no route: %v",
|
"failed with no route: %v",
|
||||||
p.identifier, failureCode)
|
p.identifier, failureCode)
|
||||||
|
|
||||||
saveErr := p.router.cfg.Control.Fail(
|
saveErr := p.router.cfg.Control.FailPayment(
|
||||||
p.identifier, failureCode,
|
p.identifier, failureCode,
|
||||||
)
|
)
|
||||||
if saveErr != nil {
|
if saveErr != nil {
|
||||||
@ -784,7 +784,7 @@ func (p *shardHandler) handleSendError(attempt *channeldb.HTLCAttemptInfo,
|
|||||||
p.identifier, *reason, sendErr)
|
p.identifier, *reason, sendErr)
|
||||||
|
|
||||||
// Fail the payment via control tower.
|
// Fail the payment via control tower.
|
||||||
if err := p.router.cfg.Control.Fail(
|
if err := p.router.cfg.Control.FailPayment(
|
||||||
p.identifier, *reason,
|
p.identifier, *reason,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
log.Errorf("unable to report failure to control "+
|
log.Errorf("unable to report failure to control "+
|
||||||
|
@ -2253,7 +2253,7 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
|
|||||||
log.Debugf("Invalid route provided for payment %x: %v",
|
log.Debugf("Invalid route provided for payment %x: %v",
|
||||||
paymentIdentifier, err)
|
paymentIdentifier, err)
|
||||||
|
|
||||||
controlErr := r.cfg.Control.Fail(
|
controlErr := r.cfg.Control.FailPayment(
|
||||||
paymentIdentifier, channeldb.FailureReasonError,
|
paymentIdentifier, channeldb.FailureReasonError,
|
||||||
)
|
)
|
||||||
if controlErr != nil {
|
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
|
// If a non-terminal error is returned and `skipTempErr` is false, then
|
||||||
// we'll use the normal no route error.
|
// we'll use the normal no route error.
|
||||||
case err == nil && !skipTempErr:
|
case err == nil && !skipTempErr:
|
||||||
err = r.cfg.Control.Fail(
|
err = r.cfg.Control.FailPayment(
|
||||||
paymentIdentifier, channeldb.FailureReasonNoRoute,
|
paymentIdentifier, channeldb.FailureReasonNoRoute,
|
||||||
)
|
)
|
||||||
|
|
||||||
// If this is a failure reason, then we'll apply the failure directly
|
// 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.
|
// to the control tower, and return the normal response to the caller.
|
||||||
case goErrors.As(err, &failureReason):
|
case goErrors.As(err, &failureReason):
|
||||||
err = r.cfg.Control.Fail(paymentIdentifier, *failureReason)
|
err = r.cfg.Control.FailPayment(
|
||||||
|
paymentIdentifier, *failureReason,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -3896,7 +3896,7 @@ func TestSendMPPaymentFailed(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Simple mocking the rest.
|
// Simple mocking the rest.
|
||||||
controlTower.On("Fail", identifier, failureReason).Return(nil)
|
controlTower.On("FailPayment", identifier, failureReason).Return(nil)
|
||||||
payer.On("SendHTLC",
|
payer.On("SendHTLC",
|
||||||
mock.Anything, mock.Anything, mock.Anything,
|
mock.Anything, mock.Anything, mock.Anything,
|
||||||
).Return(nil)
|
).Return(nil)
|
||||||
@ -4091,7 +4091,7 @@ func TestSendMPPaymentFailedWithShardsInFlight(t *testing.T) {
|
|||||||
|
|
||||||
// Simple mocking the rest.
|
// Simple mocking the rest.
|
||||||
cntFail := 0
|
cntFail := 0
|
||||||
controlTower.On("Fail", identifier, failureReason).Return(nil)
|
controlTower.On("FailPayment", identifier, failureReason).Return(nil)
|
||||||
payer.On("SendHTLC",
|
payer.On("SendHTLC",
|
||||||
mock.Anything, mock.Anything, mock.Anything,
|
mock.Anything, mock.Anything, mock.Anything,
|
||||||
).Return(nil).Run(func(args mock.Arguments) {
|
).Return(nil).Run(func(args mock.Arguments) {
|
||||||
@ -4412,7 +4412,7 @@ func TestSendToRouteSkipTempErrPermanentFailure(t *testing.T) {
|
|||||||
).Return(testAttempt, nil)
|
).Return(testAttempt, nil)
|
||||||
|
|
||||||
// Expect the payment to be failed.
|
// 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",
|
payer.On("SendHTLC",
|
||||||
mock.Anything, mock.Anything, mock.Anything,
|
mock.Anything, mock.Anything, mock.Anything,
|
||||||
@ -4501,7 +4501,7 @@ func TestSendToRouteTempFailure(t *testing.T) {
|
|||||||
).Return(testAttempt, nil)
|
).Return(testAttempt, nil)
|
||||||
|
|
||||||
// Expect the payment to be failed.
|
// 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",
|
payer.On("SendHTLC",
|
||||||
mock.Anything, mock.Anything, mock.Anything,
|
mock.Anything, mock.Anything, mock.Anything,
|
||||||
|
Loading…
Reference in New Issue
Block a user