From 4a5f7a0cce435e1a493e2d8dfd4f7da267473b00 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 5 Mar 2021 19:40:50 +0100 Subject: [PATCH] probe: Allow the caller to specify the amount to probe We used to only probe for a 10sat amount, which allows us to test basic reachability, but it doesn't say much about whether we can actually pay for something reasonable, so this fixes that. This may require the following SQL statement to be applied to the database if you are upgrading from a prior version: ```sql ALTER TABLE probes ADD amount INTEGER; ``` This is not required if you start with a new database. --- probe/probe.py | 13 ++++++++++--- probe/test_probe.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/probe/probe.py b/probe/probe.py index a71f172ae..43a32f179 100755 --- a/probe/probe.py +++ b/probe/probe.py @@ -67,11 +67,13 @@ class Probe(Base): payment_hash = Column(String) started_at = Column(DateTime) finished_at = Column(DateTime) + amount = Column(Integer) def jsdict(self): return { 'id': self.id, 'destination': self.destination, + 'amount': self.amount, 'route': self.route, 'erring_channel': self.erring_channel, 'failcode': self.failcode, @@ -87,19 +89,24 @@ def start_probe(plugin): @plugin.async_method('probe') -def probe(plugin, request, node_id=None, **kwargs): +def probe(plugin, request, node_id=None, amount=10000, **kwargs): res = None if node_id is None: nodes = plugin.rpc.listnodes()['nodes'] node_id = choice(nodes)['nodeid'] s = plugin.Session() - p = Probe(destination=node_id, started_at=datetime.now()) + p = Probe( + destination=node_id, + started_at=datetime.now(), + amount=amount + ) s.add(p) + try: route = plugin.rpc.getroute( node_id, - msatoshi=10000, + msatoshi=amount, riskfactor=1, exclude=exclusions + list(temporary_exclusions.keys()) )['route'] diff --git a/probe/test_probe.py b/probe/test_probe.py index b359dd4ea..ec8f08cde 100644 --- a/probe/test_probe.py +++ b/probe/test_probe.py @@ -1,3 +1,4 @@ +import unittest import os from pyln.testing.fixtures import * # noqa: F401,F403 @@ -14,3 +15,44 @@ def test_probe_starts(node_factory): # Then statically l1.daemon.opts["plugin"] = plugin_path l1.start() + + +@unittest.skipIf(not DEVELOPER, "Gossip is slow") +def test_probe(node_factory): + l1, l2, l3, l4 = node_factory.line_graph( + 4, + opts=[ + {'plugin': plugin_path}, + {}, + {}, + {} + ], + wait_for_announce=True + ) + + res = l1.rpc.probe(l4.info['id']) + assert(res['destination'] == l4.info['id']) + assert(res['failcode'] == 16399) + + +@unittest.skipIf(not DEVELOPER, "Gossip is slow") +def test_route_unreachable(node_factory): + l1, l2, l3, l4 = node_factory.line_graph( + 4, + opts=[ + {'plugin': plugin_path}, + {}, + {}, + {} + ], + wait_for_announce=True + ) + + l2.rpc.close(l3.info['id']) + + res = l1.rpc.probe(l4.info['id']) + assert(res['destination'] == l4.info['id']) + assert(res['failcode'] == 16394) + route = res['route'].split(',') + assert(route.index(res['erring_channel']) == 1) +