Skip to content

Commit c3fb159

Browse files
committed
pytest: rework test_real_data and test_real_biases to be parallel.
This speeds them up, and exercises the askrene parallel code. Before: test_real_data: 260s test_real_biases: 173s After: test_real_data: 133s test_real_biases: 106s And this is because much of the time is spent uncompressing the gossmap and startup. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 263d4c7 commit c3fb159

File tree

1 file changed

+68
-50
lines changed

1 file changed

+68
-50
lines changed

tests/test_askrene.py

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ def test_min_htlc_after_excess(node_factory, bitcoind):
14051405

14061406

14071407
@pytest.mark.slow_test
1408-
def test_real_data(node_factory, bitcoind):
1408+
def test_real_data(node_factory, bitcoind, executor):
14091409
# Route from Rusty's node to the top nodes
14101410
# From tests/data/gossip-store-2024-09-22-node-map.xz:
14111411
# Me: 3301:024b9a1fa8e006f1e3937f65f66c408e6da8e1ca728ea43222a7381df1cc449605:BLUEIRON
@@ -1451,59 +1451,63 @@ def test_real_data(node_factory, bitcoind):
14511451
limit = 100
14521452
expected = (9, 96, 6565466, 668476, 90)
14531453

1454-
fees = {}
1454+
# 0.5% is the norm
1455+
MAX_FEE = AMOUNT // 200
1456+
1457+
# Do these in parallel.
1458+
futs = {}
14551459
for n in range(0, limit):
1456-
print(f"XXX: {n}")
1457-
# 0.5% is the norm
1458-
MAX_FEE = AMOUNT // 200
1460+
futs[n] = executor.submit(l1.rpc.getroutes,
1461+
source=l1.info['id'],
1462+
destination=nodeids[n],
1463+
amount_msat=AMOUNT,
1464+
layers=['auto.sourcefree', 'auto.localchans'],
1465+
maxfee_msat=MAX_FEE,
1466+
final_cltv=18)
14591467

1468+
1469+
fees = {}
1470+
prevs = {}
1471+
for n in range(0, limit):
1472+
fees[n] = []
14601473
if n in badnodes:
14611474
with pytest.raises(RpcError, match=badnodes[n]):
1462-
l1.rpc.getroutes(source=l1.info['id'],
1463-
destination=nodeids[n],
1464-
amount_msat=AMOUNT,
1465-
layers=['auto.sourcefree', 'auto.localchans'],
1466-
maxfee_msat=MAX_FEE,
1467-
final_cltv=18)
1468-
fees[n] = []
1469-
continue
1470-
1471-
try:
1472-
prev = l1.rpc.getroutes(source=l1.info['id'],
1473-
destination=nodeids[n],
1474-
amount_msat=AMOUNT,
1475-
layers=['auto.sourcefree', 'auto.localchans'],
1476-
maxfee_msat=MAX_FEE,
1477-
final_cltv=18)
1478-
except RpcError:
1479-
fees[n] = []
1475+
futs[n].result(TIMEOUT)
14801476
continue
14811477

1482-
# Now stress it, by asking it to spend 1msat less!
1483-
fees[n] = [sum([r['path'][0]['amount_msat'] for r in prev['routes']]) - AMOUNT]
1478+
prevs[n] = futs[n].result(TIMEOUT)
1479+
1480+
# Stress it by asking harder for each one which succeeded
1481+
while prevs != {}:
1482+
futs = {}
1483+
for n, prev in prevs.items():
1484+
# Record fees
1485+
fees[n].append(sum([r['path'][0]['amount_msat'] for r in prev['routes']]) - AMOUNT)
1486+
# Now stress it, by asking it to spend 1msat less!
1487+
futs[n] = executor.submit(l1.rpc.getroutes,
1488+
source=l1.info['id'],
1489+
destination=nodeids[n],
1490+
amount_msat=AMOUNT,
1491+
layers=['auto.sourcefree', 'auto.localchans'],
1492+
maxfee_msat=fees[n][-1] - 1,
1493+
final_cltv=18)
14841494

1485-
while True:
1486-
# Keep making it harder...
1495+
for n, fut in futs.items():
14871496
try:
1488-
routes = l1.rpc.getroutes(source=l1.info['id'],
1489-
destination=nodeids[n],
1490-
amount_msat=AMOUNT,
1491-
layers=['auto.sourcefree', 'auto.localchans'],
1492-
maxfee_msat=fees[n][-1] - 1,
1493-
final_cltv=18)
1497+
routes = fut.result(TIMEOUT)
14941498
except RpcError:
1495-
break
1499+
# Too much, this one is one.
1500+
del prevs[n]
1501+
continue
14961502

14971503
fee = sum([r['path'][0]['amount_msat'] for r in routes['routes']]) - AMOUNT
14981504
# Should get less expensive
14991505
assert fee < fees[n][-1]
15001506

15011507
# Should get less likely (Note! This is violated because once we care
15021508
# about fees, the total is reduced, leading to better prob!).
1503-
# assert routes['probability_ppm'] < prev['probability_ppm']
1504-
1505-
fees[n].append(fee)
1506-
prev = routes
1509+
# assert routes['probability_ppm'] < prevs[n]['probability_ppm']
1510+
prevs[n] = routes
15071511

15081512
# Which succeeded in improving
15091513
improved = [n for n in fees if len(fees[n]) > 1]
@@ -1521,10 +1525,12 @@ def test_real_data(node_factory, bitcoind):
15211525
best = n
15221526

15231527
assert (len(fees[best]), len(improved), total_first_fee, total_final_fee, percent_fee_reduction) == expected
1528+
# askrene will have restricted how many we run
1529+
assert l1.daemon.is_in_log(r"Too many running at once \(4 vs 4\): waiting")
15241530

15251531

15261532
@pytest.mark.slow_test
1527-
def test_real_biases(node_factory, bitcoind):
1533+
def test_real_biases(node_factory, bitcoind, executor):
15281534
# Route from Rusty's node to the top 100.
15291535
# From tests/data/gossip-store-2024-09-22-node-map.xz:
15301536
# Me: 3301:024b9a1fa8e006f1e3937f65f66c408e6da8e1ca728ea43222a7381df1cc449605:BLUEIRON
@@ -1572,22 +1578,34 @@ def test_real_biases(node_factory, bitcoind):
15721578
num_changed = {}
15731579
bias_ineffective = 0
15741580

1581+
# 0.5% is the norm
1582+
MAX_FEE = AMOUNT // 200
1583+
1584+
# To exercise parallelism, do bases all at once.
1585+
futures = {}
1586+
for n in range(0, limit):
1587+
if n in badnodes:
1588+
continue
1589+
futures[n] = executor.submit(l1.rpc.getroutes,
1590+
source=l1.info[ 'id'],
1591+
destination=nodeids[n],
1592+
amount_msat=AMOUNT,
1593+
layers=['auto.sourcefree', 'auto.localchans'],
1594+
maxfee_msat=MAX_FEE,
1595+
final_cltv=18)
1596+
1597+
base_routes = {}
1598+
for n in range(0, limit):
1599+
if n in badnodes:
1600+
continue
1601+
base_routes[n] = futures[n].result(TIMEOUT)
1602+
15751603
for bias in (1, 2, 4, 8, 16, 32, 64, 100):
15761604
num_changed[bias] = 0
15771605
for n in range(0, limit):
1578-
# 0.5% is the norm
1579-
MAX_FEE = AMOUNT // 200
1580-
15811606
if n in badnodes:
15821607
continue
1583-
1584-
route = l1.rpc.getroutes(source=l1.info['id'],
1585-
destination=nodeids[n],
1586-
amount_msat=AMOUNT,
1587-
layers=['auto.sourcefree', 'auto.localchans'],
1588-
maxfee_msat=MAX_FEE,
1589-
final_cltv=18)
1590-
1608+
route = base_routes[n]
15911609
# Now add bias against final channel, see if it changes.
15921610
chan = route['routes'][0]['path'][-1]['short_channel_id_dir']
15931611

0 commit comments

Comments
 (0)