multi: move FailureReason to payment package

This commit is contained in:
ziggie committed 2025-08-14 19:53:18 +02:00
1 parent d77b2f9c26
commit d138e23919
19 files changed
+134 -140

No files matched your search

-57
View File
@@ -8,63 +8,6 @@ import (
"github.com/lightningnetwork/lnd/lnwire"
)
// FailureReason encodes the reason a payment ultimately failed.
type FailureReason byte
const (
// FailureReasonTimeout indicates that the payment did timeout before a
// successful payment attempt was made.
FailureReasonTimeout FailureReason = 0
// FailureReasonNoRoute indicates no successful route to the
// destination was found during path finding.
FailureReasonNoRoute FailureReason = 1
// FailureReasonError indicates that an unexpected error happened during
// payment.
FailureReasonError FailureReason = 2
// FailureReasonPaymentDetails indicates that either the hash is unknown
// or the final cltv delta or amount is incorrect.
FailureReasonPaymentDetails FailureReason = 3
// FailureReasonInsufficientBalance indicates that we didn't have enough
// balance to complete the payment.
FailureReasonInsufficientBalance FailureReason = 4
// FailureReasonCanceled indicates that the payment was canceled by the
// user.
FailureReasonCanceled FailureReason = 5
// TODO(joostjager): Add failure reasons for:
// LocalLiquidityInsufficient, RemoteCapacityInsufficient.
)
// Error returns a human-readable error string for the FailureReason.
func (r FailureReason) Error() string {
return r.String()
}
// String returns a human-readable FailureReason.
func (r FailureReason) String() string {
switch r {
case FailureReasonTimeout:
return "timeout"
case FailureReasonNoRoute:
return "no_route"
case FailureReasonError:
return "error"
case FailureReasonPaymentDetails:
return "incorrect_payment_details"
case FailureReasonInsufficientBalance:
return "insufficient_balance"
case FailureReasonCanceled:
return "canceled"
}
return "unknown"
}
// PaymentCreationInfo is the information necessary to have ready when
// initiating a payment, moving it into state InFlight.
type PaymentCreationInfo struct {
+7 -8
View File
@@ -14,7 +14,6 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/wire"
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/feature"
"github.com/lightningnetwork/lnd/fn/v2"
@@ -1843,7 +1842,7 @@ func convertPaymentStatus(dbStatus paymentsdb.PaymentStatus, useInit bool) (
// marshallPaymentFailureReason marshalls the failure reason to the corresponding rpc
// type.
func marshallPaymentFailureReason(reason *channeldb.FailureReason) (
func marshallPaymentFailureReason(reason *paymentsdb.FailureReason) (
lnrpc.PaymentFailureReason, error) {
if reason == nil {
@@ -1851,22 +1850,22 @@ func marshallPaymentFailureReason(reason *channeldb.FailureReason) (
}
switch *reason {
case channeldb.FailureReasonTimeout:
case paymentsdb.FailureReasonTimeout:
return lnrpc.PaymentFailureReason_FAILURE_REASON_TIMEOUT, nil
case channeldb.FailureReasonNoRoute:
case paymentsdb.FailureReasonNoRoute:
return lnrpc.PaymentFailureReason_FAILURE_REASON_NO_ROUTE, nil
case channeldb.FailureReasonError:
case paymentsdb.FailureReasonError:
return lnrpc.PaymentFailureReason_FAILURE_REASON_ERROR, nil
case channeldb.FailureReasonPaymentDetails:
case paymentsdb.FailureReasonPaymentDetails:
return lnrpc.PaymentFailureReason_FAILURE_REASON_INCORRECT_PAYMENT_DETAILS, nil
case channeldb.FailureReasonInsufficientBalance:
case paymentsdb.FailureReasonInsufficientBalance:
return lnrpc.PaymentFailureReason_FAILURE_REASON_INSUFFICIENT_BALANCE, nil
case channeldb.FailureReasonCanceled:
case paymentsdb.FailureReasonCanceled:
return lnrpc.PaymentFailureReason_FAILURE_REASON_CANCELED, nil
}
+2 -2
View File
@@ -157,10 +157,10 @@ func fetchDuplicatePayment(bucket kvdb.RBucket) (*MPPayment, error) {
}
// Get failure reason if available.
var failureReason *channeldb.FailureReason
var failureReason *FailureReason
b = bucket.Get(duplicatePaymentFailInfoKey)
if b != nil {
reason := channeldb.FailureReason(b[0])
reason := FailureReason(b[0])
failureReason = &reason
}
+3 -3
View File
@@ -605,7 +605,7 @@ func (p *KVPaymentsDB) updateHtlcKey(paymentHash lntypes.Hash,
// its next call for this payment hash, allowing the switch to make a
// subsequent payment.
func (p *KVPaymentsDB) Fail(paymentHash lntypes.Hash,
reason channeldb.FailureReason) (*MPPayment, error) {
reason FailureReason) (*MPPayment, error) {
var (
updateErr error
@@ -979,10 +979,10 @@ func fetchPayment(bucket kvdb.RBucket) (*MPPayment, error) {
}
// Get failure reason if available.
var failureReason *channeldb.FailureReason
var failureReason *FailureReason
b := bucket.Get(paymentFailInfoKey)
if b != nil {
reason := channeldb.FailureReason(b[0])
reason := FailureReason(b[0])
failureReason = &reason
}
+8 -8
View File
@@ -82,7 +82,7 @@ func TestKVPaymentsDBSwitchFail(t *testing.T) {
)
// Fail the payment, which should moved it to Failed.
failReason := channeldb.FailureReasonNoRoute
failReason := FailureReasonNoRoute
_, err = paymentDB.Fail(info.PaymentIdentifier, failReason)
require.NoError(t, err, "unable to fail payment hash")
@@ -301,7 +301,7 @@ func TestKVPaymentsDBFailsWithoutInFlight(t *testing.T) {
// Calling Fail should return an error.
_, err = paymentDB.Fail(
info.PaymentIdentifier, channeldb.FailureReasonNoRoute,
info.PaymentIdentifier, FailureReasonNoRoute,
)
require.ErrorIs(t, err, ErrPaymentNotInitiated)
}
@@ -383,7 +383,7 @@ func TestKVPaymentsDBDeleteNonInFlight(t *testing.T) {
}
// Fail the payment, which should moved it to Failed.
failReason := channeldb.FailureReasonNoRoute
failReason := FailureReasonNoRoute
_, err = paymentDB.Fail(
info.PaymentIdentifier, failReason,
)
@@ -787,7 +787,7 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
HTLCAttemptInfo: a,
}
var firstFailReason *channeldb.FailureReason
var firstFailReason *FailureReason
if test.settleFirst {
_, err := paymentDB.SettleAttempt(
info.PaymentIdentifier, a.AttemptID,
@@ -827,7 +827,7 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
// We also record a payment level fail, to move it into
// a terminal state.
failReason := channeldb.FailureReasonNoRoute
failReason := FailureReasonNoRoute
_, err = paymentDB.Fail(
info.PaymentIdentifier, failReason,
)
@@ -910,7 +910,7 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
// failure. This is to allow multiple concurrent shard
// write a terminal failure to the database without
// syncing.
failReason := channeldb.FailureReasonPaymentDetails
failReason := FailureReasonPaymentDetails
_, err = paymentDB.Fail(
info.PaymentIdentifier, failReason,
)
@@ -1156,7 +1156,7 @@ type htlcStatus struct {
// assertPaymentInfo retrieves the payment referred to by hash and verifies the
// expected values.
func assertPaymentInfo(t *testing.T, p *KVPaymentsDB, hash lntypes.Hash,
c *channeldb.PaymentCreationInfo, f *channeldb.FailureReason,
c *channeldb.PaymentCreationInfo, f *FailureReason,
a *htlcStatus) {
t.Helper()
@@ -1339,7 +1339,7 @@ func createTestPayments(t *testing.T, p *KVPaymentsDB, payments []*payment) {
)
require.NoError(t, err, "unable to fail htlc")
failReason := channeldb.FailureReasonNoRoute
failReason := FailureReasonNoRoute
_, err = p.Fail(info.PaymentIdentifier,
failReason)
require.NoError(t, err, "unable to fail payment hash")
+59 -2
View File
@@ -19,6 +19,63 @@ import (
"github.com/lightningnetwork/lnd/routing/route"
)
// FailureReason encodes the reason a payment ultimately failed.
type FailureReason byte
const (
// FailureReasonTimeout indicates that the payment did timeout before a
// successful payment attempt was made.
FailureReasonTimeout FailureReason = 0
// FailureReasonNoRoute indicates no successful route to the
// destination was found during path finding.
FailureReasonNoRoute FailureReason = 1
// FailureReasonError indicates that an unexpected error happened during
// payment.
FailureReasonError FailureReason = 2
// FailureReasonPaymentDetails indicates that either the hash is unknown
// or the final cltv delta or amount is incorrect.
FailureReasonPaymentDetails FailureReason = 3
// FailureReasonInsufficientBalance indicates that we didn't have enough
// balance to complete the payment.
FailureReasonInsufficientBalance FailureReason = 4
// FailureReasonCanceled indicates that the payment was canceled by the
// user.
FailureReasonCanceled FailureReason = 5
// TODO(joostjager): Add failure reasons for:
// LocalLiquidityInsufficient, RemoteCapacityInsufficient.
)
// Error returns a human-readable error string for the FailureReason.
func (r FailureReason) Error() string {
return r.String()
}
// String returns a human-readable FailureReason.
func (r FailureReason) String() string {
switch r {
case FailureReasonTimeout:
return "timeout"
case FailureReasonNoRoute:
return "no_route"
case FailureReasonError:
return "error"
case FailureReasonPaymentDetails:
return "incorrect_payment_details"
case FailureReasonInsufficientBalance:
return "insufficient_balance"
case FailureReasonCanceled:
return "canceled"
}
return "unknown"
}
// HTLCAttemptInfo contains static information about a specific HTLC attempt
// for a payment. This information is used by the router to handle any errors
// coming back after an attempt is made, and to query the switch about the
@@ -252,7 +309,7 @@ type MPPayment struct {
//
// NOTE: Will only be set once the daemon has given up on the payment
// altogether.
FailureReason *channeldb.FailureReason
FailureReason *FailureReason
// Status is the current PaymentStatus of this payment.
Status PaymentStatus
@@ -273,7 +330,7 @@ func (m *MPPayment) Terminated() bool {
// TerminalInfo returns any HTLC settle info recorded. If no settle info is
// recorded, any payment level failure will be returned. If neither a settle
// nor a failure is recorded, both return values will be nil.
func (m *MPPayment) TerminalInfo() (*HTLCAttempt, *channeldb.FailureReason) {
func (m *MPPayment) TerminalInfo() (*HTLCAttempt, *FailureReason) {
for _, h := range m.HTLCs {
if h.Settle != nil {
return &h, nil
+1 -3
View File
@@ -2,8 +2,6 @@ package paymentsdb
import (
"fmt"
"github.com/lightningnetwork/lnd/channeldb"
)
// PaymentStatus represent current status of payment.
@@ -173,7 +171,7 @@ func (ps PaymentStatus) updatable() error {
// failed` is false, this indicates all the payment's HTLCs have occurred a
// temporarily failure and the payment is still in-flight.
func decidePaymentStatus(htlcs []HTLCAttempt,
reason *channeldb.FailureReason) (PaymentStatus, error) {
reason *FailureReason) (PaymentStatus, error) {
var (
inflight bool
+2 -3
View File
@@ -4,7 +4,6 @@ import (
"fmt"
"testing"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/stretchr/testify/require"
)
@@ -24,13 +23,13 @@ func TestDecidePaymentStatus(t *testing.T) {
}
// Create a test failure reason and get the pointer.
reason := channeldb.FailureReasonNoRoute
reason := FailureReasonNoRoute
failure := &reason
testCases := []struct {
name string
htlcs []HTLCAttempt
reason *channeldb.FailureReason
reason *FailureReason
expectedStatus PaymentStatus
expectedErr error
}{
+1 -1
View File
@@ -598,7 +598,7 @@ func TestPaymentSetState(t *testing.T) {
// Create a test preimage and failure reason.
preimage := lntypes.Preimage{1}
failureReasonError := channeldb.FailureReasonError
failureReasonError := FailureReasonError
testCases := []struct {
name string
+3 -3
View File
@@ -39,7 +39,7 @@ type DBMPPayment interface {
// TerminalInfo returns the settled HTLC attempt or the payment's
// failure reason.
TerminalInfo() (*paymentsdb.HTLCAttempt, *channeldb.FailureReason)
TerminalInfo() (*paymentsdb.HTLCAttempt, *paymentsdb.FailureReason)
}
// ControlTower tracks all outgoing payments made, whose primary purpose is to
@@ -85,7 +85,7 @@ type ControlTower interface {
// invoking this method, InitPayment should return nil on its next call
// for this payment hash, allowing the user to make a subsequent
// payment.
FailPayment(lntypes.Hash, channeldb.FailureReason) error
FailPayment(lntypes.Hash, paymentsdb.FailureReason) error
// FetchInFlightPayments returns all payments with status InFlight.
FetchInFlightPayments() ([]*paymentsdb.MPPayment, error)
@@ -287,7 +287,7 @@ func (p *controlTower) FetchPayment(paymentHash lntypes.Hash) (
// NOTE: This method will overwrite the failure reason if the payment is already
// failed.
func (p *controlTower) FailPayment(paymentHash lntypes.Hash,
reason channeldb.FailureReason) error {
reason paymentsdb.FailureReason) error {
p.paymentsMtx.Lock(paymentHash)
defer p.paymentsMtx.Unlock(paymentHash)
+2 -2
View File
@@ -481,7 +481,7 @@ func testKVPaymentsDBSubscribeFail(t *testing.T, registerAttempt,
// Mark the payment as failed.
err = pControl.FailPayment(
info.PaymentIdentifier, channeldb.FailureReasonTimeout,
info.PaymentIdentifier, paymentsdb.FailureReasonTimeout,
)
if err != nil {
t.Fatal(err)
@@ -537,7 +537,7 @@ func testKVPaymentsDBSubscribeFail(t *testing.T, registerAttempt,
"subscriber %v failed, want %s, got %s", i,
paymentsdb.StatusFailed, result.GetStatus())
if *result.FailureReason != channeldb.FailureReasonTimeout {
if *result.FailureReason != paymentsdb.FailureReasonTimeout {
t.Fatal("unexpected failure reason")
}
+4 -4
View File
@@ -11,11 +11,11 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btclog/v2"
"github.com/btcsuite/btcwallet/walletdb"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
paymentsdb "github.com/lightningnetwork/lnd/payments/db"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/tlv"
)
@@ -617,7 +617,7 @@ func (m *MissionControl) GetPairHistorySnapshot(
// payment attempts need to be made.
func (m *MissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route,
failureSourceIdx *int, failure lnwire.FailureMessage) (
*channeldb.FailureReason, error) {
*paymentsdb.FailureReason, error) {
timestamp := m.cfg.clock.Now()
@@ -649,7 +649,7 @@ func (m *MissionControl) ReportPaymentSuccess(paymentID uint64,
// processPaymentResult stores a payment result in the mission control store and
// updates mission control's in-memory state.
func (m *MissionControl) processPaymentResult(result *paymentResult) (
*channeldb.FailureReason, error) {
*paymentsdb.FailureReason, error) {
// Store complete result in database.
m.store.AddResult(result)
@@ -667,7 +667,7 @@ func (m *MissionControl) processPaymentResult(result *paymentResult) (
// estimates. It returns a bool indicating whether this error is a final error
// and no further payment attempts need to be made.
func (m *MissionControl) applyPaymentResult(
result *paymentResult) *channeldb.FailureReason {
result *paymentResult) *paymentsdb.FailureReason {
// Interpret result.
i := interpretResult(&result.route.Val, result.failure.ValOpt())
+12 -12
View File
@@ -134,12 +134,12 @@ var _ MissionControlQuerier = (*mockMissionControlOld)(nil)
func (m *mockMissionControlOld) ReportPaymentFail(
paymentID uint64, rt *route.Route,
failureSourceIdx *int, failure lnwire.FailureMessage) (
*channeldb.FailureReason, error) {
*paymentsdb.FailureReason, error) {
// Report a permanent failure if this is an error caused
// by incorrect details.
if failure.Code() == lnwire.CodeIncorrectOrUnknownPaymentDetails {
reason := channeldb.FailureReasonPaymentDetails
reason := paymentsdb.FailureReasonPaymentDetails
return &reason, nil
}
@@ -264,7 +264,7 @@ type failAttemptArgs struct {
}
type failPaymentArgs struct {
reason channeldb.FailureReason
reason paymentsdb.FailureReason
}
type testPayment struct {
@@ -275,7 +275,7 @@ type testPayment struct {
type mockControlTowerOld struct {
payments map[lntypes.Hash]*testPayment
successful map[lntypes.Hash]struct{}
failed map[lntypes.Hash]channeldb.FailureReason
failed map[lntypes.Hash]paymentsdb.FailureReason
init chan initArgs
registerAttempt chan registerAttemptArgs
@@ -293,7 +293,7 @@ func makeMockControlTower() *mockControlTowerOld {
return &mockControlTowerOld{
payments: make(map[lntypes.Hash]*testPayment),
successful: make(map[lntypes.Hash]struct{}),
failed: make(map[lntypes.Hash]channeldb.FailureReason),
failed: make(map[lntypes.Hash]paymentsdb.FailureReason),
}
}
@@ -489,7 +489,7 @@ func (m *mockControlTowerOld) FailAttempt(phash lntypes.Hash, pid uint64,
}
func (m *mockControlTowerOld) FailPayment(phash lntypes.Hash,
reason channeldb.FailureReason) error {
reason paymentsdb.FailureReason) error {
m.Lock()
defer m.Unlock()
@@ -664,7 +664,7 @@ var _ MissionControlQuerier = (*mockMissionControl)(nil)
func (m *mockMissionControl) ReportPaymentFail(
paymentID uint64, rt *route.Route,
failureSourceIdx *int, failure lnwire.FailureMessage) (
*channeldb.FailureReason, error) {
*paymentsdb.FailureReason, error) {
args := m.Called(paymentID, rt, failureSourceIdx, failure)
@@ -673,7 +673,7 @@ func (m *mockMissionControl) ReportPaymentFail(
return nil, args.Error(1)
}
return args.Get(0).(*channeldb.FailureReason), args.Error(1)
return args.Get(0).(*paymentsdb.FailureReason), args.Error(1)
}
func (m *mockMissionControl) ReportPaymentSuccess(paymentID uint64,
@@ -779,7 +779,7 @@ func (m *mockControlTower) FailAttempt(phash lntypes.Hash, pid uint64,
}
func (m *mockControlTower) FailPayment(phash lntypes.Hash,
reason channeldb.FailureReason) error {
reason paymentsdb.FailureReason) error {
args := m.Called(phash, reason)
return args.Error(0)
@@ -863,13 +863,13 @@ func (m *mockMPPayment) AllowMoreAttempts() (bool, error) {
}
func (m *mockMPPayment) TerminalInfo() (*paymentsdb.HTLCAttempt,
*channeldb.FailureReason) {
*paymentsdb.FailureReason) {
args := m.Called()
var (
settleInfo *paymentsdb.HTLCAttempt
failureInfo *channeldb.FailureReason
failureInfo *paymentsdb.FailureReason
)
settle := args.Get(0)
@@ -879,7 +879,7 @@ func (m *mockMPPayment) TerminalInfo() (*paymentsdb.HTLCAttempt,
reason := args.Get(1)
if reason != nil {
failureInfo = reason.(*channeldb.FailureReason)
failureInfo = reason.(*paymentsdb.FailureReason)
}
return settleInfo, failureInfo
+5 -6
View File
@@ -9,7 +9,6 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/davecgh/go-spew/spew"
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/htlcswitch"
@@ -353,13 +352,13 @@ func (p *paymentLifecycle) checkContext(ctx context.Context) error {
// user-provided timeout was reached, or the context was
// canceled, either to a manual cancellation or due to an
// unknown error.
var reason channeldb.FailureReason
var reason paymentsdb.FailureReason
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
reason = channeldb.FailureReasonTimeout
reason = paymentsdb.FailureReasonTimeout
log.Warnf("Payment attempt not completed before "+
"context timeout, id=%s", p.identifier.String())
} else {
reason = channeldb.FailureReasonCanceled
reason = paymentsdb.FailureReasonCanceled
log.Warnf("Payment attempt context canceled, id=%s",
p.identifier.String())
}
@@ -795,7 +794,7 @@ func (p *paymentLifecycle) amendFirstHopData(rt *route.Route) error {
// failAttemptAndPayment fails both the payment and its attempt via the
// router's control tower, which marks the payment as failed in db.
func (p *paymentLifecycle) failPaymentAndAttempt(
attemptID uint64, reason *channeldb.FailureReason,
attemptID uint64, reason *paymentsdb.FailureReason,
sendErr error) (*attemptResult, error) {
log.Errorf("Payment %v failed: final_outcome=%v, raw_err=%v",
@@ -827,7 +826,7 @@ func (p *paymentLifecycle) failPaymentAndAttempt(
func (p *paymentLifecycle) handleSwitchErr(attempt *paymentsdb.HTLCAttempt,
sendErr error) (*attemptResult, error) {
internalErrorReason := channeldb.FailureReasonError
internalErrorReason := paymentsdb.FailureReasonError
attemptID := attempt.AttemptID
// reportAndFail is a helper closure that reports the failure to the
+10 -11
View File
@@ -8,7 +8,6 @@ import (
"time"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/lnmock"
@@ -303,7 +302,7 @@ func TestCheckTimeoutTimedOut(t *testing.T) {
// Mock the control tower's `FailPayment` method.
ct := &mockControlTower{}
ct.On("FailPayment",
p.identifier, channeldb.FailureReasonTimeout).Return(nil)
p.identifier, paymentsdb.FailureReasonTimeout).Return(nil)
// Mount the mocked control tower.
p.router.cfg.Control = ct
@@ -324,7 +323,7 @@ func TestCheckTimeoutTimedOut(t *testing.T) {
// Mock `FailPayment` to return a dummy error.
ct = &mockControlTower{}
ct.On("FailPayment",
p.identifier, channeldb.FailureReasonTimeout).Return(errDummy)
p.identifier, paymentsdb.FailureReasonTimeout).Return(errDummy)
// Mount the mocked control tower.
p.router.cfg.Control = ct
@@ -468,7 +467,7 @@ func TestRequestRouteHandleNoRouteErr(t *testing.T) {
// The payment should be failed with reason no route.
m.control.On("FailPayment",
p.identifier, channeldb.FailureReasonNoRoute,
p.identifier, paymentsdb.FailureReasonNoRoute,
).Return(nil).Once()
result, err := p.requestRoute(ps)
@@ -838,7 +837,7 @@ func TestResumePaymentFailOnTimeout(t *testing.T) {
// 4. the payment should be failed with reason timeout.
m.control.On("FailPayment",
p.identifier, channeldb.FailureReasonTimeout,
p.identifier, paymentsdb.FailureReasonTimeout,
).Return(nil).Once()
// 5. decideNextStep now returns stepExit.
@@ -849,7 +848,7 @@ func TestResumePaymentFailOnTimeout(t *testing.T) {
m.control.On("DeleteFailedAttempts", p.identifier).Return(nil).Once()
// 7. the payment returns the failed reason.
reason := channeldb.FailureReasonTimeout
reason := paymentsdb.FailureReasonTimeout
m.payment.On("TerminalInfo").Return(nil, &reason)
// Send the payment and assert it failed with the timeout reason.
@@ -925,7 +924,7 @@ func TestResumePaymentFailContextCancel(t *testing.T) {
cancel()
m.control.On(
"FailPayment", p.identifier, channeldb.FailureReasonCanceled,
"FailPayment", p.identifier, paymentsdb.FailureReasonCanceled,
).Return(nil).Once()
// 4. decideNextStep now returns stepExit.
@@ -936,7 +935,7 @@ func TestResumePaymentFailContextCancel(t *testing.T) {
m.control.On("DeleteFailedAttempts", p.identifier).Return(nil).Once()
// 6. We will observe FailureReasonError if the context was cancelled.
reason := channeldb.FailureReasonError
reason := paymentsdb.FailureReasonError
m.payment.On("TerminalInfo").Return(nil, &reason)
// Send the payment and assert it failed with the timeout reason.
@@ -1162,7 +1161,7 @@ func TestResumePaymentFailOnSendAttemptErr(t *testing.T) {
// which we'd fail the payment, cancel the shard and fail the attempt.
//
// `FailPayment` should be called with an internal reason.
reason := channeldb.FailureReasonError
reason := paymentsdb.FailureReasonError
m.control.On("FailPayment", p.identifier, reason).Return(nil).Once()
// `CancelShard` should be called with the attemptID.
@@ -1453,7 +1452,7 @@ func TestCollectResultExitOnErr(t *testing.T) {
// which we'd fail the payment, cancel the shard and fail the attempt.
//
// `FailPayment` should be called with an internal reason.
reason := channeldb.FailureReasonError
reason := paymentsdb.FailureReasonError
m.control.On("FailPayment", p.identifier, reason).Return(nil).Once()
// `CancelShard` should be called with the attemptID.
@@ -1499,7 +1498,7 @@ func TestCollectResultExitOnResultErr(t *testing.T) {
// which we'd fail the payment, cancel the shard and fail the attempt.
//
// `FailPayment` should be called with an internal reason.
reason := channeldb.FailureReasonError
reason := paymentsdb.FailureReasonError
m.control.On("FailPayment", p.identifier, reason).Return(nil).Once()
// `CancelShard` should be called with the attemptID.
+5 -5
View File
@@ -5,12 +5,12 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btclog/v2"
"github.com/lightningnetwork/lnd/channeldb"
graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/lnutils"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/netann"
paymentsdb "github.com/lightningnetwork/lnd/payments/db"
"github.com/lightningnetwork/lnd/routing/route"
)
@@ -104,7 +104,7 @@ func (e noRouteError) Error() string {
}
// FailureReason converts a path finding error into a payment-level failure.
func (e noRouteError) FailureReason() channeldb.FailureReason {
func (e noRouteError) FailureReason() paymentsdb.FailureReason {
switch e {
case
errNoTlvPayload,
@@ -114,13 +114,13 @@ func (e noRouteError) FailureReason() channeldb.FailureReason {
errUnknownRequiredFeature,
errMissingDependentFeature:
return channeldb.FailureReasonNoRoute
return paymentsdb.FailureReasonNoRoute
case errInsufficientBalance:
return channeldb.FailureReasonInsufficientBalance
return paymentsdb.FailureReasonInsufficientBalance
default:
return channeldb.FailureReasonError
return paymentsdb.FailureReasonError
}
}
+4 -4
View File
@@ -5,17 +5,17 @@ import (
"fmt"
"io"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/lnwire"
paymentsdb "github.com/lightningnetwork/lnd/payments/db"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/tlv"
)
// Instantiate variables to allow taking a reference from the failure reason.
var (
reasonError = channeldb.FailureReasonError
reasonIncorrectDetails = channeldb.FailureReasonPaymentDetails
reasonError = paymentsdb.FailureReasonError
reasonIncorrectDetails = paymentsdb.FailureReasonPaymentDetails
)
// pairResult contains the result of the interpretation of a payment attempt for
@@ -70,7 +70,7 @@ type interpretedResult struct {
// finalFailureReason is set to a non-nil value if it makes no more
// sense to start another payment attempt. It will contain the reason
// why.
finalFailureReason *channeldb.FailureReason
finalFailureReason *paymentsdb.FailureReason
// policyFailure is set to a node pair if there is a policy failure on
// that connection. This is used to control the second chance logic for
+3 -3
View File
@@ -175,7 +175,7 @@ type MissionControlQuerier interface {
// need to be made.
ReportPaymentFail(attemptID uint64, rt *route.Route,
failureSourceIdx *int, failure lnwire.FailureMessage) (
*channeldb.FailureReason, error)
*paymentsdb.FailureReason, error)
// ReportPaymentSuccess reports a successful payment to mission control
// as input for future probability estimates.
@@ -1068,7 +1068,7 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
// Helper function to fail a payment. It makes sure the payment is only
// failed once so that the failure reason is not overwritten.
failPayment := func(paymentIdentifier lntypes.Hash,
reason channeldb.FailureReason) error {
reason paymentsdb.FailureReason) error {
payment, fetchErr := r.cfg.Control.FetchPayment(
paymentIdentifier,
@@ -1191,7 +1191,7 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
// Since for SendToRoute we won't retry in case the shard fails, we'll
// mark the payment failed with the control tower immediately if the
// skipTempErr is false.
reason := channeldb.FailureReasonError
reason := paymentsdb.FailureReasonError
// If we failed to send the HTLC, we need to further decide if we want
// to fail the payment.
+3 -3
View File
@@ -21,7 +21,6 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/davecgh/go-spew/spew"
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/graph"
@@ -32,6 +31,7 @@ import (
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
paymentsdb "github.com/lightningnetwork/lnd/payments/db"
"github.com/lightningnetwork/lnd/record"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/zpay32"
@@ -1091,7 +1091,7 @@ func TestSendPaymentErrorPathPruning(t *testing.T) {
// The final error returned should also indicate that the peer wasn't
// online (the last error we returned).
require.Equal(t, channeldb.FailureReasonNoRoute, err)
require.Equal(t, paymentsdb.FailureReasonNoRoute, err)
// Inspect the two attempts that were made before the payment failed.
p, err := ctx.router.cfg.Control.FetchPayment(*payment.paymentHash)
@@ -2429,7 +2429,7 @@ func TestSendToRouteSkipTempErrPermanentFailure(t *testing.T) {
mock.Anything, mock.Anything, mock.Anything,
).Return(permErr)
failureReason := channeldb.FailureReasonPaymentDetails
failureReason := paymentsdb.FailureReasonPaymentDetails
missionControl.On("ReportPaymentFail",
mock.Anything, rt, mock.Anything, mock.Anything,
).Return(&failureReason, nil)