From b174ae80bfd3c51a19fc6fd20714c8e069a72572 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 21 Aug 2017 22:33:20 -0700 Subject: [PATCH] lnwire: convert all relevant fields to use the MilliSatoshi type --- lnwire/accept_channel.go | 12 ++++-------- lnwire/lnwire_test.go | 14 +++++++------- lnwire/onion_error.go | 16 ++++++++-------- lnwire/onion_error_test.go | 4 +--- lnwire/open_channel.go | 14 +++++--------- lnwire/update_add_htlc.go | 10 +++------- 6 files changed, 28 insertions(+), 42 deletions(-) diff --git a/lnwire/accept_channel.go b/lnwire/accept_channel.go index 3cd0e1fb..020e2827 100644 --- a/lnwire/accept_channel.go +++ b/lnwire/accept_channel.go @@ -25,9 +25,7 @@ type AcceptChannel struct { // MaxValueInFlight represents the maximum amount of coins that can be // pending within the channel at any given time. If the amount of funds // in limbo exceeds this amount, then the channel will be failed. - // - // TODO(roasbeef): is msat - MaxValueInFlight btcutil.Amount + MaxValueInFlight MilliSatoshi // ChannelReserve is the amount of BTC that the receiving party MUST // maintain a balance above at all times. This is a safety mechanism to @@ -41,9 +39,7 @@ type AcceptChannel struct { // HtlcMinimum is the smallest HTLC that the sender of this message // will accept. - // - // TODO(roasbeef): is msat - HtlcMinimum uint32 + HtlcMinimum MilliSatoshi // CsvDelay is the number of blocks to use for the relative time lock // in the pay-to-self output of both commitment transactions. @@ -149,6 +145,6 @@ func (a *AcceptChannel) MsgType() MessageType { // // This is part of the lnwire.Message interface. func (a *AcceptChannel) MaxPayloadLength(uint32) uint32 { - // 32 + (8 * 3) + (4 * 2) + (2 * 2) + (33 * 5) - return 233 + // 32 + (8 * 4) + (4 * 1) + (2 * 2) + (33 * 5) + return 237 } diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index eea58d3f..0f7ecb04 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -124,7 +124,7 @@ func TestLightningWireProtocol(t *testing.T) { } if !reflect.DeepEqual(msg, newMsg) { t.Fatalf("messages don't match after re-encoding: %v "+ - "vs %v", msg, newMsg) + "vs %v", spew.Sdump(msg), spew.Sdump(newMsg)) return false } @@ -149,11 +149,11 @@ func TestLightningWireProtocol(t *testing.T) { MsgOpenChannel: func(v []reflect.Value, r *rand.Rand) { req := OpenChannel{ FundingAmount: btcutil.Amount(r.Int63()), - PushAmount: btcutil.Amount(r.Int63()), + PushAmount: MilliSatoshi(r.Int63()), DustLimit: btcutil.Amount(r.Int63()), - MaxValueInFlight: btcutil.Amount(r.Int63()), + MaxValueInFlight: MilliSatoshi(r.Int63()), ChannelReserve: btcutil.Amount(r.Int63()), - HtlcMinimum: uint32(r.Int31()), + HtlcMinimum: MilliSatoshi(r.Int31()), FeePerKiloWeight: uint32(r.Int63()), CsvDelay: uint16(r.Int31()), MaxAcceptedHTLCs: uint16(r.Int31()), @@ -202,10 +202,10 @@ func TestLightningWireProtocol(t *testing.T) { MsgAcceptChannel: func(v []reflect.Value, r *rand.Rand) { req := AcceptChannel{ DustLimit: btcutil.Amount(r.Int63()), - MaxValueInFlight: btcutil.Amount(r.Int63()), + MaxValueInFlight: MilliSatoshi(r.Int63()), ChannelReserve: btcutil.Amount(r.Int63()), MinAcceptDepth: uint32(r.Int31()), - HtlcMinimum: uint32(r.Int31()), + HtlcMinimum: MilliSatoshi(r.Int31()), CsvDelay: uint16(r.Int31()), MaxAcceptedHTLCs: uint16(r.Int31()), } @@ -412,7 +412,7 @@ func TestLightningWireProtocol(t *testing.T) { Timestamp: uint32(r.Int31()), Flags: uint16(r.Int31()), TimeLockDelta: uint16(r.Int31()), - HtlcMinimumMsat: uint64(r.Int63()), + HtlcMinimumMsat: MilliSatoshi(r.Int63()), BaseFee: uint32(r.Int31()), FeeRate: uint32(r.Int31()), } diff --git a/lnwire/onion_error.go b/lnwire/onion_error.go index 4f87ad4a..121c50b3 100644 --- a/lnwire/onion_error.go +++ b/lnwire/onion_error.go @@ -448,15 +448,15 @@ func (f *FailTemporaryChannelFailure) Encode(w io.Writer, pver uint32) error { // NOTE: May only be returned by the intermediate nodes in the path. type FailAmountBelowMinimum struct { // HtlcMsat is the wrong amount of the incoming HTLC. - HtlcMsat btcutil.Amount + HtlcMsat MilliSatoshi - // Update is used to update information about state of the channel which - // caused the failure. + // Update is used to update information about state of the channel + // which caused the failure. Update ChannelUpdate } // NewAmountBelowMinimum creates new instance of the FailAmountBelowMinimum. -func NewAmountBelowMinimum(htlcMsat btcutil.Amount, +func NewAmountBelowMinimum(htlcMsat MilliSatoshi, update ChannelUpdate) *FailAmountBelowMinimum { return &FailAmountBelowMinimum{ @@ -512,7 +512,7 @@ func (f *FailAmountBelowMinimum) Encode(w io.Writer, pver uint32) error { // NOTE: May only be returned by intermediate nodes. type FailFeeInsufficient struct { // HtlcMsat is the wrong amount of the incoming HTLC. - HtlcMsat btcutil.Amount + HtlcMsat MilliSatoshi // Update is used to update information about state of the channel // which caused the failure. @@ -520,7 +520,7 @@ type FailFeeInsufficient struct { } // NewFeeInsufficient creates new instance of the FailFeeInsufficient. -func NewFeeInsufficient(htlcMsat btcutil.Amount, +func NewFeeInsufficient(htlcMsat MilliSatoshi, update ChannelUpdate) *FailFeeInsufficient { return &FailFeeInsufficient{ HtlcMsat: htlcMsat, @@ -791,12 +791,12 @@ func (f *FailFinalIncorrectCltvExpiry) Encode(w io.Writer, pver uint32) error { // NOTE: May only be returned by the final node. type FailFinalIncorrectHtlcAmount struct { // IncomingHTLCAmount is the wrong forwarded htlc amount. - IncomingHTLCAmount btcutil.Amount + IncomingHTLCAmount MilliSatoshi } // NewFinalIncorrectHtlcAmount creates new instance of the // FailFinalIncorrectHtlcAmount. -func NewFinalIncorrectHtlcAmount(amount btcutil.Amount) *FailFinalIncorrectHtlcAmount { +func NewFinalIncorrectHtlcAmount(amount MilliSatoshi) *FailFinalIncorrectHtlcAmount { return &FailFinalIncorrectHtlcAmount{ IncomingHTLCAmount: amount, } diff --git a/lnwire/onion_error_test.go b/lnwire/onion_error_test.go index 3650b59d..7817f677 100644 --- a/lnwire/onion_error_test.go +++ b/lnwire/onion_error_test.go @@ -4,13 +4,11 @@ import ( "bytes" "reflect" "testing" - - "github.com/roasbeef/btcutil" ) var ( testOnionHash = []byte{} - testAmount = btcutil.Amount(1) + testAmount = MilliSatoshi(1) testCtlvExpiry = uint32(2) testFlags = uint16(2) testChannelUpdate = ChannelUpdate{ diff --git a/lnwire/open_channel.go b/lnwire/open_channel.go index 74e1ac29..1029cbdd 100644 --- a/lnwire/open_channel.go +++ b/lnwire/open_channel.go @@ -31,9 +31,7 @@ type OpenChannel struct { // PushAmount is the value that the initiating party wishes to "push" // to the responding as part of the first commitment state. If the // responder accepts, then this will be their initial balance. - // - // TODO(roasbeef): is msat - PushAmount btcutil.Amount + PushAmount MilliSatoshi // DustLimit is the specific dust limit the sender of this message // would like enforced on their version of the commitment transaction. @@ -44,7 +42,7 @@ type OpenChannel struct { // MaxValueInFlight represents the maximum amount of coins that can be // pending within the channel at any given time. If the amount of funds // in limbo exceeds this amount, then the channel will be failed. - MaxValueInFlight btcutil.Amount + MaxValueInFlight MilliSatoshi // ChannelReserve is the amount of BTC that the receiving party MUST // maintain a balance above at all times. This is a safety mechanism to @@ -54,9 +52,7 @@ type OpenChannel struct { // HtlcMinimum is the smallest HTLC that the sender of this message // will accept. - // - // TODO(roasbeef): is msat - HtlcMinimum uint32 + HtlcMinimum MilliSatoshi // FeePerKiloWeight is the initial fee rate that the initiator suggests // for both commitment transaction. This value is expressed in sat per @@ -179,6 +175,6 @@ func (o *OpenChannel) MsgType() MessageType { // // This is part of the lnwire.Message interface. func (o *OpenChannel) MaxPayloadLength(uint32) uint32 { - // (32 * 2) + (8 * 5) + (4 * 2) + (2 * 2) + (33 * 5) + 1 - return 282 + // (32 * 2) + (8 * 6) + (4 * 1) + (2 * 2) + (33 * 5) + 1 + return 286 } diff --git a/lnwire/update_add_htlc.go b/lnwire/update_add_htlc.go index e2923d2f..fa2924a5 100644 --- a/lnwire/update_add_htlc.go +++ b/lnwire/update_add_htlc.go @@ -1,10 +1,6 @@ package lnwire -import ( - "io" - - "github.com/roasbeef/btcutil" -) +import "io" // OnionPacketSize is the size of the serialized Sphinx onion packet included // in each UpdateAddHTLC message. The breakdown of the onion packet is as @@ -35,8 +31,8 @@ type UpdateAddHTLC struct { // sufficient expiry value to allow her to redeem the incoming HTLC. Expiry uint32 - // Amount is the amount of satoshis this HTLC is worth. - Amount btcutil.Amount + // Amount is the amount of millisatoshis this HTLC is worth. + Amount MilliSatoshi // PaymentHash is the payment hash to be included in the HTLC this // request creates. The pre-image to this HTLC must be revelaed by the