@@ -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,62 @@ 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+ fees = {}
1469+ prevs = {}
1470+ for n in range (0 , limit ):
1471+ fees [n ] = []
14601472 if n in badnodes :
14611473 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 ] = []
1474+ futs [n ].result (TIMEOUT )
14801475 continue
14811476
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 ]
1477+ prevs [n ] = futs [n ].result (TIMEOUT )
1478+
1479+ # Stress it by asking harder for each one which succeeded
1480+ while prevs != {}:
1481+ futs = {}
1482+ for n , prev in prevs .items ():
1483+ # Record fees
1484+ fees [n ].append (sum ([r ['path' ][0 ]['amount_msat' ] for r in prev ['routes' ]]) - AMOUNT )
1485+ # Now stress it, by asking it to spend 1msat less!
1486+ futs [n ] = executor .submit (l1 .rpc .getroutes ,
1487+ source = l1 .info ['id' ],
1488+ destination = nodeids [n ],
1489+ amount_msat = AMOUNT ,
1490+ layers = ['auto.sourcefree' , 'auto.localchans' ],
1491+ maxfee_msat = fees [n ][- 1 ] - 1 ,
1492+ final_cltv = 18 )
14841493
1485- while True :
1486- # Keep making it harder...
1494+ for n , fut in futs .items ():
14871495 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 )
1496+ routes = fut .result (TIMEOUT )
14941497 except RpcError :
1495- break
1498+ # Too much, this one is one.
1499+ del prevs [n ]
1500+ continue
14961501
14971502 fee = sum ([r ['path' ][0 ]['amount_msat' ] for r in routes ['routes' ]]) - AMOUNT
14981503 # Should get less expensive
14991504 assert fee < fees [n ][- 1 ]
15001505
15011506 # Should get less likely (Note! This is violated because once we care
15021507 # 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
1508+ # assert routes['probability_ppm'] < prevs[n]['probability_ppm']
1509+ prevs [n ] = routes
15071510
15081511 # Which succeeded in improving
15091512 improved = [n for n in fees if len (fees [n ]) > 1 ]
@@ -1521,10 +1524,12 @@ def test_real_data(node_factory, bitcoind):
15211524 best = n
15221525
15231526 assert (len (fees [best ]), len (improved ), total_first_fee , total_final_fee , percent_fee_reduction ) == expected
1527+ # askrene will have restricted how many we run
1528+ assert l1 .daemon .is_in_log (r"Too many running at once \(4 vs 4\): waiting" )
15241529
15251530
15261531@pytest .mark .slow_test
1527- def test_real_biases (node_factory , bitcoind ):
1532+ def test_real_biases (node_factory , bitcoind , executor ):
15281533 # Route from Rusty's node to the top 100.
15291534 # From tests/data/gossip-store-2024-09-22-node-map.xz:
15301535 # Me: 3301:024b9a1fa8e006f1e3937f65f66c408e6da8e1ca728ea43222a7381df1cc449605:BLUEIRON
@@ -1572,22 +1577,34 @@ def test_real_biases(node_factory, bitcoind):
15721577 num_changed = {}
15731578 bias_ineffective = 0
15741579
1575- for bias in (1 , 2 , 4 , 8 , 16 , 32 , 64 , 100 ):
1576- num_changed [bias ] = 0
1577- for n in range (0 , limit ):
1578- # 0.5% is the norm
1579- MAX_FEE = AMOUNT // 200
1580-
1581- if n in badnodes :
1582- continue
1580+ # 0.5% is the norm
1581+ MAX_FEE = AMOUNT // 200
15831582
1584- route = l1 .rpc .getroutes (source = l1 .info ['id' ],
1583+ # To exercise parallelism, do bases all at once.
1584+ futures = {}
1585+ for n in range (0 , limit ):
1586+ if n in badnodes :
1587+ continue
1588+ futures [n ] = executor .submit (l1 .rpc .getroutes ,
1589+ source = l1 .info ['id' ],
15851590 destination = nodeids [n ],
15861591 amount_msat = AMOUNT ,
15871592 layers = ['auto.sourcefree' , 'auto.localchans' ],
15881593 maxfee_msat = MAX_FEE ,
15891594 final_cltv = 18 )
15901595
1596+ base_routes = {}
1597+ for n in range (0 , limit ):
1598+ if n in badnodes :
1599+ continue
1600+ base_routes [n ] = futures [n ].result (TIMEOUT )
1601+
1602+ for bias in (1 , 2 , 4 , 8 , 16 , 32 , 64 , 100 ):
1603+ num_changed [bias ] = 0
1604+ for n in range (0 , limit ):
1605+ if n in badnodes :
1606+ continue
1607+ route = base_routes [n ]
15911608 # Now add bias against final channel, see if it changes.
15921609 chan = route ['routes' ][0 ]['path' ][- 1 ]['short_channel_id_dir' ]
15931610
0 commit comments