From 706debf3d4097977fa4f86fc6d862925312a6a56 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 1 Feb 2019 16:23:35 +1030 Subject: [PATCH] pytest: make test_pay_direct more effective. The test sometimes passes: our routing logic always chooses between the shorter of two equal-cost routes (because we compare best with < not <=). By adding another hop, we add more noise, and by making the alternate route fee 0 we provide the worst case. But to be fair, we make the amount of the payment ~50c (15,000,000 msat), and increase our cltv-delay to 14 and fee-base 1000 to match mainnet. The final patch shows the effect of this choice. Otherwise our risk penalty is completely in the noise on mainnet which has the vast majority of fees set at 1000msat + 1ppm. Signed-off-by: Rusty Russell --- tests/test_pay.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/test_pay.py b/tests/test_pay.py index fa0f7a2fe..c2bbffd7d 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -1345,12 +1345,22 @@ def test_pay_routeboost(node_factory, bitcoind): def test_pay_direct(node_factory, bitcoind): """Check that we prefer the direct route. """ - l1, l2, l3 = node_factory.get_nodes(3) + # l2->l3 is really cheap by comparison. + l0, l1, l2, l3 = node_factory.get_nodes(4, opts=[{'fee-base': 1000, + 'cltv-delta': 14}, + {'fee-base': 1000, + 'cltv-delta': 14}, + {'fee-base': 0, + 'cltv-delta': 14}, + {'fee-base': 1000, + 'cltv-delta': 14}]) - # Direct channel + # Direct channel l0->l1->l3 + l0.rpc.connect(l1.info['id'], 'localhost', l1.port) + l0.fund_channel(l1, 10**7) l1.rpc.connect(l3.info['id'], 'localhost', l3.port) l1.fund_channel(l3, 10**7) - # Indirect route + # Indirect route l0->l1->l2->l3 l1.rpc.connect(l2.info['id'], 'localhost', l2.port) l1.fund_channel(l2, 10**7) l2.rpc.connect(l3.info['id'], 'localhost', l3.port) @@ -1359,8 +1369,8 @@ def test_pay_direct(node_factory, bitcoind): # Let channels lock in. bitcoind.generate_block(5) - # Make sure l1 knows the l2->l3 channel. - l1.wait_channel_active(c3) + # Make sure l0 knows the l2->l3 channel. + l0.wait_channel_active(c3) # Find out how much msatoshi l1 owns on l1->l2 channel. l1l2msatreference = only_one(l1.rpc.getpeer(l2.info['id'])['channels'])['msatoshi_to_us'] @@ -1368,9 +1378,9 @@ def test_pay_direct(node_factory, bitcoind): # Try multiple times to ensure that route randomization # will not override our preference for direct route. for i in range(8): - inv = l3.rpc.invoice(10000, 'pay{}'.format(i), 'desc')['bolt11'] + inv = l3.rpc.invoice(15000000, 'pay{}'.format(i), 'desc')['bolt11'] - l1.rpc.pay(inv) + l0.rpc.pay(inv) # We should have gone the direct route, so # l1->l2 channel msatoshi_to_us should not