Skip to content

Commit 2f375f8

Browse files
committed
offers: honor payment-fronting-nodes when creating invoices.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent db8f46f commit 2f375f8

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

plugins/offers_invreq_hook.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ static struct command_result *found_best_peer(struct command *cmd,
277277
* for each `blinded_path` in `paths`, in order.
278278
*/
279279
if (!best) {
280+
/* Don't allow bare invoices if they explicitly told us to front */
281+
if (od->fronting_nodes) {
282+
return fail_invreq(cmd, ir,
283+
"Could not find path from payment-fronting-node");
284+
}
285+
280286
/* Note: since we don't make one, createinvoice adds a dummy. */
281287
plugin_log(cmd->plugin, LOG_UNUSUAL,
282288
"No incoming channel for %s, so no blinded path",
@@ -387,10 +393,12 @@ static struct command_result *found_best_peer(struct command *cmd,
387393
static struct command_result *add_blindedpaths(struct command *cmd,
388394
struct invreq *ir)
389395
{
396+
const struct offers_data *od = get_offers_data(cmd->plugin);
397+
390398
if (!we_want_blinded_path(cmd->plugin, true))
391399
return create_invoicereq(cmd, ir);
392400

393-
return find_best_peer(cmd, OPT_ROUTE_BLINDING, NULL,
401+
return find_best_peer(cmd, OPT_ROUTE_BLINDING, od->fronting_nodes,
394402
found_best_peer, ir);
395403
}
396404

tests/test_invoices.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,5 +973,12 @@ def test_payment_fronting(node_factory):
973973
l4offer = l4.rpc.offer(1000, 'l4offer', 'l4offer')['bolt12']
974974
assert [r['first_node_id'] for r in l4.rpc.decode(l4offer)['offer_paths']] == [l1.info['id'], l2.info['id']]
975975

976-
l1.rpc.fetchinvoice(l3offer)['invoice']
977-
l1.rpc.fetchinvoice(l4offer)['invoice']
976+
l3invb12 = l1.rpc.fetchinvoice(l3offer)['invoice']
977+
l4invb12 = l1.rpc.fetchinvoice(l4offer)['invoice']
978+
979+
assert only_one(l3.rpc.decode(l3invb12)['invoice_paths'])['first_node_id'] == l1.info['id']
980+
# Given multiple, it will pick one.
981+
assert only_one(l3.rpc.decode(l3invb12)['invoice_paths'])['first_node_id'] in (l1.info['id'], l2.info['id'])
982+
983+
l1.rpc.xpay(l3invb12)
984+
l1.rpc.xpay(l4invb12)

0 commit comments

Comments
 (0)