diff --git a/lnwire/channel_update.go b/lnwire/channel_update.go index 6d70f32c4..f43f11ef2 100644 --- a/lnwire/channel_update.go +++ b/lnwire/channel_update.go @@ -8,6 +8,23 @@ import ( "github.com/roasbeef/btcd/chaincfg/chainhash" ) +// ChanUpdateFlag is a btifield 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 + +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 + + // ChanUpdateDisabled is a bit that indicates if the channel edge + // selected by the ChanUpdateDirection bit is to be treated as being + // disabled. + ChanUpdateDisabled +) + // ChannelUpdate 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 @@ -31,10 +48,13 @@ type ChannelUpdate struct { // the last-received. Timestamp uint32 - // Flags least-significant bit must be set to 0 if the creating node + // Flags 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. - Flags uint16 + // announcement and 1 otherwise. If the second bit is set, then the + // channel is set to be disabled. + Flags ChanUpdateFlag // TimeLockDelta is the minimum number of blocks this node requires to // be added to the expiry of HTLCs. This is a security parameter diff --git a/lnwire/lnwire.go b/lnwire/lnwire.go index 705ab358c..ce9ead460 100644 --- a/lnwire/lnwire.go +++ b/lnwire/lnwire.go @@ -98,6 +98,12 @@ 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)) + if _, err := w.Write(b[:]); err != nil { + return err + } case ErrorCode: var b [2]byte binary.BigEndian.PutUint16(b[:], uint16(e)) @@ -406,6 +412,12 @@ 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 { + return err + } + *e = ChanUpdateFlag(binary.BigEndian.Uint16(b[:])) case *ErrorCode: var b [2]byte if _, err := io.ReadFull(r, b[:]); err != nil { diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index 021181ad4..f78e2c4d1 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -427,7 +427,7 @@ func TestLightningWireProtocol(t *testing.T) { Signature: testSig, ShortChannelID: NewShortChanIDFromInt(uint64(r.Int63())), Timestamp: uint32(r.Int31()), - Flags: uint16(r.Int31()), + Flags: ChanUpdateFlag(r.Int31()), TimeLockDelta: uint16(r.Int31()), HtlcMinimumMsat: MilliSatoshi(r.Int63()), BaseFee: uint32(r.Int31()),