multi: move PaymentCreationInfo to payment pkg

This commit is contained in:
ziggie committed 2025-08-14 19:53:18 +02:00
1 parent d138e23919
commit df9bac2ecf
11 files changed
+58 -75

No files matched your search

-37
View File
@@ -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)
}
+4 -5
View File
@@ -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,
}
+2 -3
View File
@@ -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
+5 -5
View File
@@ -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
+5 -6
View File
@@ -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
+29 -2
View File
@@ -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.
+3 -4
View File
@@ -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,
+2 -3
View File
@@ -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 {
+2 -2
View File
@@ -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),
+4 -5
View File
@@ -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)
+2 -3
View File
@@ -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(),