multi: move PaymentCreationInfo to payment pkg

This commit is contained in:
ziggie
2025-08-12 14:03:13 +02:00
parent d138e23919
commit df9bac2ecf
11 changed files with 58 additions and 75 deletions

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

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

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

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.

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,