Skip to content

Commit ae21089

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

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

plugins/offers_invreq_hook.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ static struct command_result *found_best_peer(struct command *cmd,
274274
* for each `blinded_path` in `paths`, in order.
275275
*/
276276
if (!best) {
277+
/* Don't allow bare invoices if they explicitly told us to front */
278+
if (od->fronting_nodes) {
279+
return fail_invreq(cmd, ir,
280+
"Could not find path from payment-fronting-node");
281+
}
282+
277283
/* Note: since we don't make one, createinvoice adds a dummy. */
278284
plugin_log(cmd->plugin, LOG_UNUSUAL,
279285
"No incoming channel for %s, so no blinded path",
@@ -384,6 +390,8 @@ static struct command_result *found_best_peer(struct command *cmd,
384390
static struct command_result *add_blindedpaths(struct command *cmd,
385391
struct invreq *ir)
386392
{
393+
const struct offers_data *od = get_offers_data(cmd->plugin);
394+
387395
if (!we_want_blinded_path(cmd->plugin, true))
388396
return create_invoicereq(cmd, ir);
389397

@@ -393,7 +401,7 @@ static struct command_result *add_blindedpaths(struct command *cmd,
393401
* us onion messaging. */
394402
return find_best_peer(cmd,
395403
(1ULL << OPT_ROUTE_BLINDING) | (1ULL << OPT_ONION_MESSAGES),
396-
NULL, found_best_peer, ir);
404+
od->fronting_nodes, found_best_peer, ir);
397405
}
398406

399407
static struct command_result *cancel_invoice(struct command *cmd,

tests/test_invoices.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,15 @@ def test_payment_fronting(node_factory):
976976
l4offer = l4.rpc.offer(1000, 'l4offer', 'l4offer')['bolt12']
977977
assert [r['first_node_id'] for r in l4.rpc.decode(l4offer)['offer_paths']] == [l1.info['id'], l2.info['id']]
978978

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

982989

983990
def test_invoice_maxdesc(node_factory, chainparams):

0 commit comments

Comments
 (0)