routing: add proper test for excessive number of hops

This commit is contained in:
Christopher Jämthagen 2017-02-01 16:48:30 +01:00 committed by Olaoluwa Osuntokun
parent 4200d8a7e0
commit 24a569b047
2 changed files with 392 additions and 10 deletions

@ -1,7 +1,6 @@
package routing
import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"
@ -23,7 +22,8 @@ const (
// basicGraphFilePath is the file path for a basic graph used within
// the tests. The basic graph consists of 5 nodes with 5 channels
// connecting them.
basicGraphFilePath = "testdata/basic_graph.json"
basicGraphFilePath = "testdata/basic_graph.json"
excessiveHopsGraphFilePath = "testdata/excessive_hops.json"
)
// testGraph is the struct which coresponds to the JSON format used to encode
@ -329,17 +329,31 @@ func TestBasicGraphPathFinding(t *testing.T) {
func TestNewRoutePathTooLong(t *testing.T) {
// Ensure that potential paths which are over the maximum hop-limit are
// rejected.
var v vertex
fakePath := make(map[vertex]edgeWithPrev)
for i := 0; i < 21; i++ {
copy(v[:], bytes.Repeat([]byte{byte(2 + i)}, 33))
fakePath[v] = edgeWithPrev{}
graph, cleanUp, aliases, err := parseTestGraph(excessiveHopsGraphFilePath)
defer cleanUp()
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}
_, err := newRoute(10, v, v, fakePath)
if err != ErrMaxHopsExceeded {
t.Fatalf("path should have been rejected")
const paymentAmt = btcutil.Amount(100)
// We start by confirminig that routing a payment 20 hops away is possible.
// Alice should be able to find a valid route to ursula.
target := aliases["ursula"]
route, err := findRoute(graph, target, paymentAmt)
if err != nil {
t.Fatalf("path should have been found")
}
// Vincent is 21 hops away from Alice, and thus no valid route should be
// presented to Alice.
target = aliases["vincent"]
route, err = findRoute(graph, target, paymentAmt)
if err == nil {
t.Fatalf("should not have been able to find path, supposed to be "+
"greater than 20 hops, found route with %v hops", len(route.Hops))
}
}
func TestPathNotAvailable(t *testing.T) {

368
routing/testdata/excessive_hops.json vendored Normal file

@ -0,0 +1,368 @@
{
"nodes": [
{
"source": true,
"pubkey": "021b96642e723592ee0b095983fe3a26c8b40b8926968d8b7510e51c9429d4562c",
"alias": "alice"
},
{
"source": false,
"pubkey": "022096b2b0ac083e708074a5ab57288bc821b6bef7b964185b307e073772c3748f",
"alias": "bob"
},
{
"source": false,
"pubkey": "022a190ce901ab2b6f349483f18b28a1d72c64a7bccb8057291f25784c0899840f",
"alias": "carol"
},
{
"source": false,
"pubkey": "022d855d09971dd047b7ecf929b23c6f147b568d4668af67fb2226eb8c15c4660d",
"alias": "dave"
},
{
"source": false,
"pubkey": "024ca436834b0d38d9dc7ee4d95aa21db321c45598dc5921a4a52304a8e0dd2952",
"alias": "eve"
},
{
"source": false,
"pubkey": "025234a0c44cbf1b20c18e2c397107ad731376831e1c43ddb360b41dbb98c10266",
"alias": "fez"
},
{
"source": false,
"pubkey": "0253e9d03030f2ff08d3a7f1d824ad6d8c0dae422f324e72d5bb313e3f2a2d45a8",
"alias": "gabby"
},
{
"source": false,
"pubkey": "0263d4f2baca258ff3bd5bce86c2754e95daaea27f268ae1a048c1253ff20de56e",
"alias": "harold"
},
{
"source": false,
"pubkey": "02650db8e44302f75e265e9427264bc0d7e2337831d6b9ceb7c58ed1e725d4576a",
"alias": "inez"
},
{
"source": false,
"pubkey": "02727bfd298aa055a6419404931dfc1ccb4f0eb7c9660a7df346b93d0025df3ba1",
"alias": "jake"
},
{
"source": false,
"pubkey": "0280c83b3eded413dcec12f7952410e2738f079bd9cbc9a7c462e32ed4d74bd5b7",
"alias": "karen"
},
{
"source": false,
"pubkey": "0290bf454f4b95baf9227801301b331e35d477c6b6e7f36a599983ae58747b3828",
"alias": "liam"
},
{
"source": false,
"pubkey": "0297c8de635d17e3dd5775edfa2797be0874c53b0026f69009787cecd2fa577de8",
"alias": "maggie"
},
{
"source": false,
"pubkey": "02a27227113c71eab0c8609ac0cdc7e76791fc3163c16e643cb4658d1080c7e336",
"alias": "nick"
},
{
"source": false,
"pubkey": "02f5f6bb6373fc60528118003f803557b916fbecd90c3a0c5df4c86c6a6e962fd1",
"alias": "ophelia"
},
{
"source": false,
"pubkey": "02fd7a5f04d550cf0ba8af6053a20e0080d956f41b1221357a35fab3a363e5f78e",
"alias": "patrick"
},
{
"source": false,
"pubkey": "030da942ed7cfc7d3096811b3264e15115778e692eaacb2b7a76fb27a58cbb5359",
"alias": "quinn"
},
{
"source": false,
"pubkey": "0319d6b038e26ac89802e856d7e78f293e9d109c414614f98e3fa5c626f20934be",
"alias": "rick"
},
{
"source": false,
"pubkey": "03384439e78e87d168fecabe8d88218dfd5983c5e14fd8fa6dc89caeb3cc0fb171",
"alias": "sarah"
},
{
"source": false,
"pubkey": "0362002b8fbc1a799c839c8bcea43fce38a147467a00bc450414bbeab5c7a19efe",
"alias": "tim"
},
{
"source": false,
"pubkey": "0369bca64993fce966745d32c09b882f668958d9bd7aabb60ba35ef1884013be1d",
"alias": "ursula"
},
{
"source": false,
"pubkey": "0367cec75158a4129177bfb8b269cb586efe93d751b43800d456485e81c2620ca6",
"alias": "vincent"
}
],
"edges": [
{
"node_1": "021b96642e723592ee0b095983fe3a26c8b40b8926968d8b7510e51c9429d4562c",
"node_2": "022096b2b0ac083e708074a5ab57288bc821b6bef7b964185b307e073772c3748f",
"channel_id": 12345,
"channel_point": "99dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "022096b2b0ac083e708074a5ab57288bc821b6bef7b964185b307e073772c3748f",
"node_2": "022a190ce901ab2b6f349483f18b28a1d72c64a7bccb8057291f25784c0899840f",
"channel_id": 12346,
"channel_point": "79dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "022a190ce901ab2b6f349483f18b28a1d72c64a7bccb8057291f25784c0899840f",
"node_2": "022d855d09971dd047b7ecf929b23c6f147b568d4668af67fb2226eb8c15c4660d",
"channel_id": 12347,
"channel_point": "69dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "022d855d09971dd047b7ecf929b23c6f147b568d4668af67fb2226eb8c15c4660d",
"node_2": "024ca436834b0d38d9dc7ee4d95aa21db321c45598dc5921a4a52304a8e0dd2952",
"channel_id": 12348,
"channel_point": "59dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "024ca436834b0d38d9dc7ee4d95aa21db321c45598dc5921a4a52304a8e0dd2952",
"node_2": "025234a0c44cbf1b20c18e2c397107ad731376831e1c43ddb360b41dbb98c10266",
"channel_id": 12349,
"channel_point": "49dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "025234a0c44cbf1b20c18e2c397107ad731376831e1c43ddb360b41dbb98c10266",
"node_2": "0253e9d03030f2ff08d3a7f1d824ad6d8c0dae422f324e72d5bb313e3f2a2d45a8",
"channel_id": 12340,
"channel_point": "39dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "0253e9d03030f2ff08d3a7f1d824ad6d8c0dae422f324e72d5bb313e3f2a2d45a8",
"node_2": "0263d4f2baca258ff3bd5bce86c2754e95daaea27f268ae1a048c1253ff20de56e",
"channel_id": 12344,
"channel_point": "29dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "0263d4f2baca258ff3bd5bce86c2754e95daaea27f268ae1a048c1253ff20de56e",
"node_2": "02650db8e44302f75e265e9427264bc0d7e2337831d6b9ceb7c58ed1e725d4576a",
"channel_id": 12343,
"channel_point": "19dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "02650db8e44302f75e265e9427264bc0d7e2337831d6b9ceb7c58ed1e725d4576a",
"node_2": "02727bfd298aa055a6419404931dfc1ccb4f0eb7c9660a7df346b93d0025df3ba1",
"channel_id": 12342,
"channel_point": "88dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "02727bfd298aa055a6419404931dfc1ccb4f0eb7c9660a7df346b93d0025df3ba1",
"node_2": "0280c83b3eded413dcec12f7952410e2738f079bd9cbc9a7c462e32ed4d74bd5b7",
"channel_id": 12341,
"channel_point": "87dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "0280c83b3eded413dcec12f7952410e2738f079bd9cbc9a7c462e32ed4d74bd5b7",
"node_2": "0290bf454f4b95baf9227801301b331e35d477c6b6e7f36a599983ae58747b3828",
"channel_id": 12355,
"channel_point": "86dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "0290bf454f4b95baf9227801301b331e35d477c6b6e7f36a599983ae58747b3828",
"node_2": "0297c8de635d17e3dd5775edfa2797be0874c53b0026f69009787cecd2fa577de8",
"channel_id": 12365,
"channel_point": "85dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "0297c8de635d17e3dd5775edfa2797be0874c53b0026f69009787cecd2fa577de8",
"node_2": "02a27227113c71eab0c8609ac0cdc7e76791fc3163c16e643cb4658d1080c7e336",
"channel_id": 12375,
"channel_point": "84dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "02a27227113c71eab0c8609ac0cdc7e76791fc3163c16e643cb4658d1080c7e336",
"node_2": "02f5f6bb6373fc60528118003f803557b916fbecd90c3a0c5df4c86c6a6e962fd1",
"channel_id": 12385,
"channel_point": "83dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "02f5f6bb6373fc60528118003f803557b916fbecd90c3a0c5df4c86c6a6e962fd1",
"node_2": "02fd7a5f04d550cf0ba8af6053a20e0080d956f41b1221357a35fab3a363e5f78e",
"channel_id": 12395,
"channel_point": "82dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "02fd7a5f04d550cf0ba8af6053a20e0080d956f41b1221357a35fab3a363e5f78e",
"node_2": "030da942ed7cfc7d3096811b3264e15115778e692eaacb2b7a76fb27a58cbb5359",
"channel_id": 12305,
"channel_point": "81dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "030da942ed7cfc7d3096811b3264e15115778e692eaacb2b7a76fb27a58cbb5359",
"node_2": "0319d6b038e26ac89802e856d7e78f293e9d109c414614f98e3fa5c626f20934be",
"channel_id": 12335,
"channel_point": "80dc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "0319d6b038e26ac89802e856d7e78f293e9d109c414614f98e3fa5c626f20934be",
"node_2": "03384439e78e87d168fecabe8d88218dfd5983c5e14fd8fa6dc89caeb3cc0fb171",
"channel_id": 12325,
"channel_point": "89ec56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "03384439e78e87d168fecabe8d88218dfd5983c5e14fd8fa6dc89caeb3cc0fb171",
"node_2": "0362002b8fbc1a799c839c8bcea43fce38a147467a00bc450414bbeab5c7a19efe",
"channel_id": 12315,
"channel_point": "89fc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "0362002b8fbc1a799c839c8bcea43fce38a147467a00bc450414bbeab5c7a19efe",
"node_2": "0369bca64993fce966745d32c09b882f668958d9bd7aabb60ba35ef1884013be1d",
"channel_id": 12445,
"channel_point": "89cc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
},
{
"node_1": "0369bca64993fce966745d32c09b882f668958d9bd7aabb60ba35ef1884013be1d",
"node_2": "0367cec75158a4129177bfb8b269cb586efe93d751b43800d456485e81c2620ca6",
"channel_id": 12545,
"channel_point": "89bc56859c6a082d15ba1a7f6cb6be3fea62e1746e2cb8497b1189155c21a233:0",
"flags": 0,
"expiry": 1,
"min_htlc": 1,
"fee_base_msat": 10,
"fee_rate": 0.001,
"capacity": 100000
}
]
}