multi: partition lnwire.ChanUpdateFlag into ChannelFlags and MessageFlags

In this commit:

* we partition lnwire.ChanUpdateFlag into two (ChanUpdateChanFlags and
ChanUpdateMsgFlags), from a uint16 to a pair of uint8's

* we rename the ChannelUpdate.Flags to ChannelFlags and add an
additional MessageFlags field, which will be used to indicate the
presence of the optional field HtlcMaximumMsat within the ChannelUpdate.

* we partition ChannelEdgePolicy.Flags into message and channel flags.
This change corresponds to the partitioning of the ChannelUpdate's Flags
field into MessageFlags and ChannelFlags.

Co-authored-by: Johan T. Halseth <johanth@gmail.com>
This commit is contained in:
Valentine Wallace
2019-01-12 18:59:43 +01:00
committed by Johan T. Halseth
parent 375be936ce
commit 0fd6004958
21 changed files with 176 additions and 113 deletions

View File

@@ -8,16 +8,20 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
)
// ChanUpdateFlag is a bitfield that signals various options concerning a
// ChanUpdateMsgFlags is a bitfield that signals whether optional fields are
// present in the ChannelUpdate.
type ChanUpdateMsgFlags uint8
// ChanUpdateChanFlags is a bitfield that signals various options concerning a
// particular channel edge. Each bit is to be examined in order to determine
// how the ChannelUpdate message is to be interpreted.
type ChanUpdateFlag uint16
type ChanUpdateChanFlags uint8
const (
// ChanUpdateDirection indicates the direction of a channel update. If
// this bit is set to 0 if Node1 (the node with the "smaller" Node ID)
// is updating the channel, and to 1 otherwise.
ChanUpdateDirection ChanUpdateFlag = 1 << iota
ChanUpdateDirection ChanUpdateChanFlags = 1 << iota
// ChanUpdateDisabled is a bit that indicates if the channel edge
// selected by the ChanUpdateDirection bit is to be treated as being
@@ -48,13 +52,18 @@ type ChannelUpdate struct {
// the last-received.
Timestamp uint32
// Flags is a bitfield that describes additional meta-data concerning
// how the update is to be interpreted. Currently, the
// MessageFlags is a bitfield that describes whether optional fields
// are present in this update. Currently, the least-significant bit
// must be set to 1 if the optional field MaxHtlc is present.
MessageFlags ChanUpdateMsgFlags
// ChannelFlags is a bitfield that describes additional meta-data
// concerning how the update is to be interpreted. Currently, the
// least-significant bit must be set to 0 if the creating node
// corresponds to the first node in the previously sent channel
// announcement and 1 otherwise. If the second bit is set, then the
// channel is set to be disabled.
Flags ChanUpdateFlag
ChannelFlags ChanUpdateChanFlags
// TimeLockDelta is the minimum number of blocks this node requires to
// be added to the expiry of HTLCs. This is a security parameter
@@ -98,7 +107,8 @@ func (a *ChannelUpdate) Decode(r io.Reader, pver uint32) error {
a.ChainHash[:],
&a.ShortChannelID,
&a.Timestamp,
&a.Flags,
&a.MessageFlags,
&a.ChannelFlags,
&a.TimeLockDelta,
&a.HtlcMinimumMsat,
&a.BaseFee,
@@ -133,7 +143,8 @@ func (a *ChannelUpdate) Encode(w io.Writer, pver uint32) error {
a.ChainHash[:],
a.ShortChannelID,
a.Timestamp,
a.Flags,
a.MessageFlags,
a.ChannelFlags,
a.TimeLockDelta,
a.HtlcMinimumMsat,
a.BaseFee,
@@ -168,7 +179,8 @@ func (a *ChannelUpdate) DataToSign() ([]byte, error) {
a.ChainHash[:],
a.ShortChannelID,
a.Timestamp,
a.Flags,
a.MessageFlags,
a.ChannelFlags,
a.TimeLockDelta,
a.HtlcMinimumMsat,
a.BaseFee,