multi: move DBMPPayment to paymentsdb package
What changed, and why it matters
This commit is a straightforward code cleanup: it moves an existing interface definition (DBMPPayment) from the routing package to the payments/db package and updates all references. There is no functional change to how the software behaves, and no security issue is introduced or fixed.
No security action required. Treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change relocates the DBMPPayment interface from routing/control_tower.go to payments/db/interface.go. All type references in routing/control_tower.go, routing/payment_lifecycle.go, and routing/mock_test.go are updated from DBMPPayment to paymentsdb.DBMPPayment. The interface’s method signatures and semantics remain identical; only the package location changes.
Changed components
routing/control_tower.gorouting/payment_lifecycle.gorouting/mock_test.gopayments/db/interface.goInspect captured patch +42 / −40
diff --git a/payments/db/interface.go b/payments/db/interface.go
index 9b91de9..c41dc37 100644
--- a/payments/db/interface.go
+++ b/payments/db/interface.go
@@ -89,3 +89,35 @@ type PaymentControl interface {
// completed, and the payment has reached a final terminal state.
DeleteFailedAttempts(lntypes.Hash) error
}
+
+// DBMPPayment is an interface that represents the payment state during a
+// payment lifecycle.
+type DBMPPayment interface {
+ // GetState returns the current state of the payment.
+ GetState() *MPPaymentState
+
+ // Terminated returns true if the payment is in a final state.
+ Terminated() bool
+
+ // GetStatus returns the current status of the payment.
+ GetStatus() PaymentStatus
+
+ // NeedWaitAttempts specifies whether the payment needs to wait for the
+ // outcome of an attempt.
+ NeedWaitAttempts() (bool, error)
+
+ // GetHTLCs returns all HTLCs of this payment.
+ GetHTLCs() []HTLCAttempt
+
+ // InFlightHTLCs returns all HTLCs that are in flight.
+ InFlightHTLCs() []HTLCAttempt
+
+ // AllowMoreAttempts is used to decide whether we can safely attempt
+ // more HTLCs for a given payment state. Return an error if the payment
+ // is in an unexpected state.
+ AllowMoreAttempts() (bool, error)
+
+ // TerminalInfo returns the settled HTLC attempt or the payment's
+ // failure reason.
+ TerminalInfo() (*HTLCAttempt, *FailureReason)
+}
diff --git a/routing/control_tower.go b/routing/control_tower.go
index fcbfbe8..c5d91e8 100644
--- a/routing/control_tower.go
+++ b/routing/control_tower.go
@@ -9,38 +9,6 @@ import (
"github.com/lightningnetwork/lnd/queue"
)
-// DBMPPayment is an interface derived from channeldb.MPPayment that is used by
-// the payment lifecycle.
-type DBMPPayment interface {
- // GetState returns the current state of the payment.
- GetState() *paymentsdb.MPPaymentState
-
- // Terminated returns true if the payment is in a final state.
- Terminated() bool
-
- // GetStatus returns the current status of the payment.
- GetStatus() paymentsdb.PaymentStatus
-
- // NeedWaitAttempts specifies whether the payment needs to wait for the
- // outcome of an attempt.
- NeedWaitAttempts() (bool, error)
-
- // GetHTLCs returns all HTLCs of this payment.
- GetHTLCs() []paymentsdb.HTLCAttempt
-
- // InFlightHTLCs returns all HTLCs that are in flight.
- InFlightHTLCs() []paymentsdb.HTLCAttempt
-
- // AllowMoreAttempts is used to decide whether we can safely attempt
- // more HTLCs for a given payment state. Return an error if the payment
- // is in an unexpected state.
- AllowMoreAttempts() (bool, error)
-
- // TerminalInfo returns the settled HTLC attempt or the payment's
- // failure reason.
- TerminalInfo() (*paymentsdb.HTLCAttempt, *paymentsdb.FailureReason)
-}
-
// ControlTower tracks all outgoing payments made, whose primary purpose is to
// prevent duplicate payments to the same payment hash. In production, a
// persistent implementation is preferred so that tracking can survive across
@@ -76,7 +44,7 @@ type ControlTower interface {
// FetchPayment fetches the payment corresponding to the given payment
// hash.
- FetchPayment(paymentHash lntypes.Hash) (DBMPPayment, error)
+ FetchPayment(paymentHash lntypes.Hash) (paymentsdb.DBMPPayment, error)
// FailPayment transitions a payment into the Failed state, and records
// the ultimate reason the payment failed. Note that this should only
@@ -273,7 +241,7 @@ func (p *controlTower) FailAttempt(paymentHash lntypes.Hash,
// FetchPayment fetches the payment corresponding to the given payment hash.
func (p *controlTower) FetchPayment(paymentHash lntypes.Hash) (
- DBMPPayment, error) {
+ paymentsdb.DBMPPayment, error) {
return p.db.FetchPayment(paymentHash)
}
diff --git a/routing/mock_test.go b/routing/mock_test.go
index 9cb938f..19a76ee 100644
--- a/routing/mock_test.go
+++ b/routing/mock_test.go
@@ -510,7 +510,7 @@ func (m *mockControlTowerOld) FailPayment(phash lntypes.Hash,
}
func (m *mockControlTowerOld) FetchPayment(phash lntypes.Hash) (
- DBMPPayment, error) {
+ paymentsdb.DBMPPayment, error) {
m.Lock()
defer m.Unlock()
@@ -787,7 +787,7 @@ func (m *mockControlTower) FailPayment(phash lntypes.Hash,
}
func (m *mockControlTower) FetchPayment(phash lntypes.Hash) (
- DBMPPayment, error) {
+ paymentsdb.DBMPPayment, error) {
args := m.Called(phash)
@@ -825,7 +825,7 @@ type mockMPPayment struct {
mock.Mock
}
-var _ DBMPPayment = (*mockMPPayment)(nil)
+var _ paymentsdb.DBMPPayment = (*mockMPPayment)(nil)
func (m *mockMPPayment) GetState() *paymentsdb.MPPaymentState {
args := m.Called()
diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go
index 245e3b3..cc92a8b 100644
--- a/routing/payment_lifecycle.go
+++ b/routing/payment_lifecycle.go
@@ -130,7 +130,7 @@ const (
// wait for results, the method will exit with `stepExit` such that the payment
// lifecycle loop will terminate.
func (p *paymentLifecycle) decideNextStep(
- payment DBMPPayment) (stateStep, error) {
+ payment paymentsdb.DBMPPayment) (stateStep, error) {
// Check whether we could make new HTLC attempts.
allow, err := payment.AllowMoreAttempts()
@@ -1110,7 +1110,9 @@ func (p *paymentLifecycle) patchLegacyPaymentHash(
// reloadInflightAttempts is called when the payment lifecycle is resumed after
// a restart. It reloads all inflight attempts from the control tower and
// collects the results of the attempts that have been sent before.
-func (p *paymentLifecycle) reloadInflightAttempts() (DBMPPayment, error) {
+func (p *paymentLifecycle) reloadInflightAttempts() (paymentsdb.DBMPPayment,
+ error) {
+
payment, err := p.router.cfg.Control.FetchPayment(p.identifier)
if err != nil {
return nil, err
@@ -1133,7 +1135,7 @@ func (p *paymentLifecycle) reloadInflightAttempts() (DBMPPayment, error) {
}
// reloadPayment returns the latest payment found in the db (control tower).
-func (p *paymentLifecycle) reloadPayment() (DBMPPayment,
+func (p *paymentLifecycle) reloadPayment() (paymentsdb.DBMPPayment,
*paymentsdb.MPPaymentState, error) {
// Read the db to get the latest state of the payment.
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.