MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_getroutes_maxhops

Function test_getroutes_maxhops

tests/test_askrene.py:2807–2846  ·  view source on GitHub ↗

maxhops limits the length of every returned path.

(node_factory)

Source from the content-addressed store, hash-verified

2805
2806
2807def test_getroutes_maxhops(node_factory):
2808 """maxhops limits the length of every returned path."""
2809 gsfile, nodemap = maxhops_gossip(pricey_propfee=300, long_len=5)
2810 l1 = node_factory.get_node(gossip_store_file=gsfile.name)
2811 payment_amount = 100_000_000
2812
2813 # A limit that doesn't bind changes nothing.
2814 for maxhops in (2, 3, 5, 100):
2815 routes = l1.rpc.getroutes(
2816 source=nodemap[0],
2817 destination=nodemap[1000],
2818 amount_msat=payment_amount,
2819 layers=[f"maxhops={maxhops}"],
2820 maxfee_msat=payment_amount,
2821 final_cltv=18,
2822 )["routes"]
2823 assert [len(r["path"]) for r in routes] == [2]
2824 assert routes[0]["path"][0]["node_id_out"] == nodemap[2000]
2825
2826 # Impossible.
2827 with pytest.raises(RpcError, match="excessive hop count"):
2828 l1.rpc.getroutes(
2829 source=nodemap[0],
2830 destination=nodemap[1000],
2831 amount_msat=payment_amount,
2832 layers=["maxhops=1"],
2833 maxfee_msat=payment_amount,
2834 final_cltv=18,
2835 )
2836
2837 # A hop limit works for one-hop routes too.
2838 routes = l1.rpc.getroutes(
2839 source=nodemap[2000],
2840 destination=nodemap[1000],
2841 amount_msat=payment_amount,
2842 layers=["maxhops=1"],
2843 maxfee_msat=payment_amount,
2844 final_cltv=18,
2845 )["routes"]
2846 assert [len(r["path"]) for r in routes] == [1]
2847
2848
2849def test_getroutes_maxhops_mpp(node_factory):

Callers

nothing calls this directly

Calls 3

maxhops_gossipFunction · 0.85
getroutesMethod · 0.80
get_nodeMethod · 0.45

Tested by

no test coverage detected