Skip to content

Commit 99fb900

Browse files
committed
xpay: forward command notifications from askrene.
This gives us more route details (particularly at higher log levels). Signed-off-by: Rusty Russell <[email protected]>
1 parent 4524888 commit 99fb900

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

plugins/xpay/xpay.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,10 +1348,11 @@ static struct command_result *getroutes_for(struct command *aux_cmd,
13481348
maxfee = AMOUNT_MSAT(0);
13491349
}
13501350

1351-
req = jsonrpc_request_start(aux_cmd, "getroutes",
1352-
getroutes_done,
1353-
getroutes_done_err,
1354-
payment);
1351+
req = jsonrpc_request_notified_start(aux_cmd, "getroutes",
1352+
getroutes_done,
1353+
getroutes_done_err,
1354+
forward_notified,
1355+
payment);
13551356

13561357
json_add_pubkey(req->js, "source", &xpay->local_id);
13571358
json_add_pubkey(req->js, "destination", dst);

tests/test_askrene.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,3 +1536,20 @@ def test_simple_dummy_channel(node_factory):
15361536
final_cltv=5,
15371537
layers=["mylayer"],
15381538
)
1539+
1540+
1541+
def test_askrene_notifications(node_factory):
1542+
l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True)
1543+
1544+
out = subprocess.check_output(['cli/lightning-cli',
1545+
'--network={}'.format(TEST_NETWORK),
1546+
'--lightning-dir={}'
1547+
.format(l1.daemon.lightning_dir),
1548+
'getroutes',
1549+
l1.info['id'],
1550+
l3.info['id'],
1551+
"10000msat",
1552+
"[]",
1553+
"1000msat",
1554+
"11"]).decode('utf-8').splitlines()
1555+
assert out == []

tests/test_xpay.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,3 +1036,41 @@ def test_xpay_bip353(node_factory):
10361036
# Now with a payer_note:
10371037
l2.rpc.xpay(invstring='[email protected]', amount_msat=123, payer_note="Eat at Joes!")
10381038
assert l1.rpc.decode(l1.rpc.listinvoices()['invoices'][1]['bolt12'])['invreq_payer_note'] == "Eat at Joes!"
1039+
1040+
1041+
def test_xpay_forward_askrene_notifications(node_factory):
1042+
l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True)
1043+
1044+
scid12 = first_scid(l1, l2)
1045+
scid23 = first_scid(l3, l2)
1046+
offer = l3.rpc.offer("1000sat", 'test_xpay_forward_askrene_notifications')['bolt12']
1047+
out = subprocess.check_output(['cli/lightning-cli',
1048+
'--network={}'.format(TEST_NETWORK),
1049+
'--lightning-dir={}'
1050+
.format(l1.daemon.lightning_dir),
1051+
'xpay',
1052+
offer]).decode('utf-8').splitlines()
1053+
preimage = only_one(l3.rpc.listinvoices()['invoices'])['payment_preimage']
1054+
assert out == ['# Fetching invoice for offer',
1055+
f'# getroutes: Flow 0/1: 1000011msat/11 {scid12}/1 -> 1000011msat/11 {scid23}/0 -> 1000000msat/5 0x0x0/1 -> 1000000msat/0',
1056+
f'# ->{l2.info["id"]}->{l3.info["id"]}->020000000000000000000000000000000000000000000000000000000000000001: Success: preimage={preimage}',
1057+
'{',
1058+
f' "payment_preimage": "{preimage}",',
1059+
' "amount_msat": 1000000,',
1060+
' "amount_sent_msat": 1000011,',
1061+
' "failed_parts": 0,',
1062+
' "successful_parts": 1',
1063+
'}']
1064+
1065+
out2 = subprocess.check_output(['cli/lightning-cli',
1066+
'--network={}'.format(TEST_NETWORK),
1067+
# Now with debugging level notifications
1068+
'--notifications=debug',
1069+
'--lightning-dir={}'
1070+
.format(l1.daemon.lightning_dir),
1071+
'xpay',
1072+
offer]).decode('utf-8').splitlines()
1073+
assert out2[:3] == ['# Fetching invoice for offer',
1074+
f'# offer is {offer}',
1075+
f'# Invoice gave route {l3.info["id"]}->020000000000000000000000000000000000000000000000000000000000000001 (0x0x0/1)']
1076+
assert len(out2) > len(out)

0 commit comments

Comments
 (0)