lnwire: add new ChanUpdateFlag for the ChannelUpdate flag bitmask
In this commit, we add a new type to the lnwire package: ChanUpdateFlag. This type represent the bitfield that’s used within the ChannelUpdate message to give additional details as how the message should be interpreted.
This commit is contained in:
parent
c3ec32e67b
commit
5e3dbfcd78
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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()),
|
||||
|
Loading…
Reference in New Issue
Block a user