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 WallaceandJohan T. Halseth authored and Johan T. Halseth committed 2019-01-22 08:42:26 +01:00
1 parent 375be936ce
commit 0fd6004958
21 files changed
+176 -113

No files matched your search

+21 -9
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,
+19 -7
View File
@@ -105,9 +105,15 @@ func WriteElement(w io.Writer, element interface{}) error {
if _, err := w.Write(b[:]); err != nil {
return err
}
case ChanUpdateFlag:
var b [2]byte
binary.BigEndian.PutUint16(b[:], uint16(e))
case ChanUpdateMsgFlags:
var b [1]byte
b[0] = uint8(e)
if _, err := w.Write(b[:]); err != nil {
return err
}
case ChanUpdateChanFlags:
var b [1]byte
b[0] = uint8(e)
if _, err := w.Write(b[:]); err != nil {
return err
}
@@ -470,12 +476,18 @@ func ReadElement(r io.Reader, element interface{}) error {
return err
}
*e = binary.BigEndian.Uint16(b[:])
case *ChanUpdateFlag:
var b [2]byte
if _, err := io.ReadFull(r, b[:]); err != nil {
case *ChanUpdateMsgFlags:
var b [1]uint8
if _, err := r.Read(b[:]); err != nil {
return err
}
*e = ChanUpdateFlag(binary.BigEndian.Uint16(b[:]))
*e = ChanUpdateMsgFlags(b[0])
case *ChanUpdateChanFlags:
var b [1]uint8
if _, err := r.Read(b[:]); err != nil {
return err
}
*e = ChanUpdateChanFlags(b[0])
case *ErrorCode:
var b [2]byte
if _, err := io.ReadFull(r, b[:]); err != nil {
+2 -1
View File
@@ -608,7 +608,8 @@ func TestLightningWireProtocol(t *testing.T) {
req := ChannelUpdate{
ShortChannelID: NewShortChanIDFromInt(uint64(r.Int63())),
Timestamp: uint32(r.Int31()),
Flags: ChanUpdateFlag(r.Int31()),
MessageFlags: ChanUpdateMsgFlags(r.Int31()),
ChannelFlags: ChanUpdateChanFlags(r.Int31()),
TimeLockDelta: uint16(r.Int31()),
HtlcMinimumMsat: MilliSatoshi(r.Int63()),
BaseFee: uint32(r.Int31()),
+2 -1
View File
@@ -20,7 +20,8 @@ var (
Signature: sig,
ShortChannelID: NewShortChanIDFromInt(1),
Timestamp: 1,
Flags: 1,
MessageFlags: 0,
ChannelFlags: 1,
}
)