multi: move PaymentCreationInfo to payment pkg
What changed, and why it matters
This commit is a straightforward internal code reorganization: it moves the PaymentCreationInfo data structure from the channeldb package into the payments/db package and updates all references accordingly. There is no functional change, no bug fix, and no security-relevant behavior change visible in the diff.
No security action needed; treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change deletes channeldb/payments.go, adds the same PaymentCreationInfo struct (and its String method) to payments/db/payment.go, and mechanically replaces all channeldb.PaymentCreationInfo type references with paymentsdb.PaymentCreationInfo across tests, mocks, serialization helpers, and the routing control tower. Field definitions, serialization/deserialization logic, and call sites remain identical.
Changed components
channeldb/payments.gopayments/db/payment.gopayments/db/kv_store.gopayments/db/kv_duplicate_payments.gorouting/control_tower.gorouting/router.golnrpc/routerrpc/router_server_test.gopayments/db/kv_store_test.gopayments/db/payment_test.gorouting/control_tower_test.gorouting/mock_test.goInspect captured patch +58 / −75
diff --git a/channeldb/payments.go b/channeldb/payments.go
deleted file mode 100644
index 2543c9d..0000000
--- a/channeldb/payments.go
+++ /dev/null
@@ -1,37 +0,0 @@
-package channeldb
-
-import (
- "fmt"
- "time"
-
- "github.com/lightningnetwork/lnd/lntypes"
- "github.com/lightningnetwork/lnd/lnwire"
-)
-
-// PaymentCreationInfo is the information necessary to have ready when
-// initiating a payment, moving it into state InFlight.
-type PaymentCreationInfo struct {
- // PaymentIdentifier is the hash this payment is paying to in case of
- // non-AMP payments, and the SetID for AMP payments.
- PaymentIdentifier lntypes.Hash
-
- // Value is the amount we are paying.
- Value lnwire.MilliSatoshi
-
- // CreationTime is the time when this payment was initiated.
- CreationTime time.Time
-
- // PaymentRequest is the full payment request, if any.
- PaymentRequest []byte
-
- // FirstHopCustomRecords are the TLV records that are to be sent to the
- // first hop of this payment. These records will be transmitted via the
- // wire message only and therefore do not affect the onion payload size.
- FirstHopCustomRecords lnwire.CustomRecords
-}
-
-// String returns a human-readable description of the payment creation info.
-func (p *PaymentCreationInfo) String() string {
- return fmt.Sprintf("payment_id=%v, amount=%v, created_at=%v",
- p.PaymentIdentifier, p.Value, p.CreationTime)
-}
diff --git a/lnrpc/routerrpc/router_server_test.go b/lnrpc/routerrpc/router_server_test.go
index ce513d5..70e3fbd 100644
--- a/lnrpc/routerrpc/router_server_test.go
+++ b/lnrpc/routerrpc/router_server_test.go
@@ -6,7 +6,6 @@ import (
"time"
"github.com/btcsuite/btcd/btcec/v2"
- "github.com/lightningnetwork/lnd/channeldb"
graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwire"
@@ -131,11 +130,11 @@ func TestTrackPaymentsInflightUpdates(t *testing.T) {
// Enqueue some payment updates on the mock.
towerMock.queue.ChanIn() <- &paymentsdb.MPPayment{
- Info: &channeldb.PaymentCreationInfo{},
+ Info: &paymentsdb.PaymentCreationInfo{},
Status: paymentsdb.StatusInFlight,
}
towerMock.queue.ChanIn() <- &paymentsdb.MPPayment{
- Info: &channeldb.PaymentCreationInfo{},
+ Info: &paymentsdb.PaymentCreationInfo{},
Status: paymentsdb.StatusSucceeded,
}
@@ -193,11 +192,11 @@ func TestTrackPaymentsNoInflightUpdates(t *testing.T) {
// Enqueue some payment updates on the mock.
towerMock.queue.ChanIn() <- &paymentsdb.MPPayment{
- Info: &channeldb.PaymentCreationInfo{},
+ Info: &paymentsdb.PaymentCreationInfo{},
Status: paymentsdb.StatusInFlight,
}
towerMock.queue.ChanIn() <- &paymentsdb.MPPayment{
- Info: &channeldb.PaymentCreationInfo{},
+ Info: &paymentsdb.PaymentCreationInfo{},
Status: paymentsdb.StatusSucceeded,
}
diff --git a/payments/db/kv_duplicate_payments.go b/payments/db/kv_duplicate_payments.go
index ed539ce..3ac1fad 100644
--- a/payments/db/kv_duplicate_payments.go
+++ b/payments/db/kv_duplicate_payments.go
@@ -8,7 +8,6 @@ import (
"time"
"github.com/btcsuite/btcd/btcec/v2"
- "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
@@ -94,11 +93,11 @@ func deserializeDuplicateHTLCAttemptInfo(r io.Reader) (
}
func deserializeDuplicatePaymentCreationInfo(r io.Reader) (
- *channeldb.PaymentCreationInfo, error) {
+ *PaymentCreationInfo, error) {
var scratch [8]byte
- c := &channeldb.PaymentCreationInfo{}
+ c := &PaymentCreationInfo{}
if _, err := io.ReadFull(r, c.PaymentIdentifier[:]); err != nil {
return nil, err
diff --git a/payments/db/kv_store.go b/payments/db/kv_store.go
index 18365f1..02ba649 100644
--- a/payments/db/kv_store.go
+++ b/payments/db/kv_store.go
@@ -186,7 +186,7 @@ func initKVStore(db kvdb.Backend) error {
// method returns successfully, the payment is guaranteed to be in the InFlight
// state.
func (p *KVPaymentsDB) InitPayment(paymentHash lntypes.Hash,
- info *channeldb.PaymentCreationInfo) error {
+ info *PaymentCreationInfo) error {
// Obtain a new sequence number for this payment. This is used
// to sort the payments in order of creation, and also acts as
@@ -943,7 +943,7 @@ func (p *KVPaymentsDB) FetchPayments() ([]*MPPayment, error) {
return payments, nil
}
-func fetchCreationInfo(bucket kvdb.RBucket) (*channeldb.PaymentCreationInfo, error) {
+func fetchCreationInfo(bucket kvdb.RBucket) (*PaymentCreationInfo, error) {
b := bucket.Get(paymentCreationInfoKey)
if b == nil {
return nil, fmt.Errorf("creation info not found")
@@ -1621,7 +1621,7 @@ func fetchSequenceNumbers(paymentBucket kvdb.RBucket) ([][]byte, error) {
return sequenceNumbers, nil
}
-func serializePaymentCreationInfo(w io.Writer, c *channeldb.PaymentCreationInfo) error {
+func serializePaymentCreationInfo(w io.Writer, c *PaymentCreationInfo) error {
var scratch [8]byte
if _, err := w.Write(c.PaymentIdentifier[:]); err != nil {
@@ -1658,12 +1658,12 @@ func serializePaymentCreationInfo(w io.Writer, c *channeldb.PaymentCreationInfo)
return nil
}
-func deserializePaymentCreationInfo(r io.Reader) (*channeldb.PaymentCreationInfo,
+func deserializePaymentCreationInfo(r io.Reader) (*PaymentCreationInfo,
error) {
var scratch [8]byte
- c := &channeldb.PaymentCreationInfo{}
+ c := &PaymentCreationInfo{}
if _, err := io.ReadFull(r, c.PaymentIdentifier[:]); err != nil {
return nil, err
diff --git a/payments/db/kv_store_test.go b/payments/db/kv_store_test.go
index 3bf4f35..cc64776 100644
--- a/payments/db/kv_store_test.go
+++ b/payments/db/kv_store_test.go
@@ -13,7 +13,6 @@ import (
"github.com/btcsuite/btcwallet/walletdb"
"github.com/davecgh/go-spew/spew"
- "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
@@ -32,7 +31,7 @@ func genPreimage() ([32]byte, error) {
return preimage, nil
}
-func genInfo(t *testing.T) (*channeldb.PaymentCreationInfo, *HTLCAttemptInfo,
+func genInfo(t *testing.T) (*PaymentCreationInfo, *HTLCAttemptInfo,
lntypes.Preimage, error) {
preimage, err := genPreimage()
@@ -50,7 +49,7 @@ func genInfo(t *testing.T) (*channeldb.PaymentCreationInfo, *HTLCAttemptInfo,
)
require.NoError(t, err)
- return &channeldb.PaymentCreationInfo{
+ return &PaymentCreationInfo{
PaymentIdentifier: rhash,
Value: testRoute.ReceiverAmt(),
CreationTime: time.Unix(time.Now().Unix(), 0),
@@ -1156,7 +1155,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 *FailureReason,
+ c *PaymentCreationInfo, f *FailureReason,
a *htlcStatus) {
t.Helper()
@@ -1397,7 +1396,7 @@ func assertPayments(t *testing.T, paymentDB *KVPaymentsDB,
require.Equal(t, payments, p)
}
-func makeFakeInfo(t *testing.T) (*channeldb.PaymentCreationInfo,
+func makeFakeInfo(t *testing.T) (*PaymentCreationInfo,
*HTLCAttemptInfo) {
var preimg lntypes.Preimage
@@ -1405,7 +1404,7 @@ func makeFakeInfo(t *testing.T) (*channeldb.PaymentCreationInfo,
hash := preimg.Hash()
- c := &channeldb.PaymentCreationInfo{
+ c := &PaymentCreationInfo{
PaymentIdentifier: hash,
Value: 1000,
// Use single second precision to avoid false positive test
diff --git a/payments/db/payment.go b/payments/db/payment.go
index 334b66e..a5ad753 100644
--- a/payments/db/payment.go
+++ b/payments/db/payment.go
@@ -12,7 +12,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/lntypes"
"github.com/lightningnetwork/lnd/lnutils"
"github.com/lightningnetwork/lnd/lnwire"
@@ -76,6 +75,34 @@ func (r FailureReason) String() string {
return "unknown"
}
+// PaymentCreationInfo is the information necessary to have ready when
+// initiating a payment, moving it into state InFlight.
+type PaymentCreationInfo struct {
+ // PaymentIdentifier is the hash this payment is paying to in case of
+ // non-AMP payments, and the SetID for AMP payments.
+ PaymentIdentifier lntypes.Hash
+
+ // Value is the amount we are paying.
+ Value lnwire.MilliSatoshi
+
+ // CreationTime is the time when this payment was initiated.
+ CreationTime time.Time
+
+ // PaymentRequest is the full payment request, if any.
+ PaymentRequest []byte
+
+ // FirstHopCustomRecords are the TLV records that are to be sent to the
+ // first hop of this payment. These records will be transmitted via the
+ // wire message only and therefore do not affect the onion payload size.
+ FirstHopCustomRecords lnwire.CustomRecords
+}
+
+// String returns a human-readable description of the payment creation info.
+func (p *PaymentCreationInfo) String() string {
+ return fmt.Sprintf("payment_id=%v, amount=%v, created_at=%v",
+ p.PaymentIdentifier, p.Value, p.CreationTime)
+}
+
// 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
@@ -298,7 +325,7 @@ type MPPayment struct {
// Info holds all static information about this payment, and is
// populated when the payment is initiated.
- Info *channeldb.PaymentCreationInfo
+ Info *PaymentCreationInfo
// HTLCs holds the information about individual HTLCs that we send in
// order to make the payment.
diff --git a/payments/db/payment_test.go b/payments/db/payment_test.go
index a0878e5..2f6bf40 100644
--- a/payments/db/payment_test.go
+++ b/payments/db/payment_test.go
@@ -12,7 +12,6 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/davecgh/go-spew/spew"
- "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record"
@@ -694,7 +693,7 @@ func TestPaymentSetState(t *testing.T) {
t.Parallel()
// Attach the payment info.
- info := &channeldb.PaymentCreationInfo{
+ info := &PaymentCreationInfo{
Value: lnwire.MilliSatoshi(tc.totalAmt),
}
tc.payment.Info = info
@@ -824,7 +823,7 @@ func TestNeedWaitAttempts(t *testing.T) {
tc := tc
p := &MPPayment{
- Info: &channeldb.PaymentCreationInfo{
+ Info: &PaymentCreationInfo{
PaymentIdentifier: [32]byte{1, 2, 3},
},
Status: tc.status,
@@ -1002,7 +1001,7 @@ func TestAllowMoreAttempts(t *testing.T) {
tc := tc
p := &MPPayment{
- Info: &channeldb.PaymentCreationInfo{
+ Info: &PaymentCreationInfo{
PaymentIdentifier: [32]byte{1, 2, 3},
},
Status: tc.status,
diff --git a/routing/control_tower.go b/routing/control_tower.go
index 70e7d9b..c5af230 100644
--- a/routing/control_tower.go
+++ b/routing/control_tower.go
@@ -3,7 +3,6 @@ package routing
import (
"sync"
- "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/multimutex"
paymentsdb "github.com/lightningnetwork/lnd/payments/db"
@@ -50,7 +49,7 @@ type DBMPPayment interface {
type ControlTower interface {
// This method checks that no succeeded payment exist for this payment
// hash.
- InitPayment(lntypes.Hash, *channeldb.PaymentCreationInfo) error
+ InitPayment(lntypes.Hash, *paymentsdb.PaymentCreationInfo) error
// DeleteFailedAttempts removes all failed HTLCs from the db. It should
// be called for a given payment whenever all inflight htlcs are
@@ -185,7 +184,7 @@ func NewControlTower(db *paymentsdb.KVPaymentsDB) ControlTower {
// method returns successfully, the payment is guaranteed to be in the
// Initiated state.
func (p *controlTower) InitPayment(paymentHash lntypes.Hash,
- info *channeldb.PaymentCreationInfo) error {
+ info *paymentsdb.PaymentCreationInfo) error {
err := p.db.InitPayment(paymentHash, info)
if err != nil {
diff --git a/routing/control_tower_test.go b/routing/control_tower_test.go
index 9250b21..9a49377 100644
--- a/routing/control_tower_test.go
+++ b/routing/control_tower_test.go
@@ -559,7 +559,7 @@ func initDB(t *testing.T) *channeldb.DB {
)
}
-func genInfo() (*channeldb.PaymentCreationInfo, *paymentsdb.HTLCAttemptInfo,
+func genInfo() (*paymentsdb.PaymentCreationInfo, *paymentsdb.HTLCAttemptInfo,
lntypes.Preimage, error) {
preimage, err := genPreimage()
@@ -579,7 +579,7 @@ func genInfo() (*channeldb.PaymentCreationInfo, *paymentsdb.HTLCAttemptInfo,
return nil, nil, lntypes.Preimage{}, err
}
- return &channeldb.PaymentCreationInfo{
+ return &paymentsdb.PaymentCreationInfo{
PaymentIdentifier: rhash,
Value: testRoute.ReceiverAmt(),
CreationTime: time.Unix(time.Now().Unix(), 0),
diff --git a/routing/mock_test.go b/routing/mock_test.go
index e993ea8..596b511 100644
--- a/routing/mock_test.go
+++ b/routing/mock_test.go
@@ -7,7 +7,6 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
- "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/htlcswitch"
@@ -248,7 +247,7 @@ func (m *mockPayerOld) CleanStore(pids map[uint64]struct{}) error {
}
type initArgs struct {
- c *channeldb.PaymentCreationInfo
+ c *paymentsdb.PaymentCreationInfo
}
type registerAttemptArgs struct {
@@ -268,7 +267,7 @@ type failPaymentArgs struct {
}
type testPayment struct {
- info channeldb.PaymentCreationInfo
+ info paymentsdb.PaymentCreationInfo
attempts []paymentsdb.HTLCAttempt
}
@@ -298,7 +297,7 @@ func makeMockControlTower() *mockControlTowerOld {
}
func (m *mockControlTowerOld) InitPayment(phash lntypes.Hash,
- c *channeldb.PaymentCreationInfo) error {
+ c *paymentsdb.PaymentCreationInfo) error {
if m.init != nil {
m.init <- initArgs{c}
@@ -733,7 +732,7 @@ type mockControlTower struct {
var _ ControlTower = (*mockControlTower)(nil)
func (m *mockControlTower) InitPayment(phash lntypes.Hash,
- c *channeldb.PaymentCreationInfo) error {
+ c *paymentsdb.PaymentCreationInfo) error {
args := m.Called(phash, c)
return args.Error(0)
diff --git a/routing/router.go b/routing/router.go
index 45d80f6..1dac108 100644
--- a/routing/router.go
+++ b/routing/router.go
@@ -15,7 +15,6 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/amp"
- "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/graph/db/models"
@@ -999,7 +998,7 @@ func (r *ChannelRouter) PreparePayment(payment *LightningPayment) (
// already in-flight.
//
// TODO(roasbeef): store records as part of creation info?
- info := &channeldb.PaymentCreationInfo{
+ info := &paymentsdb.PaymentCreationInfo{
PaymentIdentifier: payment.Identifier(),
Value: payment.Amount,
CreationTime: r.cfg.Clock.Now(),
@@ -1122,7 +1121,7 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
// Record this payment hash with the ControlTower, ensuring it is not
// already in-flight.
- info := &channeldb.PaymentCreationInfo{
+ info := &paymentsdb.PaymentCreationInfo{
PaymentIdentifier: paymentIdentifier,
Value: amt,
CreationTime: r.cfg.Clock.Now(),
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.