routing: add private key attribute in router test

This commit is contained in:
bluetegu 2018-12-10 07:32:21 -05:00 committed by yyforyongyu
parent 9062ab1671
commit fc113c7508
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
3 changed files with 50 additions and 13 deletions

@ -118,10 +118,13 @@ type testGraph struct {
// testNode represents a node within the test graph above. We skip certain // testNode represents a node within the test graph above. We skip certain
// information such as the node's IP address as that information isn't needed // information such as the node's IP address as that information isn't needed
// for our tests. // for our tests. Private keys are optional. If set, they should be consistent
// with the public key. The private key is used to sign error messages
// sent from the node.
type testNode struct { type testNode struct {
Source bool `json:"source"` Source bool `json:"source"`
PubKey string `json:"pubkey"` PubKey string `json:"pubkey"`
PrivKey string `json:"privkey"`
Alias string `json:"alias"` Alias string `json:"alias"`
} }
@ -200,6 +203,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)
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.
@ -230,6 +234,33 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
// alias map for easy lookup. // alias map for easy lookup.
aliasMap[node.Alias] = dbNode.PubKeyBytes aliasMap[node.Alias] = dbNode.PubKeyBytes
// private keys are needed for signing error messages. If set
// check the consistency with the public key.
privBytes, err := hex.DecodeString(node.PrivKey)
if err != nil {
return nil, err
}
if len(privBytes) > 0 {
key, derivedPub := btcec.PrivKeyFromBytes(
btcec.S256(), privBytes,
)
if !bytes.Equal(
pubBytes, derivedPub.SerializeCompressed(),
) {
return nil, fmt.Errorf("%s public key and "+
"private key are inconsistent\n"+
"got %x\nwant %x\n",
node.Alias,
derivedPub.SerializeCompressed(),
pubBytes,
)
}
privKeyMap[node.Alias] = key
}
// If the node is tagged as the source, then we create a // If the node is tagged as the source, then we create a
// pointer to is so we can mark the source in the graph // pointer to is so we can mark the source in the graph
// properly. // properly.
@ -240,7 +271,8 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
// node can be the source in the graph. // node can be the source in the graph.
if source != nil { if source != nil {
return nil, errors.New("JSON is invalid " + return nil, errors.New("JSON is invalid " +
"multiple nodes are tagged as the source") "multiple nodes are tagged as the " +
"source")
} }
source = dbNode source = dbNode
@ -330,6 +362,7 @@ func parseTestGraph(path string) (*testGraphInstance, error) {
graph: graph, graph: graph,
cleanUp: cleanUp, cleanUp: cleanUp,
aliasMap: aliasMap, aliasMap: aliasMap,
privKeyMap: privKeyMap,
}, nil }, nil
} }

@ -35,6 +35,8 @@ type testCtx struct {
aliases map[string]route.Vertex aliases map[string]route.Vertex
privKeys map[string]*btcec.PrivateKey
chain *mockChain chain *mockChain
chainView *mockChainView chainView *mockChainView
@ -151,6 +153,7 @@ func createTestCtxFromGraphInstanceAssumeValid(startingHeight uint32,
router: router, router: router,
graph: graphInstance.graph, graph: graphInstance.graph,
aliases: graphInstance.aliasMap, aliases: graphInstance.aliasMap,
privKeys: graphInstance.privKeyMap,
chain: chain, chain: chain,
chainView: chainView, chainView: chainView,
} }

@ -39,7 +39,8 @@
}, },
{ {
"source": false, "source": false,
"pubkey": "032b480de5d002f1a8fd1fe1bbf0a0f1b07760f65f052e66d56f15d71097c01add", "pubkey": "026c43a8ac1cd8519985766e90748e1e06871dab0ff6b8af27e8c1a61640481318",
"privkey": "82b266f659bd83a976bac11b2cc442baec5508e84e61085d7ec2b0fc52156c87",
"alias": "songoku" "alias": "songoku"
}, },
{ {
@ -154,7 +155,7 @@
"capacity": 120000 "capacity": 120000
}, },
{ {
"node_1": "032b480de5d002f1a8fd1fe1bbf0a0f1b07760f65f052e66d56f15d71097c01add", "node_1": "026c43a8ac1cd8519985766e90748e1e06871dab0ff6b8af27e8c1a61640481318",
"node_2": "0367cec75158a4129177bfb8b269cb586efe93d751b43800d456485e81c2620ca6", "node_2": "0367cec75158a4129177bfb8b269cb586efe93d751b43800d456485e81c2620ca6",
"channel_id": 12345, "channel_id": 12345,
"channel_point": "89dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0", "channel_point": "89dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
@ -168,7 +169,7 @@
"capacity": 100000 "capacity": 100000
}, },
{ {
"node_1": "032b480de5d002f1a8fd1fe1bbf0a0f1b07760f65f052e66d56f15d71097c01add", "node_1": "026c43a8ac1cd8519985766e90748e1e06871dab0ff6b8af27e8c1a61640481318",
"node_2": "0367cec75158a4129177bfb8b269cb586efe93d751b43800d456485e81c2620ca6", "node_2": "0367cec75158a4129177bfb8b269cb586efe93d751b43800d456485e81c2620ca6",
"channel_id": 12345, "channel_id": 12345,
"channel_point": "89dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0", "channel_point": "89dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
@ -182,7 +183,7 @@
"capacity": 100000 "capacity": 100000
}, },
{ {
"node_1": "032b480de5d002f1a8fd1fe1bbf0a0f1b07760f65f052e66d56f15d71097c01add", "node_1": "026c43a8ac1cd8519985766e90748e1e06871dab0ff6b8af27e8c1a61640481318",
"node_2": "036264734b40c9e91d3d990a8cdfbbe23b5b0b7ad3cd0e080a25dcd05d39eeb7eb", "node_2": "036264734b40c9e91d3d990a8cdfbbe23b5b0b7ad3cd0e080a25dcd05d39eeb7eb",
"channel_id": 3495345, "channel_id": 3495345,
"channel_point": "9f155756b33a0a6827713965babbd561b55f9520444ac5db0cf7cb2eb0deb5bc:0", "channel_point": "9f155756b33a0a6827713965babbd561b55f9520444ac5db0cf7cb2eb0deb5bc:0",
@ -196,7 +197,7 @@
"capacity": 110000 "capacity": 110000
}, },
{ {
"node_1": "032b480de5d002f1a8fd1fe1bbf0a0f1b07760f65f052e66d56f15d71097c01add", "node_1": "026c43a8ac1cd8519985766e90748e1e06871dab0ff6b8af27e8c1a61640481318",
"node_2": "036264734b40c9e91d3d990a8cdfbbe23b5b0b7ad3cd0e080a25dcd05d39eeb7eb", "node_2": "036264734b40c9e91d3d990a8cdfbbe23b5b0b7ad3cd0e080a25dcd05d39eeb7eb",
"channel_id": 3495345, "channel_id": 3495345,
"channel_point": "9f155756b33a0a6827713965babbd561b55f9520444ac5db0cf7cb2eb0deb5bc:0", "channel_point": "9f155756b33a0a6827713965babbd561b55f9520444ac5db0cf7cb2eb0deb5bc:0",