d884efea29
This commit modifies the login of sent/recv’d wire messages in trace mode in order utilize the more detailed, and automatically generated logging statements using pure spew.Sdump. In order to avoid the spammy messages due to spew printing the btcec.S256() curve paramter within wire messages with public keys, we introduce a new logging function to unset the curve paramter to it isn’t printed in its entirety. To insure we don’t run into any panics as a result of a nil pointer defense, we now copy the public keys during the funding process so we don’t run into a panic due to modifying a pointer to the same object.
175 lines
4.2 KiB
Go
175 lines
4.2 KiB
Go
package lnwire
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"io"
|
|
|
|
"github.com/roasbeef/btcd/btcec"
|
|
)
|
|
|
|
// ChannelUpdateAnnouncement message is used after channel has been initially
|
|
// announced. Each side independently announces its fees and minimum expiry for
|
|
// HTLCs and other parameters. Also this message is used to redeclare initially
|
|
// setted channel parameters.
|
|
type ChannelUpdateAnnouncement struct {
|
|
// Signature is used to validate the announced data and prove the
|
|
// ownership of node id.
|
|
Signature *btcec.Signature
|
|
|
|
// ChannelID is the unique description of the funding transaction.
|
|
ChannelID ChannelID
|
|
|
|
// Timestamp allows ordering in the case of multiple announcements.
|
|
// We should ignore the message if timestamp is not greater than
|
|
// the last-received.
|
|
Timestamp uint32
|
|
|
|
// Flags least-significant bit must be set to 0 if the creating node
|
|
// corresponds to the first node in previously sent channel
|
|
// announcement and 1 otherwise.
|
|
Flags uint16
|
|
|
|
// Expiry is the minimum number of blocks this node requires to be
|
|
// added to the expiry of HTLCs. This is a security parameter determined
|
|
// by the node operator.
|
|
Expiry uint16
|
|
|
|
// HtlcMinimumMstat is the minimum HTLC value which will be accepted.
|
|
HtlcMinimumMstat uint32
|
|
|
|
// FeeBaseMstat...
|
|
FeeBaseMstat uint32
|
|
|
|
// FeeProportionalMillionths...
|
|
FeeProportionalMillionths uint32
|
|
}
|
|
|
|
// A compile time check to ensure ChannelUpdateAnnouncement implements the
|
|
// lnwire.Message interface.
|
|
var _ Message = (*ChannelUpdateAnnouncement)(nil)
|
|
|
|
// Validate performs any necessary sanity checks to ensure all fields present
|
|
// on the ChannelUpdateAnnouncement are valid.
|
|
//
|
|
// This is part of the lnwire.Message interface.
|
|
func (a *ChannelUpdateAnnouncement) Validate() error {
|
|
// NOTE: As far as we don't have the node id (public key) in this
|
|
// message, we can't validate the signature on this stage, it should
|
|
// be validated latter - in discovery service handler.
|
|
|
|
if a.Expiry == 0 {
|
|
return errors.New("expiry should be greater then zero")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Decode deserializes a serialized ChannelUpdateAnnouncement stored in the
|
|
// passed io.Reader observing the specified protocol version.
|
|
//
|
|
// This is part of the lnwire.Message interface.
|
|
func (c *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error {
|
|
err := readElements(r,
|
|
&c.Signature,
|
|
&c.ChannelID,
|
|
&c.Timestamp,
|
|
&c.Flags,
|
|
&c.Expiry,
|
|
&c.HtlcMinimumMstat,
|
|
&c.FeeBaseMstat,
|
|
&c.FeeProportionalMillionths,
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Encode serializes the target ChannelUpdateAnnouncement into the passed
|
|
// io.Writer observing the protocol version specified.
|
|
//
|
|
// This is part of the lnwire.Message interface.
|
|
func (c *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error {
|
|
err := writeElements(w,
|
|
c.Signature,
|
|
c.ChannelID,
|
|
c.Timestamp,
|
|
c.Flags,
|
|
c.Expiry,
|
|
c.HtlcMinimumMstat,
|
|
c.FeeBaseMstat,
|
|
c.FeeProportionalMillionths,
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Command returns the integer uniquely identifying this message type on the
|
|
// wire.
|
|
//
|
|
// This is part of the lnwire.Message interface.
|
|
func (c *ChannelUpdateAnnouncement) Command() uint32 {
|
|
return CmdChannelUpdateAnnoucmentMessage
|
|
}
|
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for this message
|
|
// observing the specified protocol version.
|
|
//
|
|
// This is part of the lnwire.Message interface.
|
|
func (c *ChannelUpdateAnnouncement) MaxPayloadLength(pver uint32) uint32 {
|
|
var length uint32
|
|
|
|
// Signature - 64 bytes
|
|
length += 64
|
|
|
|
// ChannelID - 8 bytes
|
|
length += 8
|
|
|
|
// Timestamp - 4 bytes
|
|
length += 4
|
|
|
|
// Flags - 2 bytes
|
|
length += 2
|
|
|
|
// Expiry - 2 bytes
|
|
length += 2
|
|
|
|
// HtlcMinimumMstat - 4 bytes
|
|
length += 4
|
|
|
|
// FeeBaseMstat - 4 bytes
|
|
length += 4
|
|
|
|
// FeeProportionalMillionths - 4 bytes
|
|
length += 4
|
|
|
|
return length
|
|
}
|
|
|
|
// DataToSign is used to retrieve part of the announcement message which
|
|
// should be signed.
|
|
func (c *ChannelUpdateAnnouncement) DataToSign() ([]byte, error) {
|
|
|
|
// We should not include the signatures itself.
|
|
var w bytes.Buffer
|
|
err := writeElements(&w,
|
|
c.ChannelID,
|
|
c.Timestamp,
|
|
c.Flags,
|
|
c.Expiry,
|
|
c.HtlcMinimumMstat,
|
|
c.FeeBaseMstat,
|
|
c.FeeProportionalMillionths,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return w.Bytes(), nil
|
|
}
|