From 967b4b2dc307046f8668a5241e0739b7fa1943f5 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 19 Feb 2020 09:53:13 +0100 Subject: [PATCH] channeldb: remove redundant MPPaymentCreationInfo struct MPPaymentCreationInfo and PaymentCreationInfo are identical except for the naming of CreationTime/CreationDate. --- channeldb/mp_payment.go | 23 +++-------------------- channeldb/payment_control_test.go | 2 +- channeldb/payments.go | 12 ++++++------ channeldb/payments_test.go | 2 +- routing/control_tower_test.go | 2 +- routing/router.go | 4 ++-- 6 files changed, 14 insertions(+), 31 deletions(-) diff --git a/channeldb/mp_payment.go b/channeldb/mp_payment.go index 9a26cdbd..bee26759 100644 --- a/channeldb/mp_payment.go +++ b/channeldb/mp_payment.go @@ -5,26 +5,9 @@ import ( "github.com/btcsuite/btcd/btcec" "github.com/lightningnetwork/lnd/lntypes" - "github.com/lightningnetwork/lnd/lnwire" "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 // 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 @@ -74,8 +57,8 @@ type HTLCFailInfo struct { FailTime time.Time } -// MPPayment is a wrapper around a payment's MPPaymentCreationInfo and -// HTLCAttempts. All payments will have the MPPPaymentCreationInfo set, any +// MPPayment is a wrapper around a payment's PaymentCreationInfo and +// HTLCAttempts. All payments will have the PaymentCreationInfo set, any // HTLCs made in attempts to be completed will populated in the HTLCs slice. // 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 @@ -87,7 +70,7 @@ type MPPayment struct { // Info holds all static information about this payment, and is // populated when the payment is initiated. - Info *MPPaymentCreationInfo + Info *PaymentCreationInfo // HTLCs holds the information about individual HTLCs that we send in // order to make the payment. diff --git a/channeldb/payment_control_test.go b/channeldb/payment_control_test.go index 7be04c6b..bb1458ae 100644 --- a/channeldb/payment_control_test.go +++ b/channeldb/payment_control_test.go @@ -51,7 +51,7 @@ func genInfo() (*PaymentCreationInfo, *PaymentAttemptInfo, return &PaymentCreationInfo{ PaymentHash: rhash, Value: 1, - CreationDate: time.Unix(time.Now().Unix(), 0), + CreationTime: time.Unix(time.Now().Unix(), 0), PaymentRequest: []byte("hola"), }, &PaymentAttemptInfo{ diff --git a/channeldb/payments.go b/channeldb/payments.go index a03c9e0c..0800b998 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -178,8 +178,8 @@ type PaymentCreationInfo struct { // Value is the amount we are paying. Value lnwire.MilliSatoshi - // CreatingDate is the time when this payment was initiated. - CreationDate time.Time + // CreationTime is the time when this payment was initiated. + CreationTime time.Time // PaymentRequest is the full payment request, if any. PaymentRequest []byte @@ -283,10 +283,10 @@ func (p *Payment) ToMPPayment() *MPPayment { return &MPPayment{ sequenceNum: p.sequenceNum, - Info: &MPPaymentCreationInfo{ + Info: &PaymentCreationInfo{ PaymentHash: p.Info.PaymentHash, Value: p.Info.Value, - CreationTime: p.Info.CreationDate, + CreationTime: p.Info.CreationTime, PaymentRequest: p.Info.PaymentRequest, }, HTLCs: htlcs, @@ -475,7 +475,7 @@ func serializePaymentCreationInfo(w io.Writer, c *PaymentCreationInfo) error { return err } - byteOrder.PutUint64(scratch[:], uint64(c.CreationDate.Unix())) + byteOrder.PutUint64(scratch[:], uint64(c.CreationTime.Unix())) if _, err := w.Write(scratch[:]); err != nil { return err } @@ -509,7 +509,7 @@ func deserializePaymentCreationInfo(r io.Reader) (*PaymentCreationInfo, error) { if _, err := io.ReadFull(r, scratch[:]); err != nil { 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 { return nil, err diff --git a/channeldb/payments_test.go b/channeldb/payments_test.go index 16e952df..fb3de6ce 100644 --- a/channeldb/payments_test.go +++ b/channeldb/payments_test.go @@ -62,7 +62,7 @@ func makeFakeInfo() (*PaymentCreationInfo, *PaymentAttemptInfo) { Value: 1000, // Use single second precision to avoid false positive test // failures due to the monotonic time component. - CreationDate: time.Unix(time.Now().Unix(), 0), + CreationTime: time.Unix(time.Now().Unix(), 0), PaymentRequest: []byte(""), } diff --git a/routing/control_tower_test.go b/routing/control_tower_test.go index e326e98c..9fa5ec5b 100644 --- a/routing/control_tower_test.go +++ b/routing/control_tower_test.go @@ -311,7 +311,7 @@ func genInfo() (*channeldb.PaymentCreationInfo, *channeldb.PaymentAttemptInfo, return &channeldb.PaymentCreationInfo{ PaymentHash: rhash, Value: 1, - CreationDate: time.Unix(time.Now().Unix(), 0), + CreationTime: time.Unix(time.Now().Unix(), 0), PaymentRequest: []byte("hola"), }, &channeldb.PaymentAttemptInfo{ diff --git a/routing/router.go b/routing/router.go index e42ce7a0..d30191b5 100644 --- a/routing/router.go +++ b/routing/router.go @@ -1680,7 +1680,7 @@ func (r *ChannelRouter) preparePayment(payment *LightningPayment) ( info := &channeldb.PaymentCreationInfo{ PaymentHash: payment.PaymentHash, Value: payment.Amount, - CreationDate: time.Now(), + CreationTime: time.Now(), PaymentRequest: payment.PaymentRequest, } @@ -1709,7 +1709,7 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, route *route.Route) ( info := &channeldb.PaymentCreationInfo{ PaymentHash: hash, Value: amt, - CreationDate: time.Now(), + CreationTime: time.Now(), PaymentRequest: nil, }