← Watch feed
pyln: add getroutes wrapper to pyln-client, add single_route helper to pyln-testing.
What changed, and why it matters
This commit adds a new Python helper for a Lightning RPC command and updates test utilities to use it. There is no security issue visible in the change itself.
Recommended action
No security action required; review as normal code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds a getroutes() wrapper to pyln-client and a single_route() helper to pyln-testing, replacing two older getroute() calls. It is a routine API/test refactor with no cryptographic, network, or access-control changes.
Changed components
contrib/pyln-client/pyln/client/lightning.pycontrib/pyln-testing/pyln/testing/utils.pyInspect captured patch +30 / −12
diff --git a/contrib/pyln-client/pyln/client/lightning.py b/contrib/pyln-client/pyln/client/lightning.py
index 76b8eb8e..5b72fa64 100644
--- a/contrib/pyln-client/pyln/client/lightning.py
+++ b/contrib/pyln-client/pyln/client/lightning.py
@@ -896,6 +896,24 @@ class LightningRpc(UnixDomainSocketRpc):
}
return self.call("getroute", payload)
+ def getroutes(self, source, destination, amount_msat, layers, maxfee_msat,
+ final_cltv, maxdelay=None, maxparts=None):
+ """Find routes from {source} to {destination} for {amount_msat},
+ applying {layers}, paying no more than {maxfee_msat},
+ ending in {final_cltv}.
+ """
+ payload = {
+ "source": source,
+ "destination": destination,
+ "amount_msat": amount_msat,
+ "layers": layers,
+ "maxfee_msat": maxfee_msat,
+ "final_cltv": final_cltv,
+ "maxdelay": maxdelay,
+ "maxparts": maxparts,
+ }
+ return self.call("getroutes", payload)
+
def help(self, command=None):
"""
Show available commands, or just {command} if supplied.
diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py
index 861afcea..1065838c 100644
--- a/contrib/pyln-testing/pyln/testing/utils.py
+++ b/contrib/pyln-testing/pyln/testing/utils.py
@@ -1363,7 +1363,7 @@ class LightningNode(object):
start_time = time.time()
while time.time() < start_time + timeout:
try:
- self.rpc.getroute(destination.info['id'], 1, 1)
+ self.single_route(destination.info['id'], 1)
return True
except Exception:
time.sleep(1)
@@ -1383,20 +1383,10 @@ class LightningNode(object):
wait_for(lambda: len(self.rpc.listpeerchannels(peer["id"])['channels'][idx]['htlcs']) == 0)
# This sends money to a directly connected peer
- # if `route` is `True`, it can also send over the network.
- def pay(self, dst, amt, label=None, route=False):
+ def pay(self, dst, amt, label=None):
if not label:
label = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20))
- if route is True:
- invoice = dst.rpc.invoice(amt, label, "desc")
- route = self.rpc.getroute(dst.info["id"], amt, riskfactor=0, fuzzpercent=0)
- self.rpc.sendpay(route["route"], invoice["payment_hash"], payment_secret=invoice.get('payment_secret'))
- result = self.rpc.waitsendpay(invoice["payment_hash"])
- assert result.get('status') == 'complete'
- self.wait_for_htlcs()
- return
-
# check we are connected
dst_id = dst.info['id']
assert len(self.rpc.listpeers(dst_id).get('peers')) == 1
@@ -1428,6 +1418,16 @@ class LightningNode(object):
# Make sure they're all settled, in case we quickly mine blocks!
dst.wait_for_htlcs()
+ def single_route(self, node_id, amount_msat, cltv=9):
+ """Similar to the getroute() call (different output though!)"""
+ return only_one(self.rpc.getroutes(source=self.info['id'],
+ destination=node_id,
+ amount_msat=amount_msat,
+ layers=["auto.localchans", "auto.sourcefree"],
+ maxfee_msat=10000000,
+ final_cltv=cltv,
+ maxparts=1)['routes'])['path']
+
# This helper sends all money to a peer until even 1 msat can't get through.
def drain(self, peer):
total = 0
Risk score
Our methodology →Why this scored 15/100
Human-validated context
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
No validated notes yet.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.