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.
This commit is contained in:
Joost Jager 2019-03-19 15:07:05 +01:00
parent 4068e78af6
commit 35003bd87c
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -477,6 +477,16 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc
Index: 0, 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 // We first insert the existence of the edge between the two
// nodes. // nodes.
edgeInfo := channeldb.ChannelEdgeInfo{ edgeInfo := channeldb.ChannelEdgeInfo{
@ -485,10 +495,10 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc
ChannelPoint: *fundingPoint, ChannelPoint: *fundingPoint,
Capacity: testChannel.Capacity, Capacity: testChannel.Capacity,
NodeKey1Bytes: aliasMap[testChannel.Node1.Alias], NodeKey1Bytes: node1Vertex,
BitcoinKey1Bytes: aliasMap[testChannel.Node1.Alias], BitcoinKey1Bytes: node1Vertex,
NodeKey2Bytes: aliasMap[testChannel.Node2.Alias], NodeKey2Bytes: node2Vertex,
BitcoinKey2Bytes: aliasMap[testChannel.Node2.Alias], BitcoinKey2Bytes: node2Vertex,
} }
err = graph.AddChannelEdge(&edgeInfo) err = graph.AddChannelEdge(&edgeInfo)
@ -510,12 +520,12 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc
MessageFlags: msgFlags, MessageFlags: msgFlags,
ChannelFlags: channelFlags, ChannelFlags: channelFlags,
ChannelID: channelID, ChannelID: channelID,
LastUpdate: testChannel.Node1.LastUpdate, LastUpdate: node1.LastUpdate,
TimeLockDelta: testChannel.Node1.Expiry, TimeLockDelta: node1.Expiry,
MinHTLC: testChannel.Node1.MinHTLC, MinHTLC: node1.MinHTLC,
MaxHTLC: testChannel.Node1.MaxHTLC, MaxHTLC: node1.MaxHTLC,
FeeBaseMSat: testChannel.Node1.FeeBaseMsat, FeeBaseMSat: node1.FeeBaseMsat,
FeeProportionalMillionths: testChannel.Node1.FeeRate, FeeProportionalMillionths: node1.FeeRate,
} }
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil { if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
return nil, err return nil, err
@ -536,12 +546,12 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc
MessageFlags: msgFlags, MessageFlags: msgFlags,
ChannelFlags: channelFlags, ChannelFlags: channelFlags,
ChannelID: channelID, ChannelID: channelID,
LastUpdate: testChannel.Node2.LastUpdate, LastUpdate: node2.LastUpdate,
TimeLockDelta: testChannel.Node2.Expiry, TimeLockDelta: node2.Expiry,
MinHTLC: testChannel.Node2.MinHTLC, MinHTLC: node2.MinHTLC,
MaxHTLC: testChannel.Node2.MaxHTLC, MaxHTLC: node2.MaxHTLC,
FeeBaseMSat: testChannel.Node2.FeeBaseMsat, FeeBaseMSat: node2.FeeBaseMsat,
FeeProportionalMillionths: testChannel.Node2.FeeRate, FeeProportionalMillionths: node2.FeeRate,
} }
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil { if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
return nil, err return nil, err