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,
}
// 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