Test reserving channels
(node_factory)
| 30 | |
| 31 | |
| 32 | def test_reserve(node_factory): |
| 33 | """Test reserving channels""" |
| 34 | l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True) |
| 35 | |
| 36 | assert l1.rpc.askrene_listreservations() == {'reservations': []} |
| 37 | scid12 = first_scid(l1, l2) |
| 38 | scid23 = first_scid(l2, l3) |
| 39 | scid12dir = f"{scid12}/{direction(l1.info['id'], l2.info['id'])}" |
| 40 | scid23dir = f"{scid23}/{direction(l2.info['id'], l3.info['id'])}" |
| 41 | |
| 42 | initial_prob = l1.rpc.getroutes(source=l1.info['id'], |
| 43 | destination=l3.info['id'], |
| 44 | amount_msat=1000000, |
| 45 | layers=[], |
| 46 | maxfee_msat=100000, |
| 47 | final_cltv=0)['probability_ppm'] |
| 48 | |
| 49 | # Reserve 1000 sats on path. This should reduce probability! |
| 50 | l1.rpc.askrene_reserve(path=[{'short_channel_id_dir': scid12dir, |
| 51 | 'amount_msat': 1000_000}, |
| 52 | {'short_channel_id_dir': scid23dir, |
| 53 | 'amount_msat': 1000_001}]) |
| 54 | listres = l1.rpc.askrene_listreservations()['reservations'] |
| 55 | if listres[0]['short_channel_id_dir'] == scid12dir: |
| 56 | assert listres[0]['amount_msat'] == 1000_000 |
| 57 | assert listres[1]['short_channel_id_dir'] == scid23dir |
| 58 | assert listres[1]['amount_msat'] == 1000_001 |
| 59 | else: |
| 60 | assert listres[0]['short_channel_id_dir'] == scid23dir |
| 61 | assert listres[0]['amount_msat'] == 1000_001 |
| 62 | assert listres[1]['short_channel_id_dir'] == scid12dir |
| 63 | assert listres[1]['amount_msat'] == 1000_000 |
| 64 | assert len(listres) == 2 |
| 65 | |
| 66 | assert l1.rpc.getroutes(source=l1.info['id'], |
| 67 | destination=l3.info['id'], |
| 68 | amount_msat=1000000, |
| 69 | layers=[], |
| 70 | maxfee_msat=100000, |
| 71 | final_cltv=0)['probability_ppm'] < initial_prob |
| 72 | |
| 73 | # Now reserve so much there's nothing left. |
| 74 | l1.rpc.askrene_reserve(path=[{'short_channel_id_dir': scid12dir, |
| 75 | 'amount_msat': 1000_000_000_000}, |
| 76 | {'short_channel_id_dir': scid23dir, |
| 77 | 'amount_msat': 1000_000_000_000}]) |
| 78 | |
| 79 | # Keep it consistent: the below will mention a time if >= 1 seconds old, |
| 80 | # which might happen without the sleep on slow machines. |
| 81 | time.sleep(2) |
| 82 | |
| 83 | # Reservations can be in either order. |
| 84 | with pytest.raises(RpcError, match=rf'We could not find a usable set of paths. The shortest path is {scid12}->{scid23}, but {scid12dir} already reserved 10000000*msat by command ".*" \([0-9]* seconds ago\), 10000000*msat by command ".*" \([0-9]* seconds ago\)'): |
| 85 | l1.rpc.getroutes(source=l1.info['id'], |
| 86 | destination=l3.info['id'], |
| 87 | amount_msat=1000000, |
| 88 | layers=[], |
| 89 | maxfee_msat=100000, |
nothing calls this directly
no test coverage detected