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

+2 -2
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
+2 -2
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)
+1 -1
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 {
+11 -8
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)
}
+13 -11
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(),
+10 -8
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)
}