From a3836d52413e6e2a83b3409b93cb7c3b9539a65a Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Fri, 14 Jul 2017 20:28:40 +0200 Subject: [PATCH] lnwire: add update_fee message type. --- lnwire/lnwire_test.go | 6 ++++ lnwire/message.go | 3 ++ lnwire/update_fee.go | 69 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 lnwire/update_fee.go diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index b171bf8e..ebfefcfc 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -523,6 +523,12 @@ func TestLightningWireProtocol(t *testing.T) { return mainScenario(&m) }, }, + { + msgType: MsgUpdateFee, + scenario: func(m UpdateFee) bool { + return mainScenario(&m) + }, + }, { msgType: MsgChannelAnnouncement, scenario: func(m ChannelAnnouncement) bool { diff --git a/lnwire/message.go b/lnwire/message.go index e58384c9..f92705d9 100644 --- a/lnwire/message.go +++ b/lnwire/message.go @@ -39,6 +39,7 @@ const ( MsgUpdateFailHTLC = 131 MsgCommitSig = 132 MsgRevokeAndAck = 133 + MsgUpdateFee = 137 MsgChannelAnnouncement = 256 MsgNodeAnnouncement = 257 MsgChannelUpdate = 258 @@ -149,6 +150,8 @@ func makeEmptyMessage(msgType MessageType) (Message, error) { msg = &CommitSig{} case MsgRevokeAndAck: msg = &RevokeAndAck{} + case MsgUpdateFee: + msg = &UpdateFee{} case MsgError: msg = &Error{} case MsgChannelAnnouncement: diff --git a/lnwire/update_fee.go b/lnwire/update_fee.go new file mode 100644 index 00000000..cbf21b61 --- /dev/null +++ b/lnwire/update_fee.go @@ -0,0 +1,69 @@ +package lnwire + +import ( + "io" + + "github.com/roasbeef/btcutil" +) + +// UpdateFee is the message the channel initiator sends to the other peer if +// the channel commitment fee needs to be updated. +type UpdateFee struct { + // ChanID is the channel that this UpdateFee is meant for. + ChanID ChannelID + + // FeePerKw is the fee-per-kw on commit transactions that the sender of + // this message wants to use for this channel. + FeePerKw btcutil.Amount +} + +// NewUpdateFee creates a new UpdateFee message. +func NewUpdateFee(chanID ChannelID, feePerKw btcutil.Amount) *UpdateFee { + return &UpdateFee{ + ChanID: chanID, + FeePerKw: feePerKw, + } +} + +// A compile time check to ensure UpdateFee implements the lnwire.Message +// interface. +var _ Message = (*UpdateFee)(nil) + +// Decode deserializes a serialized UpdateFee message stored in the +// passed io.Reader observing the specified protocol version. +// +// This is part of the lnwire.Message interface. +func (c *UpdateFee) Decode(r io.Reader, pver uint32) error { + return readElements(r, + &c.ChanID, + &c.FeePerKw, + ) +} + +// Encode serializes the target UpdateFee into the passed io.Writer +// observing the protocol version specified. +// +// This is part of the lnwire.Message interface. +func (c *UpdateFee) Encode(w io.Writer, pver uint32) error { + return writeElements(w, + c.ChanID, + c.FeePerKw, + ) +} + +// MsgType returns the integer uniquely identifying this message type on the +// wire. +// +// This is part of the lnwire.Message interface. +func (c *UpdateFee) MsgType() MessageType { + return MsgUpdateFee +} + +// MaxPayloadLength returns the maximum allowed payload size for a +// UpdateFee complete message observing the specified protocol version. +// +// This is part of the lnwire.Message interface. +func (c *UpdateFee) MaxPayloadLength(uint32) uint32 { + // 32 + 8 + return 40 +}