From 35003bd87c854664fab27936d348d0b0ed8be79b Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Tue, 19 Mar 2019 15:07:05 +0100 Subject: [PATCH] routing/test: sort nodes for channel graph This commit ensures that channel endpoints in EdgeInfo are ordered node1 < node2 to not violate assumptions being made by dependent code. --- routing/pathfind_test.go | 42 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index 7ce114c29..fb5ca0a57 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -477,6 +477,16 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc Index: 0, } + // Sort nodes + node1 := testChannel.Node1 + node2 := testChannel.Node2 + node1Vertex := aliasMap[node1.Alias] + node2Vertex := aliasMap[node2.Alias] + if bytes.Compare(node1Vertex[:], node2Vertex[:]) == 1 { + node1, node2 = node2, node1 + node1Vertex, node2Vertex = node2Vertex, node1Vertex + } + // We first insert the existence of the edge between the two // nodes. edgeInfo := channeldb.ChannelEdgeInfo{ @@ -485,10 +495,10 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc ChannelPoint: *fundingPoint, Capacity: testChannel.Capacity, - NodeKey1Bytes: aliasMap[testChannel.Node1.Alias], - BitcoinKey1Bytes: aliasMap[testChannel.Node1.Alias], - NodeKey2Bytes: aliasMap[testChannel.Node2.Alias], - BitcoinKey2Bytes: aliasMap[testChannel.Node2.Alias], + NodeKey1Bytes: node1Vertex, + BitcoinKey1Bytes: node1Vertex, + NodeKey2Bytes: node2Vertex, + BitcoinKey2Bytes: node2Vertex, } err = graph.AddChannelEdge(&edgeInfo) @@ -510,12 +520,12 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc MessageFlags: msgFlags, ChannelFlags: channelFlags, ChannelID: channelID, - LastUpdate: testChannel.Node1.LastUpdate, - TimeLockDelta: testChannel.Node1.Expiry, - MinHTLC: testChannel.Node1.MinHTLC, - MaxHTLC: testChannel.Node1.MaxHTLC, - FeeBaseMSat: testChannel.Node1.FeeBaseMsat, - FeeProportionalMillionths: testChannel.Node1.FeeRate, + LastUpdate: node1.LastUpdate, + TimeLockDelta: node1.Expiry, + MinHTLC: node1.MinHTLC, + MaxHTLC: node1.MaxHTLC, + FeeBaseMSat: node1.FeeBaseMsat, + FeeProportionalMillionths: node1.FeeRate, } if err := graph.UpdateEdgePolicy(edgePolicy); err != nil { return nil, err @@ -536,12 +546,12 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc MessageFlags: msgFlags, ChannelFlags: channelFlags, ChannelID: channelID, - LastUpdate: testChannel.Node2.LastUpdate, - TimeLockDelta: testChannel.Node2.Expiry, - MinHTLC: testChannel.Node2.MinHTLC, - MaxHTLC: testChannel.Node2.MaxHTLC, - FeeBaseMSat: testChannel.Node2.FeeBaseMsat, - FeeProportionalMillionths: testChannel.Node2.FeeRate, + LastUpdate: node2.LastUpdate, + TimeLockDelta: node2.Expiry, + MinHTLC: node2.MinHTLC, + MaxHTLC: node2.MaxHTLC, + FeeBaseMSat: node2.FeeBaseMsat, + FeeProportionalMillionths: node2.FeeRate, } if err := graph.UpdateEdgePolicy(edgePolicy); err != nil { return nil, err