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
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
21 changed files with 176 additions and 113 deletions

View File

@ -229,7 +229,8 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
MinHTLC: 1,
FeeBaseMSat: 10,
FeeProportionalMillionths: 10000,
Flags: 0,
MessageFlags: 0,
ChannelFlags: 0,
}
if err := d.db.UpdateEdgePolicy(edgePolicy); err != nil {
@ -243,7 +244,8 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
MinHTLC: 1,
FeeBaseMSat: 10,
FeeProportionalMillionths: 10000,
Flags: 1,
MessageFlags: 0,
ChannelFlags: 1,
}
if err := d.db.UpdateEdgePolicy(edgePolicy); err != nil {
return nil, nil, err

View File

@ -1677,7 +1677,7 @@ func updateEdgePolicy(edges, edgeIndex, nodes *bbolt.Bucket,
// Depending on the flags value passed above, either the first
// or second edge policy is being updated.
var fromNode, toNode []byte
if edge.Flags&lnwire.ChanUpdateDirection == 0 {
if edge.ChannelFlags&lnwire.ChanUpdateDirection == 0 {
fromNode = nodeInfo[:33]
toNode = nodeInfo[33:66]
} else {
@ -2422,9 +2422,13 @@ type ChannelEdgePolicy struct {
// was received.
LastUpdate time.Time
// Flags is a bitfield which signals the capabilities of the channel as
// well as the directed edge this update applies to.
Flags lnwire.ChanUpdateFlag
// MessageFlags is a bitfield which indicates the presence of optional
// fields (like max_htlc) in the policy.
MessageFlags lnwire.ChanUpdateMsgFlags
// ChannelFlags is a bitfield which signals the capabilities of the
// channel as well as the directed edge this update applies to.
ChannelFlags lnwire.ChanUpdateChanFlags
// TimeLockDelta is the number of blocks this node will subtract from
// the expiry of an incoming HTLC. This value expresses the time buffer
@ -3186,7 +3190,10 @@ func putChanEdgePolicy(edges, nodes *bbolt.Bucket, edge *ChannelEdgePolicy,
return err
}
if err := binary.Write(&b, byteOrder, edge.Flags); err != nil {
if err := binary.Write(&b, byteOrder, edge.MessageFlags); err != nil {
return err
}
if err := binary.Write(&b, byteOrder, edge.ChannelFlags); err != nil {
return err
}
if err := binary.Write(&b, byteOrder, edge.TimeLockDelta); err != nil {
@ -3363,7 +3370,10 @@ func deserializeChanEdgePolicy(r io.Reader,
unix := int64(byteOrder.Uint64(scratch[:]))
edge.LastUpdate = time.Unix(unix, 0)
if err := binary.Read(r, byteOrder, &edge.Flags); err != nil {
if err := binary.Read(r, byteOrder, &edge.MessageFlags); err != nil {
return nil, err
}
if err := binary.Read(r, byteOrder, &edge.ChannelFlags); err != nil {
return nil, err
}
if err := binary.Read(r, byteOrder, &edge.TimeLockDelta); err != nil {

View File

@ -699,7 +699,8 @@ func TestEdgeInfoUpdates(t *testing.T) {
SigBytes: testSig.Serialize(),
ChannelID: chanID,
LastUpdate: time.Unix(433453, 0),
Flags: 0,
MessageFlags: 0,
ChannelFlags: 0,
TimeLockDelta: 99,
MinHTLC: 2342135,
FeeBaseMSat: 4352345,
@ -712,7 +713,8 @@ func TestEdgeInfoUpdates(t *testing.T) {
SigBytes: testSig.Serialize(),
ChannelID: chanID,
LastUpdate: time.Unix(124234, 0),
Flags: 1,
MessageFlags: 0,
ChannelFlags: 1,
TimeLockDelta: 99,
MinHTLC: 2342135,
FeeBaseMSat: 4352345,
@ -792,6 +794,8 @@ func newEdgePolicy(chanID uint64, op wire.OutPoint, db *DB,
return &ChannelEdgePolicy{
ChannelID: chanID,
LastUpdate: time.Unix(updateTime, 0),
MessageFlags: 0,
ChannelFlags: 0,
TimeLockDelta: uint16(prand.Int63()),
MinHTLC: lnwire.MilliSatoshi(prand.Int63()),
FeeBaseMSat: lnwire.MilliSatoshi(prand.Int63()),
@ -894,7 +898,7 @@ func TestGraphTraversal(t *testing.T) {
// Create and add an edge with random data that points from
// node1 -> node2.
edge := randEdgePolicy(chanID, op, db)
edge.Flags = 0
edge.ChannelFlags = 0
edge.Node = secondNode
edge.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge); err != nil {
@ -904,7 +908,7 @@ func TestGraphTraversal(t *testing.T) {
// Create another random edge that points from node2 -> node1
// this time.
edge = randEdgePolicy(chanID, op, db)
edge.Flags = 1
edge.ChannelFlags = 1
edge.Node = firstNode
edge.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge); err != nil {
@ -1145,7 +1149,7 @@ func TestGraphPruning(t *testing.T) {
// Create and add an edge with random data that points from
// node_i -> node_i+1
edge := randEdgePolicy(chanID, op, db)
edge.Flags = 0
edge.ChannelFlags = 0
edge.Node = graphNodes[i]
edge.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge); err != nil {
@ -1155,7 +1159,7 @@ func TestGraphPruning(t *testing.T) {
// Create another random edge that points from node_i+1 ->
// node_i this time.
edge = randEdgePolicy(chanID, op, db)
edge.Flags = 1
edge.ChannelFlags = 1
edge.Node = graphNodes[i]
edge.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge); err != nil {
@ -1414,7 +1418,7 @@ func TestChanUpdatesInHorizon(t *testing.T) {
edge1 := newEdgePolicy(
chanID.ToUint64(), op, db, edge1UpdateTime.Unix(),
)
edge1.Flags = 0
edge1.ChannelFlags = 0
edge1.Node = node2
edge1.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge1); err != nil {
@ -1424,7 +1428,7 @@ func TestChanUpdatesInHorizon(t *testing.T) {
edge2 := newEdgePolicy(
chanID.ToUint64(), op, db, edge2UpdateTime.Unix(),
)
edge2.Flags = 1
edge2.ChannelFlags = 1
edge2.Node = node1
edge2.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge2); err != nil {
@ -1915,7 +1919,7 @@ func TestFetchChanInfos(t *testing.T) {
edge1 := newEdgePolicy(
chanID.ToUint64(), op, db, updateTime.Unix(),
)
edge1.Flags = 0
edge1.ChannelFlags = 0
edge1.Node = node2
edge1.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge1); err != nil {
@ -1925,7 +1929,7 @@ func TestFetchChanInfos(t *testing.T) {
edge2 := newEdgePolicy(
chanID.ToUint64(), op, db, updateTime.Unix(),
)
edge2.Flags = 1
edge2.ChannelFlags = 1
edge2.Node = node1
edge2.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge2); err != nil {
@ -2053,7 +2057,7 @@ func TestIncompleteChannelPolicies(t *testing.T) {
edgePolicy := newEdgePolicy(
chanID.ToUint64(), op, db, updateTime.Unix(),
)
edgePolicy.Flags = 0
edgePolicy.ChannelFlags = 0
edgePolicy.Node = node2
edgePolicy.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
@ -2068,7 +2072,7 @@ func TestIncompleteChannelPolicies(t *testing.T) {
edgePolicy = newEdgePolicy(
chanID.ToUint64(), op, db, updateTime.Unix(),
)
edgePolicy.Flags = 1
edgePolicy.ChannelFlags = 1
edgePolicy.Node = node1
edgePolicy.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
@ -2125,7 +2129,7 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) {
}
edge1 := randEdgePolicy(chanID.ToUint64(), edgeInfo.ChannelPoint, db)
edge1.Flags = 0
edge1.ChannelFlags = 0
edge1.Node = node1
edge1.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge1); err != nil {
@ -2133,7 +2137,7 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) {
}
edge2 := randEdgePolicy(chanID.ToUint64(), edgeInfo.ChannelPoint, db)
edge2.Flags = 1
edge2.ChannelFlags = 1
edge2.Node = node2
edge2.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge2); err != nil {
@ -2190,12 +2194,12 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) {
// Now, we'll update the edge policies to ensure the old timestamps are
// removed from the update index.
edge1.Flags = 2
edge1.ChannelFlags = 2
edge1.LastUpdate = time.Now()
if err := graph.UpdateEdgePolicy(edge1); err != nil {
t.Fatalf("unable to update edge: %v", err)
}
edge2.Flags = 3
edge2.ChannelFlags = 3
edge2.LastUpdate = edge1.LastUpdate.Add(time.Hour)
if err := graph.UpdateEdgePolicy(edge2); err != nil {
t.Fatalf("unable to update edge: %v", err)
@ -2282,7 +2286,7 @@ func TestPruneGraphNodes(t *testing.T) {
// We'll now insert an advertised edge, but it'll only be the edge that
// points from the first to the second node.
edge1 := randEdgePolicy(chanID.ToUint64(), edgeInfo.ChannelPoint, db)
edge1.Flags = 0
edge1.ChannelFlags = 0
edge1.Node = node1
edge1.SigBytes = testSig.Serialize()
if err := graph.UpdateEdgePolicy(edge1); err != nil {
@ -2645,9 +2649,13 @@ func compareEdgePolicies(a, b *ChannelEdgePolicy) error {
return fmt.Errorf("edge LastUpdate doesn't match: expected %#v, \n "+
"got %#v", a.LastUpdate, b.LastUpdate)
}
if a.Flags != b.Flags {
return fmt.Errorf("Flags doesn't match: expected %v, "+
"got %v", a.Flags, b.Flags)
if a.MessageFlags != b.MessageFlags {
return fmt.Errorf("MessageFlags doesn't match: expected %v, "+
"got %v", a.MessageFlags, b.MessageFlags)
}
if a.ChannelFlags != b.ChannelFlags {
return fmt.Errorf("ChannelFlags doesn't match: expected %v, "+
"got %v", a.ChannelFlags, b.ChannelFlags)
}
if a.TimeLockDelta != b.TimeLockDelta {
return fmt.Errorf("TimeLockDelta doesn't match: expected %v, "+

View File

@ -327,7 +327,8 @@ func (c *ChanSeries) FetchChanUpdates(chain chainhash.Hash,
ChainHash: chanInfo.ChainHash,
ShortChannelID: shortChanID,
Timestamp: uint32(e1.LastUpdate.Unix()),
Flags: e1.Flags,
MessageFlags: e1.MessageFlags,
ChannelFlags: e1.ChannelFlags,
TimeLockDelta: e1.TimeLockDelta,
HtlcMinimumMsat: e1.MinHTLC,
BaseFee: uint32(e1.FeeBaseMSat),
@ -346,7 +347,8 @@ func (c *ChanSeries) FetchChanUpdates(chain chainhash.Hash,
ChainHash: chanInfo.ChainHash,
ShortChannelID: shortChanID,
Timestamp: uint32(e2.LastUpdate.Unix()),
Flags: e2.Flags,
MessageFlags: e2.MessageFlags,
ChannelFlags: e2.ChannelFlags,
TimeLockDelta: e2.TimeLockDelta,
HtlcMinimumMsat: e2.MinHTLC,
BaseFee: uint32(e2.FeeBaseMSat),

View File

@ -560,7 +560,7 @@ func (d *AuthenticatedGossiper) ProcessLocalAnnouncement(msg lnwire.Message,
}
// channelUpdateID is a unique identifier for ChannelUpdate messages, as
// channel updates can be identified by the (ShortChannelID, Flags)
// channel updates can be identified by the (ShortChannelID, ChannelFlags)
// tuple.
type channelUpdateID struct {
// channelID represents the set of data which is needed to
@ -570,7 +570,7 @@ type channelUpdateID struct {
// Flags 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 lnwire.ChanUpdateFlag
flags lnwire.ChanUpdateChanFlags
}
// msgWithSenders is a wrapper struct around a message, and the set of peers
@ -669,13 +669,13 @@ func (d *deDupedAnnouncements) addMsg(message networkMsg) {
mws.senders[sender] = struct{}{}
d.channelAnnouncements[deDupKey] = mws
// Channel updates are identified by the (short channel id, flags)
// tuple.
// Channel updates are identified by the (short channel id,
// channelflags) tuple.
case *lnwire.ChannelUpdate:
sender := routing.NewVertex(message.source)
deDupKey := channelUpdateID{
msg.ShortChannelID,
msg.Flags,
msg.ChannelFlags,
}
oldTimestamp := uint32(0)
@ -1911,7 +1911,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
// announcement for this edge.
timestamp := time.Unix(int64(msg.Timestamp), 0)
if d.cfg.Router.IsStaleEdgePolicy(
msg.ShortChannelID, timestamp, msg.Flags,
msg.ShortChannelID, timestamp, msg.ChannelFlags,
) {
nMsg.err <- nil
@ -1986,9 +1986,9 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
// edge is being updated.
var pubKey *btcec.PublicKey
switch {
case msg.Flags&lnwire.ChanUpdateDirection == 0:
case msg.ChannelFlags&lnwire.ChanUpdateDirection == 0:
pubKey, _ = chanInfo.NodeKey1()
case msg.Flags&lnwire.ChanUpdateDirection == 1:
case msg.ChannelFlags&lnwire.ChanUpdateDirection == 1:
pubKey, _ = chanInfo.NodeKey2()
}
@ -2009,7 +2009,8 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
SigBytes: msg.Signature.ToSignatureBytes(),
ChannelID: shortChanID,
LastUpdate: timestamp,
Flags: msg.Flags,
MessageFlags: msg.MessageFlags,
ChannelFlags: msg.ChannelFlags,
TimeLockDelta: msg.TimeLockDelta,
MinHTLC: msg.HtlcMinimumMsat,
FeeBaseMSat: lnwire.MilliSatoshi(msg.BaseFee),
@ -2041,9 +2042,9 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
// Get our peer's public key.
var remotePub *btcec.PublicKey
switch {
case msg.Flags&lnwire.ChanUpdateDirection == 0:
case msg.ChannelFlags&lnwire.ChanUpdateDirection == 0:
remotePub, _ = chanInfo.NodeKey2()
case msg.Flags&lnwire.ChanUpdateDirection == 1:
case msg.ChannelFlags&lnwire.ChanUpdateDirection == 1:
remotePub, _ = chanInfo.NodeKey1()
}
@ -2517,7 +2518,8 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo,
ChainHash: info.ChainHash,
ShortChannelID: lnwire.NewShortChanIDFromInt(edge.ChannelID),
Timestamp: uint32(timestamp),
Flags: edge.Flags,
MessageFlags: edge.MessageFlags,
ChannelFlags: edge.ChannelFlags,
TimeLockDelta: edge.TimeLockDelta,
HtlcMinimumMsat: edge.MinHTLC,
BaseFee: uint32(edge.FeeBaseMSat),

View File

@ -258,7 +258,7 @@ func (r *mockGraphSource) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
// IsStaleEdgePolicy returns true if the graph source has a channel edge for
// the passed channel ID (and flags) that have a more recent timestamp.
func (r *mockGraphSource) IsStaleEdgePolicy(chanID lnwire.ShortChannelID,
timestamp time.Time, flags lnwire.ChanUpdateFlag) bool {
timestamp time.Time, flags lnwire.ChanUpdateChanFlags) bool {
edges, ok := r.edges[chanID.ToUint64()]
if !ok {
@ -267,10 +267,10 @@ func (r *mockGraphSource) IsStaleEdgePolicy(chanID lnwire.ShortChannelID,
switch {
case len(edges) >= 1 && edges[0].Flags == flags:
case len(edges) >= 1 && edges[0].ChannelFlags == flags:
return !edges[0].LastUpdate.Before(timestamp)
case len(edges) >= 2 && edges[1].Flags == flags:
case len(edges) >= 2 && edges[1].ChannelFlags == flags:
return !edges[1].LastUpdate.Before(timestamp)
default:
@ -440,7 +440,8 @@ func createNodeAnnouncement(priv *btcec.PrivateKey,
return a, nil
}
func createUpdateAnnouncement(blockHeight uint32, flags lnwire.ChanUpdateFlag,
func createUpdateAnnouncement(blockHeight uint32,
flags lnwire.ChanUpdateChanFlags,
nodeKey *btcec.PrivateKey, timestamp uint32,
extraBytes ...[]byte) (*lnwire.ChannelUpdate, error) {
@ -451,8 +452,9 @@ func createUpdateAnnouncement(blockHeight uint32, flags lnwire.ChanUpdateFlag,
BlockHeight: blockHeight,
},
Timestamp: timestamp,
MessageFlags: 0,
ChannelFlags: flags,
TimeLockDelta: uint16(prand.Int63()),
Flags: flags,
HtlcMinimumMsat: lnwire.MilliSatoshi(prand.Int63()),
FeeRate: uint32(prand.Int31()),
BaseFee: uint32(prand.Int31()),
@ -2028,7 +2030,7 @@ func TestDeDuplicatedAnnouncements(t *testing.T) {
assertChannelUpdate := func(channelUpdate *lnwire.ChannelUpdate) {
channelKey := channelUpdateID{
ua3.ShortChannelID,
ua3.Flags,
ua3.ChannelFlags,
}
mws, ok := announcements.channelUpdates[channelKey]

View File

@ -72,7 +72,8 @@ func CreateChanAnnouncement(chanProof *channeldb.ChannelAuthProof,
ChainHash: chanInfo.ChainHash,
ShortChannelID: chanID,
Timestamp: uint32(e1.LastUpdate.Unix()),
Flags: e1.Flags,
MessageFlags: e1.MessageFlags,
ChannelFlags: e1.ChannelFlags,
TimeLockDelta: e1.TimeLockDelta,
HtlcMinimumMsat: e1.MinHTLC,
BaseFee: uint32(e1.FeeBaseMSat),
@ -89,7 +90,8 @@ func CreateChanAnnouncement(chanProof *channeldb.ChannelAuthProof,
ChainHash: chanInfo.ChainHash,
ShortChannelID: chanID,
Timestamp: uint32(e2.LastUpdate.Unix()),
Flags: e2.Flags,
MessageFlags: e2.MessageFlags,
ChannelFlags: e2.ChannelFlags,
TimeLockDelta: e2.TimeLockDelta,
HtlcMinimumMsat: e2.MinHTLC,
BaseFee: uint32(e2.FeeBaseMSat),

View File

@ -2468,7 +2468,7 @@ func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey,
// being updated within the ChannelUpdateAnnouncement announcement
// below. A value of zero means it's the edge of the "first" node and 1
// being the other node.
var chanFlags lnwire.ChanUpdateFlag
var chanFlags lnwire.ChanUpdateChanFlags
// The lexicographical ordering of the two identity public keys of the
// nodes indicates which of the nodes is "first". If our serialized
@ -2502,7 +2502,8 @@ func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey,
ShortChannelID: shortChanID,
ChainHash: chainHash,
Timestamp: uint32(time.Now().Unix()),
Flags: chanFlags,
MessageFlags: 0,
ChannelFlags: chanFlags,
TimeLockDelta: uint16(f.cfg.DefaultRoutingPolicy.TimeLockDelta),
// We use the HtlcMinimumMsat that the remote party required us

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,

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 {

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()),

View File

@ -20,7 +20,8 @@ var (
Signature: sig,
ShortChannelID: NewShortChanIDFromInt(1),
Timestamp: 1,
Flags: 1,
MessageFlags: 0,
ChannelFlags: 1,
}
)

View File

@ -1235,10 +1235,10 @@ func messageSummary(msg lnwire.Message) string {
msg.ChainHash, msg.ShortChannelID.ToUint64())
case *lnwire.ChannelUpdate:
return fmt.Sprintf("chain_hash=%v, short_chan_id=%v, flag=%v, "+
"update_time=%v", msg.ChainHash,
msg.ShortChannelID.ToUint64(), msg.Flags,
time.Unix(int64(msg.Timestamp), 0))
return fmt.Sprintf("chain_hash=%v, short_chan_id=%v, "+
"mflags=%v, cflags=%v, update_time=%v", msg.ChainHash,
msg.ShortChannelID.ToUint64(), msg.MessageFlags,
msg.ChannelFlags, time.Unix(int64(msg.Timestamp), 0))
case *lnwire.NodeAnnouncement:
return fmt.Sprintf("node=%x, update_time=%v",

View File

@ -339,7 +339,7 @@ func addToTopologyChange(graph *channeldb.ChannelGraph, update *TopologyChange,
// the second node.
sourceNode := edgeInfo.NodeKey1
connectingNode := edgeInfo.NodeKey2
if m.Flags&lnwire.ChanUpdateDirection == 1 {
if m.ChannelFlags&lnwire.ChanUpdateDirection == 1 {
sourceNode = edgeInfo.NodeKey2
connectingNode = edgeInfo.NodeKey1
}
@ -363,7 +363,7 @@ func addToTopologyChange(graph *channeldb.ChannelGraph, update *TopologyChange,
FeeRate: m.FeeProportionalMillionths,
AdvertisingNode: aNode,
ConnectingNode: cNode,
Disabled: m.Flags&lnwire.ChanUpdateDisabled != 0,
Disabled: m.ChannelFlags&lnwire.ChanUpdateDisabled != 0,
}
edgeUpdate.AdvertisingNode.Curve = nil
edgeUpdate.ConnectingNode.Curve = nil

View File

@ -402,9 +402,9 @@ func TestEdgeUpdateNotification(t *testing.T) {
// Create random policy edges that are stemmed to the channel id
// created above.
edge1 := randEdgePolicy(chanID, node1)
edge1.Flags = 0
edge1.ChannelFlags = 0
edge2 := randEdgePolicy(chanID, node2)
edge2.Flags = 1
edge2.ChannelFlags = 1
if err := ctx.router.UpdateEdge(edge1); err != nil {
t.Fatalf("unable to add edge update: %v", err)

View File

@ -562,7 +562,7 @@ func findPath(g *graphParams, r *restrictParams,
// TODO(halseth): also ignore disable flags for non-local
// channels if bandwidth hint is set?
isSourceChan := fromVertex == sourceVertex
edgeFlags := lnwire.ChanUpdateFlag(edge.Flags)
edgeFlags := edge.ChannelFlags
isDisabled := edgeFlags&lnwire.ChanUpdateDisabled != 0
if !isSourceChan && isDisabled {

View File

@ -271,7 +271,8 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
edgePolicy := &channeldb.ChannelEdgePolicy{
SigBytes: testSig.Serialize(),
Flags: lnwire.ChanUpdateFlag(edge.Flags),
MessageFlags: lnwire.ChanUpdateMsgFlags(edge.Flags >> 8),
ChannelFlags: lnwire.ChanUpdateChanFlags(edge.Flags),
ChannelID: edge.ChannelID,
LastUpdate: testTime,
TimeLockDelta: edge.Expiry,
@ -487,7 +488,8 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc
edgePolicy := &channeldb.ChannelEdgePolicy{
SigBytes: testSig.Serialize(),
Flags: lnwire.ChanUpdateFlag(0),
MessageFlags: 0,
ChannelFlags: 0,
ChannelID: channelID,
LastUpdate: testTime,
TimeLockDelta: testChannel.Node1.Expiry,
@ -501,7 +503,8 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc
edgePolicy = &channeldb.ChannelEdgePolicy{
SigBytes: testSig.Serialize(),
Flags: lnwire.ChanUpdateFlag(lnwire.ChanUpdateDirection),
MessageFlags: 0,
ChannelFlags: lnwire.ChanUpdateDirection,
ChannelID: channelID,
LastUpdate: testTime,
TimeLockDelta: testChannel.Node2.Expiry,
@ -1476,11 +1479,11 @@ func TestRouteFailDisabledEdge(t *testing.T) {
if err != nil {
t.Fatalf("unable to fetch edge: %v", err)
}
e1.Flags |= lnwire.ChanUpdateDisabled
e1.ChannelFlags |= lnwire.ChanUpdateDisabled
if err := graph.graph.UpdateEdgePolicy(e1); err != nil {
t.Fatalf("unable to update edge: %v", err)
}
e2.Flags |= lnwire.ChanUpdateDisabled
e2.ChannelFlags |= lnwire.ChanUpdateDisabled
if err := graph.graph.UpdateEdgePolicy(e2); err != nil {
t.Fatalf("unable to update edge: %v", err)
}
@ -1507,7 +1510,7 @@ func TestRouteFailDisabledEdge(t *testing.T) {
if err != nil {
t.Fatalf("unable to fetch edge: %v", err)
}
e.Flags |= lnwire.ChanUpdateDisabled
e.ChannelFlags |= lnwire.ChanUpdateDisabled
if err := graph.graph.UpdateEdgePolicy(e); err != nil {
t.Fatalf("unable to update edge: %v", err)
}
@ -1627,11 +1630,11 @@ func TestPathSourceEdgesBandwidth(t *testing.T) {
if err != nil {
t.Fatalf("unable to fetch edge: %v", err)
}
e1.Flags |= lnwire.ChanUpdateDisabled
e1.ChannelFlags |= lnwire.ChanUpdateDisabled
if err := graph.graph.UpdateEdgePolicy(e1); err != nil {
t.Fatalf("unable to update edge: %v", err)
}
e2.Flags |= lnwire.ChanUpdateDisabled
e2.ChannelFlags |= lnwire.ChanUpdateDisabled
if err := graph.graph.UpdateEdgePolicy(e2); err != nil {
t.Fatalf("unable to update edge: %v", err)
}

View File

@ -84,7 +84,7 @@ type ChannelGraphSource interface {
// edge for the passed channel ID (and flags) that have a more recent
// timestamp.
IsStaleEdgePolicy(chanID lnwire.ShortChannelID, timestamp time.Time,
flags lnwire.ChanUpdateFlag) bool
flags lnwire.ChanUpdateChanFlags) bool
// ForAllOutgoingChannels is used to iterate over all channels
// emanating from the "source" node which is the center of the
@ -243,7 +243,7 @@ func newEdgeLocatorByPubkeys(channelID uint64, fromNode, toNode *Vertex) *edgeLo
func newEdgeLocator(edge *channeldb.ChannelEdgePolicy) *edgeLocator {
return &edgeLocator{
channelID: edge.ChannelID,
direction: uint8(edge.Flags & lnwire.ChanUpdateDirection),
direction: uint8(edge.ChannelFlags & lnwire.ChanUpdateDirection),
}
}
@ -1149,25 +1149,26 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error {
// A flag set of 0 indicates this is an announcement for the
// "first" node in the channel.
case msg.Flags&lnwire.ChanUpdateDirection == 0:
case msg.ChannelFlags&lnwire.ChanUpdateDirection == 0:
// Ignore outdated message.
if !edge1Timestamp.Before(msg.LastUpdate) {
return newErrf(ErrOutdated, "Ignoring "+
"outdated update (flags=%v) for known "+
"chan_id=%v", msg.Flags, msg.ChannelID)
"outdated update (flags=%v|%v) for "+
"known chan_id=%v", msg.MessageFlags,
msg.ChannelFlags, msg.ChannelID)
}
// Similarly, a flag set of 1 indicates this is an announcement
// for the "second" node in the channel.
case msg.Flags&lnwire.ChanUpdateDirection == 1:
case msg.ChannelFlags&lnwire.ChanUpdateDirection == 1:
// Ignore outdated message.
if !edge2Timestamp.Before(msg.LastUpdate) {
return newErrf(ErrOutdated, "Ignoring "+
"outdated update (flags=%v) for known "+
"chan_id=%v", msg.Flags, msg.ChannelID)
"outdated update (flags=%v|%v) for "+
"known chan_id=%v", msg.MessageFlags,
msg.ChannelFlags, msg.ChannelID)
}
}
@ -2068,7 +2069,8 @@ func (r *ChannelRouter) applyChannelUpdate(msg *lnwire.ChannelUpdate,
SigBytes: msg.Signature.ToSignatureBytes(),
ChannelID: msg.ShortChannelID.ToUint64(),
LastUpdate: time.Unix(int64(msg.Timestamp), 0),
Flags: msg.Flags,
MessageFlags: msg.MessageFlags,
ChannelFlags: msg.ChannelFlags,
TimeLockDelta: msg.TimeLockDelta,
MinHTLC: msg.HtlcMinimumMsat,
FeeBaseMSat: lnwire.MilliSatoshi(msg.BaseFee),
@ -2270,7 +2272,7 @@ func (r *ChannelRouter) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
//
// NOTE: This method is part of the ChannelGraphSource interface.
func (r *ChannelRouter) IsStaleEdgePolicy(chanID lnwire.ShortChannelID,
timestamp time.Time, flags lnwire.ChanUpdateFlag) bool {
timestamp time.Time, flags lnwire.ChanUpdateChanFlags) bool {
edge1Timestamp, edge2Timestamp, exists, err := r.cfg.Graph.HasChannelEdge(
chanID.ToUint64(),

View File

@ -550,7 +550,8 @@ func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) {
errChanUpdate := lnwire.ChannelUpdate{
ShortChannelID: lnwire.NewShortChanIDFromInt(chanID),
Timestamp: uint32(edgeUpateToFail.LastUpdate.Unix()),
Flags: edgeUpateToFail.Flags,
MessageFlags: edgeUpateToFail.MessageFlags,
ChannelFlags: edgeUpateToFail.ChannelFlags,
TimeLockDelta: edgeUpateToFail.TimeLockDelta,
HtlcMinimumMsat: edgeUpateToFail.MinHTLC,
BaseFee: uint32(edgeUpateToFail.FeeBaseMSat),
@ -656,7 +657,8 @@ func TestSendPaymentErrorNonFinalTimeLockErrors(t *testing.T) {
errChanUpdate := lnwire.ChannelUpdate{
ShortChannelID: lnwire.NewShortChanIDFromInt(chanID),
Timestamp: uint32(edgeUpateToFail.LastUpdate.Unix()),
Flags: edgeUpateToFail.Flags,
MessageFlags: edgeUpateToFail.MessageFlags,
ChannelFlags: edgeUpateToFail.ChannelFlags,
TimeLockDelta: edgeUpateToFail.TimeLockDelta,
HtlcMinimumMsat: edgeUpateToFail.MinHTLC,
BaseFee: uint32(edgeUpateToFail.FeeBaseMSat),
@ -1098,7 +1100,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
FeeBaseMSat: 10,
FeeProportionalMillionths: 10000,
}
edgePolicy.Flags = 0
edgePolicy.ChannelFlags = 0
if err := ctx.router.UpdateEdge(edgePolicy); err != nil {
t.Fatalf("unable to update edge policy: %v", err)
@ -1114,7 +1116,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
FeeBaseMSat: 10,
FeeProportionalMillionths: 10000,
}
edgePolicy.Flags = 1
edgePolicy.ChannelFlags = 1
if err := ctx.router.UpdateEdge(edgePolicy); err != nil {
t.Fatalf("unable to update edge policy: %v", err)
@ -1194,7 +1196,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
FeeBaseMSat: 10,
FeeProportionalMillionths: 10000,
}
edgePolicy.Flags = 0
edgePolicy.ChannelFlags = 0
if err := ctx.router.UpdateEdge(edgePolicy); err != nil {
t.Fatalf("unable to update edge policy: %v", err)
@ -1209,7 +1211,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
FeeBaseMSat: 10,
FeeProportionalMillionths: 10000,
}
edgePolicy.Flags = 1
edgePolicy.ChannelFlags = 1
if err := ctx.router.UpdateEdge(edgePolicy); err != nil {
t.Fatalf("unable to update edge policy: %v", err)
@ -2099,7 +2101,7 @@ func TestIsStaleEdgePolicy(t *testing.T) {
FeeBaseMSat: 10,
FeeProportionalMillionths: 10000,
}
edgePolicy.Flags = 0
edgePolicy.ChannelFlags = 0
if err := ctx.router.UpdateEdge(edgePolicy); err != nil {
t.Fatalf("unable to update edge policy: %v", err)
}
@ -2113,7 +2115,7 @@ func TestIsStaleEdgePolicy(t *testing.T) {
FeeBaseMSat: 10,
FeeProportionalMillionths: 10000,
}
edgePolicy.Flags = 1
edgePolicy.ChannelFlags = 1
if err := ctx.router.UpdateEdge(edgePolicy); err != nil {
t.Fatalf("unable to update edge policy: %v", err)
}

View File

@ -3769,7 +3769,7 @@ func marshalDbEdge(edgeInfo *channeldb.ChannelEdgeInfo,
MinHtlc: int64(c1.MinHTLC),
FeeBaseMsat: int64(c1.FeeBaseMSat),
FeeRateMilliMsat: int64(c1.FeeProportionalMillionths),
Disabled: c1.Flags&lnwire.ChanUpdateDisabled != 0,
Disabled: c1.ChannelFlags&lnwire.ChanUpdateDisabled != 0,
}
}
@ -3779,7 +3779,7 @@ func marshalDbEdge(edgeInfo *channeldb.ChannelEdgeInfo,
MinHtlc: int64(c2.MinHTLC),
FeeBaseMsat: int64(c2.FeeBaseMSat),
FeeRateMilliMsat: int64(c2.FeeProportionalMillionths),
Disabled: c2.Flags&lnwire.ChanUpdateDisabled != 0,
Disabled: c2.ChannelFlags&lnwire.ChanUpdateDisabled != 0,
}
}

View File

@ -2978,10 +2978,10 @@ func (s *server) announceChanStatus(op wire.OutPoint, disabled bool) error {
if disabled {
// Set the bit responsible for marking a channel as disabled.
chanUpdate.Flags |= lnwire.ChanUpdateDisabled
chanUpdate.ChannelFlags |= lnwire.ChanUpdateDisabled
} else {
// Clear the bit responsible for marking a channel as disabled.
chanUpdate.Flags &= ^lnwire.ChanUpdateDisabled
chanUpdate.ChannelFlags &= ^lnwire.ChanUpdateDisabled
}
// We must now update the message's timestamp and generate a new
@ -3066,9 +3066,9 @@ func extractChannelUpdate(ownerPubKey []byte,
owner := func(edge *channeldb.ChannelEdgePolicy) []byte {
var pubKey *btcec.PublicKey
switch {
case edge.Flags&lnwire.ChanUpdateDirection == 0:
case edge.ChannelFlags&lnwire.ChanUpdateDirection == 0:
pubKey, _ = info.NodeKey1()
case edge.Flags&lnwire.ChanUpdateDirection == 1:
case edge.ChannelFlags&lnwire.ChanUpdateDirection == 1:
pubKey, _ = info.NodeKey2()
}
@ -3100,7 +3100,8 @@ func createChannelUpdate(info *channeldb.ChannelEdgeInfo,
ChainHash: info.ChainHash,
ShortChannelID: lnwire.NewShortChanIDFromInt(policy.ChannelID),
Timestamp: uint32(policy.LastUpdate.Unix()),
Flags: policy.Flags,
MessageFlags: policy.MessageFlags,
ChannelFlags: policy.ChannelFlags,
TimeLockDelta: policy.TimeLockDelta,
HtlcMinimumMsat: policy.MinHTLC,
BaseFee: uint32(policy.FeeBaseMSat),