multi: move FailureReason to payment package
What changed, and why it matters
This commit is a straightforward internal code cleanup: it moves the FailureReason type and its constants from the channeldb package to the payments/db package, then updates all references across the codebase. There is no functional change to how payments fail or how failure reasons are reported to users. It is not a security fix and does not introduce any obvious security issue.
No security action required. Treat as a normal refactoring commit during review; verify that imports and type references compile and tests pass.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change relocates the FailureReason byte type, its enumerated constants, String(), and Error() methods from channeldb/payments.go to payments/db/payment.go. All call sites in routerrpc, payments/db, routing, and tests are updated to use paymentsdb.FailureReason instead of channeldb.FailureReason. The numeric values and semantics of the constants are preserved. No logic changes are made to payment failure handling, serialization, or RPC mapping.
Changed components
channeldb/payments.gopayments/db/payment.golnrpc/routerrpc/router_backend.gopayments/db/kv_duplicate_payments.gopayments/db/kv_store.gopayments/db/payment_status.gorouting/control_tower.gorouting/missioncontrol.gorouting/payment_lifecycle.gorouting/payment_session.gorouting/result_interpretation.gorouting/router.goInspect captured patch +134 / −140
diff --git a/channeldb/payments.go b/channeldb/payments.go
index 3430e62..2543c9d 100644
--- a/channeldb/payments.go
+++ b/channeldb/payments.go
@@ -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 {
diff --git a/lnrpc/routerrpc/router_backend.go b/lnrpc/routerrpc/router_backend.go
index b31d988..022f461 100644
--- a/lnrpc/routerrpc/router_backend.go
+++ b/lnrpc/routerrpc/router_backend.go
@@ -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
}
diff --git a/payments/db/kv_duplicate_payments.go b/payments/db/kv_duplicate_payments.go
index 9a41c92..ed539ce 100644
--- a/payments/db/kv_duplicate_payments.go
+++ b/payments/db/kv_duplicate_payments.go
@@ -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
}
diff --git a/payments/db/kv_store.go b/payments/db/kv_store.go
index 02cce77..18365f1 100644
--- a/payments/db/kv_store.go
+++ b/payments/db/kv_store.go
@@ -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
}
diff --git a/payments/db/kv_store_test.go b/payments/db/kv_store_test.go
index 2b5aaac..3bf4f35 100644
--- a/payments/db/kv_store_test.go
+++ b/payments/db/kv_store_test.go
@@ -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")
diff --git a/payments/db/payment.go b/payments/db/payment.go
index 38948b1..334b66e 100644
--- a/payments/db/payment.go
+++ b/payments/db/payment.go
@@ -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
diff --git a/payments/db/payment_status.go b/payments/db/payment_status.go
index b42bb0e..3fd01ca 100644
--- a/payments/db/payment_status.go
+++ b/payments/db/payment_status.go
@@ -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
diff --git a/payments/db/payment_status_test.go b/payments/db/payment_status_test.go
index 0fcd121..1bb4dc3 100644
--- a/payments/db/payment_status_test.go
+++ b/payments/db/payment_status_test.go
@@ -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
}{
diff --git a/payments/db/payment_test.go b/payments/db/payment_test.go
index 91cbdca..a0878e5 100644
--- a/payments/db/payment_test.go
+++ b/payments/db/payment_test.go
@@ -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
diff --git a/routing/control_tower.go b/routing/control_tower.go
index 1a384cd..70e7d9b 100644
--- a/routing/control_tower.go
+++ b/routing/control_tower.go
@@ -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)
diff --git a/routing/control_tower_test.go b/routing/control_tower_test.go
index c9ddf8c..9250b21 100644
--- a/routing/control_tower_test.go
+++ b/routing/control_tower_test.go
@@ -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")
}
diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go
index 89e14f5..b03724a 100644
--- a/routing/missioncontrol.go
+++ b/routing/missioncontrol.go
@@ -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())
diff --git a/routing/mock_test.go b/routing/mock_test.go
index bb800a4..e993ea8 100644
--- a/routing/mock_test.go
+++ b/routing/mock_test.go
@@ -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
diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go
index e0a6201..245e3b3 100644
--- a/routing/payment_lifecycle.go
+++ b/routing/payment_lifecycle.go
@@ -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
diff --git a/routing/payment_lifecycle_test.go b/routing/payment_lifecycle_test.go
index 6effccd..8094f50 100644
--- a/routing/payment_lifecycle_test.go
+++ b/routing/payment_lifecycle_test.go
@@ -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.
diff --git a/routing/payment_session.go b/routing/payment_session.go
index cf20251..bb79521 100644
--- a/routing/payment_session.go
+++ b/routing/payment_session.go
@@ -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
}
}
diff --git a/routing/result_interpretation.go b/routing/result_interpretation.go
index 55c4246..713be73 100644
--- a/routing/result_interpretation.go
+++ b/routing/result_interpretation.go
@@ -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
diff --git a/routing/router.go b/routing/router.go
index 8bb64c9..45d80f6 100644
--- a/routing/router.go
+++ b/routing/router.go
@@ -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.
diff --git a/routing/router_test.go b/routing/router_test.go
index d149c42..702c29d 100644
--- a/routing/router_test.go
+++ b/routing/router_test.go
@@ -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)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.