lnwire: convert all relevant fields to use the MilliSatoshi type

This commit is contained in:
Olaoluwa Osuntokun 2017-08-21 22:33:20 -07:00
parent 05d05ac5ee
commit b174ae80bf
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
6 changed files with 28 additions and 42 deletions

@ -25,9 +25,7 @@ type AcceptChannel struct {
// MaxValueInFlight represents the maximum amount of coins that can be // MaxValueInFlight represents the maximum amount of coins that can be
// pending within the channel at any given time. If the amount of funds // pending within the channel at any given time. If the amount of funds
// in limbo exceeds this amount, then the channel will be failed. // in limbo exceeds this amount, then the channel will be failed.
// MaxValueInFlight MilliSatoshi
// TODO(roasbeef): is msat
MaxValueInFlight btcutil.Amount
// ChannelReserve is the amount of BTC that the receiving party MUST // ChannelReserve is the amount of BTC that the receiving party MUST
// maintain a balance above at all times. This is a safety mechanism to // 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 // HtlcMinimum is the smallest HTLC that the sender of this message
// will accept. // will accept.
// HtlcMinimum MilliSatoshi
// TODO(roasbeef): is msat
HtlcMinimum uint32
// CsvDelay is the number of blocks to use for the relative time lock // CsvDelay is the number of blocks to use for the relative time lock
// in the pay-to-self output of both commitment transactions. // 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. // This is part of the lnwire.Message interface.
func (a *AcceptChannel) MaxPayloadLength(uint32) uint32 { func (a *AcceptChannel) MaxPayloadLength(uint32) uint32 {
// 32 + (8 * 3) + (4 * 2) + (2 * 2) + (33 * 5) // 32 + (8 * 4) + (4 * 1) + (2 * 2) + (33 * 5)
return 233 return 237
} }

@ -124,7 +124,7 @@ func TestLightningWireProtocol(t *testing.T) {
} }
if !reflect.DeepEqual(msg, newMsg) { if !reflect.DeepEqual(msg, newMsg) {
t.Fatalf("messages don't match after re-encoding: %v "+ t.Fatalf("messages don't match after re-encoding: %v "+
"vs %v", msg, newMsg) "vs %v", spew.Sdump(msg), spew.Sdump(newMsg))
return false return false
} }
@ -149,11 +149,11 @@ func TestLightningWireProtocol(t *testing.T) {
MsgOpenChannel: func(v []reflect.Value, r *rand.Rand) { MsgOpenChannel: func(v []reflect.Value, r *rand.Rand) {
req := OpenChannel{ req := OpenChannel{
FundingAmount: btcutil.Amount(r.Int63()), FundingAmount: btcutil.Amount(r.Int63()),
PushAmount: btcutil.Amount(r.Int63()), PushAmount: MilliSatoshi(r.Int63()),
DustLimit: btcutil.Amount(r.Int63()), DustLimit: btcutil.Amount(r.Int63()),
MaxValueInFlight: btcutil.Amount(r.Int63()), MaxValueInFlight: MilliSatoshi(r.Int63()),
ChannelReserve: btcutil.Amount(r.Int63()), ChannelReserve: btcutil.Amount(r.Int63()),
HtlcMinimum: uint32(r.Int31()), HtlcMinimum: MilliSatoshi(r.Int31()),
FeePerKiloWeight: uint32(r.Int63()), FeePerKiloWeight: uint32(r.Int63()),
CsvDelay: uint16(r.Int31()), CsvDelay: uint16(r.Int31()),
MaxAcceptedHTLCs: uint16(r.Int31()), MaxAcceptedHTLCs: uint16(r.Int31()),
@ -202,10 +202,10 @@ func TestLightningWireProtocol(t *testing.T) {
MsgAcceptChannel: func(v []reflect.Value, r *rand.Rand) { MsgAcceptChannel: func(v []reflect.Value, r *rand.Rand) {
req := AcceptChannel{ req := AcceptChannel{
DustLimit: btcutil.Amount(r.Int63()), DustLimit: btcutil.Amount(r.Int63()),
MaxValueInFlight: btcutil.Amount(r.Int63()), MaxValueInFlight: MilliSatoshi(r.Int63()),
ChannelReserve: btcutil.Amount(r.Int63()), ChannelReserve: btcutil.Amount(r.Int63()),
MinAcceptDepth: uint32(r.Int31()), MinAcceptDepth: uint32(r.Int31()),
HtlcMinimum: uint32(r.Int31()), HtlcMinimum: MilliSatoshi(r.Int31()),
CsvDelay: uint16(r.Int31()), CsvDelay: uint16(r.Int31()),
MaxAcceptedHTLCs: uint16(r.Int31()), MaxAcceptedHTLCs: uint16(r.Int31()),
} }
@ -412,7 +412,7 @@ func TestLightningWireProtocol(t *testing.T) {
Timestamp: uint32(r.Int31()), Timestamp: uint32(r.Int31()),
Flags: uint16(r.Int31()), Flags: uint16(r.Int31()),
TimeLockDelta: uint16(r.Int31()), TimeLockDelta: uint16(r.Int31()),
HtlcMinimumMsat: uint64(r.Int63()), HtlcMinimumMsat: MilliSatoshi(r.Int63()),
BaseFee: uint32(r.Int31()), BaseFee: uint32(r.Int31()),
FeeRate: uint32(r.Int31()), FeeRate: uint32(r.Int31()),
} }

@ -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. // NOTE: May only be returned by the intermediate nodes in the path.
type FailAmountBelowMinimum struct { type FailAmountBelowMinimum struct {
// HtlcMsat is the wrong amount of the incoming HTLC. // 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 // Update is used to update information about state of the channel
// caused the failure. // which caused the failure.
Update ChannelUpdate Update ChannelUpdate
} }
// NewAmountBelowMinimum creates new instance of the FailAmountBelowMinimum. // NewAmountBelowMinimum creates new instance of the FailAmountBelowMinimum.
func NewAmountBelowMinimum(htlcMsat btcutil.Amount, func NewAmountBelowMinimum(htlcMsat MilliSatoshi,
update ChannelUpdate) *FailAmountBelowMinimum { update ChannelUpdate) *FailAmountBelowMinimum {
return &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. // NOTE: May only be returned by intermediate nodes.
type FailFeeInsufficient struct { type FailFeeInsufficient struct {
// HtlcMsat is the wrong amount of the incoming HTLC. // 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 // Update is used to update information about state of the channel
// which caused the failure. // which caused the failure.
@ -520,7 +520,7 @@ type FailFeeInsufficient struct {
} }
// NewFeeInsufficient creates new instance of the FailFeeInsufficient. // NewFeeInsufficient creates new instance of the FailFeeInsufficient.
func NewFeeInsufficient(htlcMsat btcutil.Amount, func NewFeeInsufficient(htlcMsat MilliSatoshi,
update ChannelUpdate) *FailFeeInsufficient { update ChannelUpdate) *FailFeeInsufficient {
return &FailFeeInsufficient{ return &FailFeeInsufficient{
HtlcMsat: htlcMsat, 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. // NOTE: May only be returned by the final node.
type FailFinalIncorrectHtlcAmount struct { type FailFinalIncorrectHtlcAmount struct {
// IncomingHTLCAmount is the wrong forwarded htlc amount. // IncomingHTLCAmount is the wrong forwarded htlc amount.
IncomingHTLCAmount btcutil.Amount IncomingHTLCAmount MilliSatoshi
} }
// NewFinalIncorrectHtlcAmount creates new instance of the // NewFinalIncorrectHtlcAmount creates new instance of the
// FailFinalIncorrectHtlcAmount. // FailFinalIncorrectHtlcAmount.
func NewFinalIncorrectHtlcAmount(amount btcutil.Amount) *FailFinalIncorrectHtlcAmount { func NewFinalIncorrectHtlcAmount(amount MilliSatoshi) *FailFinalIncorrectHtlcAmount {
return &FailFinalIncorrectHtlcAmount{ return &FailFinalIncorrectHtlcAmount{
IncomingHTLCAmount: amount, IncomingHTLCAmount: amount,
} }

@ -4,13 +4,11 @@ import (
"bytes" "bytes"
"reflect" "reflect"
"testing" "testing"
"github.com/roasbeef/btcutil"
) )
var ( var (
testOnionHash = []byte{} testOnionHash = []byte{}
testAmount = btcutil.Amount(1) testAmount = MilliSatoshi(1)
testCtlvExpiry = uint32(2) testCtlvExpiry = uint32(2)
testFlags = uint16(2) testFlags = uint16(2)
testChannelUpdate = ChannelUpdate{ testChannelUpdate = ChannelUpdate{

@ -31,9 +31,7 @@ type OpenChannel struct {
// PushAmount is the value that the initiating party wishes to "push" // PushAmount is the value that the initiating party wishes to "push"
// to the responding as part of the first commitment state. If the // to the responding as part of the first commitment state. If the
// responder accepts, then this will be their initial balance. // responder accepts, then this will be their initial balance.
// PushAmount MilliSatoshi
// TODO(roasbeef): is msat
PushAmount btcutil.Amount
// DustLimit is the specific dust limit the sender of this message // DustLimit is the specific dust limit the sender of this message
// would like enforced on their version of the commitment transaction. // 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 // MaxValueInFlight represents the maximum amount of coins that can be
// pending within the channel at any given time. If the amount of funds // pending within the channel at any given time. If the amount of funds
// in limbo exceeds this amount, then the channel will be failed. // 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 // ChannelReserve is the amount of BTC that the receiving party MUST
// maintain a balance above at all times. This is a safety mechanism to // 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 // HtlcMinimum is the smallest HTLC that the sender of this message
// will accept. // will accept.
// HtlcMinimum MilliSatoshi
// TODO(roasbeef): is msat
HtlcMinimum uint32
// FeePerKiloWeight is the initial fee rate that the initiator suggests // FeePerKiloWeight is the initial fee rate that the initiator suggests
// for both commitment transaction. This value is expressed in sat per // 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. // This is part of the lnwire.Message interface.
func (o *OpenChannel) MaxPayloadLength(uint32) uint32 { func (o *OpenChannel) MaxPayloadLength(uint32) uint32 {
// (32 * 2) + (8 * 5) + (4 * 2) + (2 * 2) + (33 * 5) + 1 // (32 * 2) + (8 * 6) + (4 * 1) + (2 * 2) + (33 * 5) + 1
return 282 return 286
} }

@ -1,10 +1,6 @@
package lnwire package lnwire
import ( import "io"
"io"
"github.com/roasbeef/btcutil"
)
// OnionPacketSize is the size of the serialized Sphinx onion packet included // OnionPacketSize is the size of the serialized Sphinx onion packet included
// in each UpdateAddHTLC message. The breakdown of the onion packet is as // 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. // sufficient expiry value to allow her to redeem the incoming HTLC.
Expiry uint32 Expiry uint32
// Amount is the amount of satoshis this HTLC is worth. // Amount is the amount of millisatoshis this HTLC is worth.
Amount btcutil.Amount Amount MilliSatoshi
// PaymentHash is the payment hash to be included in the HTLC this // 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 // request creates. The pre-image to this HTLC must be revelaed by the