lnworker: run create_route_for_payment end-to-end, incl private edges
We pass the private edges to lnrouter, and let it find routes end-to-end. Previously the edge_cost heuristics didn't apply to the private edges and we were just randomly picking one of the route hints and use that. So e.g. cheaper private edges were not preferred, but they are now. PathEdge now stores both start_node and end_node; not just end_node.
This commit is contained in:
@@ -600,17 +600,27 @@ class TestPeer(ElectrumTestCase):
|
||||
peers = graph.all_peers()
|
||||
async def pay(pay_req):
|
||||
with self.subTest(msg="bad path: edges do not chain together"):
|
||||
path = [PathEdge(node_id=graph.w_c.node_keypair.pubkey, short_channel_id=graph.chan_ab.short_channel_id),
|
||||
PathEdge(node_id=graph.w_d.node_keypair.pubkey, short_channel_id=graph.chan_bd.short_channel_id)]
|
||||
path = [PathEdge(start_node=graph.w_a.node_keypair.pubkey,
|
||||
end_node=graph.w_c.node_keypair.pubkey,
|
||||
short_channel_id=graph.chan_ab.short_channel_id),
|
||||
PathEdge(start_node=graph.w_b.node_keypair.pubkey,
|
||||
end_node=graph.w_d.node_keypair.pubkey,
|
||||
short_channel_id=graph.chan_bd.short_channel_id)]
|
||||
with self.assertRaises(LNPathInconsistent):
|
||||
await graph.w_a.pay_invoice(pay_req, full_path=path)
|
||||
with self.subTest(msg="bad path: last node id differs from invoice pubkey"):
|
||||
path = [PathEdge(node_id=graph.w_b.node_keypair.pubkey, short_channel_id=graph.chan_ab.short_channel_id)]
|
||||
path = [PathEdge(start_node=graph.w_a.node_keypair.pubkey,
|
||||
end_node=graph.w_b.node_keypair.pubkey,
|
||||
short_channel_id=graph.chan_ab.short_channel_id)]
|
||||
with self.assertRaises(LNPathInconsistent):
|
||||
await graph.w_a.pay_invoice(pay_req, full_path=path)
|
||||
with self.subTest(msg="good path"):
|
||||
path = [PathEdge(node_id=graph.w_b.node_keypair.pubkey, short_channel_id=graph.chan_ab.short_channel_id),
|
||||
PathEdge(node_id=graph.w_d.node_keypair.pubkey, short_channel_id=graph.chan_bd.short_channel_id)]
|
||||
path = [PathEdge(start_node=graph.w_a.node_keypair.pubkey,
|
||||
end_node=graph.w_b.node_keypair.pubkey,
|
||||
short_channel_id=graph.chan_ab.short_channel_id),
|
||||
PathEdge(start_node=graph.w_b.node_keypair.pubkey,
|
||||
end_node=graph.w_d.node_keypair.pubkey,
|
||||
short_channel_id=graph.chan_bd.short_channel_id)]
|
||||
result, log = await graph.w_a.pay_invoice(pay_req, full_path=path)
|
||||
self.assertTrue(result)
|
||||
self.assertEqual(
|
||||
|
||||
@@ -83,12 +83,14 @@ class Test_LNRouter(TestCaseForTestnet):
|
||||
cdb.add_channel_update({'short_channel_id': bfh('0000000000000005'), 'message_flags': b'\x00', 'channel_flags': b'\x00', 'cltv_expiry_delta': 10, 'htlc_minimum_msat': 250, 'fee_base_msat': 100, 'fee_proportional_millionths': 999, 'chain_hash': BitcoinTestnet.rev_genesis_bytes(), 'timestamp': 0})
|
||||
cdb.add_channel_update({'short_channel_id': bfh('0000000000000006'), 'message_flags': b'\x00', 'channel_flags': b'\x00', 'cltv_expiry_delta': 10, 'htlc_minimum_msat': 250, 'fee_base_msat': 100, 'fee_proportional_millionths': 99999999, 'chain_hash': BitcoinTestnet.rev_genesis_bytes(), 'timestamp': 0})
|
||||
cdb.add_channel_update({'short_channel_id': bfh('0000000000000006'), 'message_flags': b'\x00', 'channel_flags': b'\x01', 'cltv_expiry_delta': 10, 'htlc_minimum_msat': 250, 'fee_base_msat': 100, 'fee_proportional_millionths': 150, 'chain_hash': BitcoinTestnet.rev_genesis_bytes(), 'timestamp': 0})
|
||||
path = path_finder.find_path_for_payment(b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 100000)
|
||||
self.assertEqual([PathEdge(node_id=b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', short_channel_id=bfh('0000000000000003')),
|
||||
PathEdge(node_id=b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', short_channel_id=bfh('0000000000000002')),
|
||||
path = path_finder.find_path_for_payment(
|
||||
nodeA=b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
||||
nodeB=b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
|
||||
invoice_amount_msat=100000)
|
||||
self.assertEqual([PathEdge(start_node=b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', end_node=b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', short_channel_id=bfh('0000000000000003')),
|
||||
PathEdge(start_node=b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', end_node=b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', short_channel_id=bfh('0000000000000002')),
|
||||
], path)
|
||||
start_node = b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
|
||||
route = path_finder.create_route_from_path(path, start_node)
|
||||
route = path_finder.create_route_from_path(path)
|
||||
self.assertEqual(b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', route[0].node_id)
|
||||
self.assertEqual(bfh('0000000000000003'), route[0].short_channel_id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user