routing: parse Channel ID from json file
This commit is contained in:
parent
37d0e21f05
commit
ae6d8a9a8f
@ -204,6 +204,7 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
|
|||||||
|
|
||||||
aliasMap := make(map[string]route.Vertex)
|
aliasMap := make(map[string]route.Vertex)
|
||||||
privKeyMap := make(map[string]*btcec.PrivateKey)
|
privKeyMap := make(map[string]*btcec.PrivateKey)
|
||||||
|
channelIDs := make(map[route.Vertex]map[route.Vertex]uint64)
|
||||||
var source *channeldb.LightningNode
|
var source *channeldb.LightningNode
|
||||||
|
|
||||||
// First we insert all the nodes within the graph as vertexes.
|
// First we insert all the nodes within the graph as vertexes.
|
||||||
@ -356,6 +357,27 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
|
|||||||
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
|
if err := graph.UpdateEdgePolicy(edgePolicy); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We also store the channel IDs info for each of the node.
|
||||||
|
node1Vertex, err := route.NewVertexFromBytes(node1Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
node2Vertex, err := route.NewVertexFromBytes(node2Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := channelIDs[node1Vertex]; !ok {
|
||||||
|
channelIDs[node1Vertex] = map[route.Vertex]uint64{}
|
||||||
|
}
|
||||||
|
channelIDs[node1Vertex][node2Vertex] = edge.ChannelID
|
||||||
|
|
||||||
|
if _, ok := channelIDs[node2Vertex]; !ok {
|
||||||
|
channelIDs[node2Vertex] = map[route.Vertex]uint64{}
|
||||||
|
}
|
||||||
|
channelIDs[node2Vertex][node1Vertex] = edge.ChannelID
|
||||||
}
|
}
|
||||||
|
|
||||||
return &testGraphInstance{
|
return &testGraphInstance{
|
||||||
@ -363,6 +385,7 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
|
|||||||
cleanUp: cleanUp,
|
cleanUp: cleanUp,
|
||||||
aliasMap: aliasMap,
|
aliasMap: aliasMap,
|
||||||
privKeyMap: privKeyMap,
|
privKeyMap: privKeyMap,
|
||||||
|
channelIDs: channelIDs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,6 +458,9 @@ type testGraphInstance struct {
|
|||||||
// privKeyMap maps a node alias to its private key. This is used to be
|
// privKeyMap maps a node alias to its private key. This is used to be
|
||||||
// able to mock a remote node's signing behaviour.
|
// able to mock a remote node's signing behaviour.
|
||||||
privKeyMap map[string]*btcec.PrivateKey
|
privKeyMap map[string]*btcec.PrivateKey
|
||||||
|
|
||||||
|
// channelIDs stores the channel ID for each node.
|
||||||
|
channelIDs map[route.Vertex]map[route.Vertex]uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// createTestGraphFromChannels returns a fully populated ChannelGraph based on a set of
|
// createTestGraphFromChannels returns a fully populated ChannelGraph based on a set of
|
||||||
|
@ -38,11 +38,29 @@ type testCtx struct {
|
|||||||
|
|
||||||
privKeys map[string]*btcec.PrivateKey
|
privKeys map[string]*btcec.PrivateKey
|
||||||
|
|
||||||
|
channelIDs map[route.Vertex]map[route.Vertex]uint64
|
||||||
|
|
||||||
chain *mockChain
|
chain *mockChain
|
||||||
|
|
||||||
chainView *mockChainView
|
chainView *mockChainView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *testCtx) getChannelIDFromAlias(t *testing.T, a, b string) uint64 {
|
||||||
|
vertexA, ok := c.aliases[a]
|
||||||
|
require.True(t, ok, "cannot find aliases for %s", a)
|
||||||
|
|
||||||
|
vertexB, ok := c.aliases[b]
|
||||||
|
require.True(t, ok, "cannot find aliases for %s", b)
|
||||||
|
|
||||||
|
channelIDMap, ok := c.channelIDs[vertexA]
|
||||||
|
require.True(t, ok, "cannot find channelID map %s(%s)", vertexA, a)
|
||||||
|
|
||||||
|
channelID, ok := channelIDMap[vertexB]
|
||||||
|
require.True(t, ok, "cannot find channelID using %s(%s)", vertexB, b)
|
||||||
|
|
||||||
|
return channelID
|
||||||
|
}
|
||||||
|
|
||||||
func (c *testCtx) RestartRouter() error {
|
func (c *testCtx) RestartRouter() error {
|
||||||
// First, we'll reset the chainView's state as it doesn't persist the
|
// First, we'll reset the chainView's state as it doesn't persist the
|
||||||
// filter between restarts.
|
// filter between restarts.
|
||||||
@ -155,6 +173,7 @@ func createTestCtxFromGraphInstanceAssumeValid(startingHeight uint32,
|
|||||||
graph: graphInstance.graph,
|
graph: graphInstance.graph,
|
||||||
aliases: graphInstance.aliasMap,
|
aliases: graphInstance.aliasMap,
|
||||||
privKeys: graphInstance.privKeyMap,
|
privKeys: graphInstance.privKeyMap,
|
||||||
|
channelIDs: graphInstance.channelIDs,
|
||||||
chain: chain,
|
chain: chain,
|
||||||
chainView: chainView,
|
chainView: chainView,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user