channeldb: remove redundant MPPaymentCreationInfo struct

MPPaymentCreationInfo and PaymentCreationInfo are identical except for
the naming of CreationTime/CreationDate.
This commit is contained in:
Joost Jager 2020-02-19 09:53:13 +01:00
parent 8a5d846f94
commit 967b4b2dc3
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
6 changed files with 14 additions and 31 deletions

@ -5,26 +5,9 @@ import (
"github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/btcec"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
) )
// MPPaymentCreationInfo is the information necessary to have ready when
// initiating a payment, moving it into state InFlight.
type MPPaymentCreationInfo struct {
// PaymentHash is the hash this payment is paying to.
PaymentHash lntypes.Hash
// Value is the amount we are paying.
Value lnwire.MilliSatoshi
// CreatingTime is the time at which this payment was started.
CreationTime time.Time
// PaymentRequest is the full payment request, if any.
PaymentRequest []byte
}
// HTLCAttempt contains information about a specific HTLC attempt for a given // HTLCAttempt contains information about a specific HTLC attempt for a given
// payment. This information is used by the router to handle any errors coming // 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 status of a // back after an attempt is made, and to query the switch about the status of a
@ -74,8 +57,8 @@ type HTLCFailInfo struct {
FailTime time.Time FailTime time.Time
} }
// MPPayment is a wrapper around a payment's MPPaymentCreationInfo and // MPPayment is a wrapper around a payment's PaymentCreationInfo and
// HTLCAttempts. All payments will have the MPPPaymentCreationInfo set, any // HTLCAttempts. All payments will have the PaymentCreationInfo set, any
// HTLCs made in attempts to be completed will populated in the HTLCs slice. // HTLCs made in attempts to be completed will populated in the HTLCs slice.
// Each populated HTLCAttempt represents an attempted HTLC, each of which may // Each populated HTLCAttempt represents an attempted HTLC, each of which may
// have the associated Settle or Fail struct populated if the HTLC is no longer // have the associated Settle or Fail struct populated if the HTLC is no longer
@ -87,7 +70,7 @@ type MPPayment struct {
// Info holds all static information about this payment, and is // Info holds all static information about this payment, and is
// populated when the payment is initiated. // populated when the payment is initiated.
Info *MPPaymentCreationInfo Info *PaymentCreationInfo
// HTLCs holds the information about individual HTLCs that we send in // HTLCs holds the information about individual HTLCs that we send in
// order to make the payment. // order to make the payment.

@ -51,7 +51,7 @@ func genInfo() (*PaymentCreationInfo, *PaymentAttemptInfo,
return &PaymentCreationInfo{ return &PaymentCreationInfo{
PaymentHash: rhash, PaymentHash: rhash,
Value: 1, Value: 1,
CreationDate: time.Unix(time.Now().Unix(), 0), CreationTime: time.Unix(time.Now().Unix(), 0),
PaymentRequest: []byte("hola"), PaymentRequest: []byte("hola"),
}, },
&PaymentAttemptInfo{ &PaymentAttemptInfo{

@ -178,8 +178,8 @@ type PaymentCreationInfo struct {
// Value is the amount we are paying. // Value is the amount we are paying.
Value lnwire.MilliSatoshi Value lnwire.MilliSatoshi
// CreatingDate is the time when this payment was initiated. // CreationTime is the time when this payment was initiated.
CreationDate time.Time CreationTime time.Time
// PaymentRequest is the full payment request, if any. // PaymentRequest is the full payment request, if any.
PaymentRequest []byte PaymentRequest []byte
@ -283,10 +283,10 @@ func (p *Payment) ToMPPayment() *MPPayment {
return &MPPayment{ return &MPPayment{
sequenceNum: p.sequenceNum, sequenceNum: p.sequenceNum,
Info: &MPPaymentCreationInfo{ Info: &PaymentCreationInfo{
PaymentHash: p.Info.PaymentHash, PaymentHash: p.Info.PaymentHash,
Value: p.Info.Value, Value: p.Info.Value,
CreationTime: p.Info.CreationDate, CreationTime: p.Info.CreationTime,
PaymentRequest: p.Info.PaymentRequest, PaymentRequest: p.Info.PaymentRequest,
}, },
HTLCs: htlcs, HTLCs: htlcs,
@ -475,7 +475,7 @@ func serializePaymentCreationInfo(w io.Writer, c *PaymentCreationInfo) error {
return err return err
} }
byteOrder.PutUint64(scratch[:], uint64(c.CreationDate.Unix())) byteOrder.PutUint64(scratch[:], uint64(c.CreationTime.Unix()))
if _, err := w.Write(scratch[:]); err != nil { if _, err := w.Write(scratch[:]); err != nil {
return err return err
} }
@ -509,7 +509,7 @@ func deserializePaymentCreationInfo(r io.Reader) (*PaymentCreationInfo, error) {
if _, err := io.ReadFull(r, scratch[:]); err != nil { if _, err := io.ReadFull(r, scratch[:]); err != nil {
return nil, err return nil, err
} }
c.CreationDate = time.Unix(int64(byteOrder.Uint64(scratch[:])), 0) c.CreationTime = time.Unix(int64(byteOrder.Uint64(scratch[:])), 0)
if _, err := io.ReadFull(r, scratch[:4]); err != nil { if _, err := io.ReadFull(r, scratch[:4]); err != nil {
return nil, err return nil, err

@ -62,7 +62,7 @@ func makeFakeInfo() (*PaymentCreationInfo, *PaymentAttemptInfo) {
Value: 1000, Value: 1000,
// Use single second precision to avoid false positive test // Use single second precision to avoid false positive test
// failures due to the monotonic time component. // failures due to the monotonic time component.
CreationDate: time.Unix(time.Now().Unix(), 0), CreationTime: time.Unix(time.Now().Unix(), 0),
PaymentRequest: []byte(""), PaymentRequest: []byte(""),
} }

@ -311,7 +311,7 @@ func genInfo() (*channeldb.PaymentCreationInfo, *channeldb.PaymentAttemptInfo,
return &channeldb.PaymentCreationInfo{ return &channeldb.PaymentCreationInfo{
PaymentHash: rhash, PaymentHash: rhash,
Value: 1, Value: 1,
CreationDate: time.Unix(time.Now().Unix(), 0), CreationTime: time.Unix(time.Now().Unix(), 0),
PaymentRequest: []byte("hola"), PaymentRequest: []byte("hola"),
}, },
&channeldb.PaymentAttemptInfo{ &channeldb.PaymentAttemptInfo{

@ -1680,7 +1680,7 @@ func (r *ChannelRouter) preparePayment(payment *LightningPayment) (
info := &channeldb.PaymentCreationInfo{ info := &channeldb.PaymentCreationInfo{
PaymentHash: payment.PaymentHash, PaymentHash: payment.PaymentHash,
Value: payment.Amount, Value: payment.Amount,
CreationDate: time.Now(), CreationTime: time.Now(),
PaymentRequest: payment.PaymentRequest, PaymentRequest: payment.PaymentRequest,
} }
@ -1709,7 +1709,7 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, route *route.Route) (
info := &channeldb.PaymentCreationInfo{ info := &channeldb.PaymentCreationInfo{
PaymentHash: hash, PaymentHash: hash,
Value: amt, Value: amt,
CreationDate: time.Now(), CreationTime: time.Now(),
PaymentRequest: nil, PaymentRequest: nil,
} }