From c9c674fe976f4f9f9b73c464756a69048d5539f7 Mon Sep 17 00:00:00 2001 From: 21M4TW <21m4tw@proton.me> Date: Tue, 15 Apr 2025 08:49:34 -0400 Subject: [PATCH 1/2] -Fixing offers when offer_paths are present and offer_issuer_id is no longer needed. -There is a missing piece however in plugins/offers_invreq_hook.c, which causes an error in plugins/fetchinvoice.c when trying to fetch an invoice for an offer without offer_issuer _id. Comments were added to describe the remaining issue. --- plugins/fetchinvoice.c | 5 +++++ plugins/offers_invreq_hook.c | 5 +++++ plugins/offers_offer.c | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index c40889763d95..e566101cc19c 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -240,6 +240,11 @@ static struct command_result *handle_invreq_response(struct command *cmd, badfield = "invoice_payment_hash"; goto badinv; } + /* Currently the following check fails for offers that do not contain + * offer_issuer_id and for which an invoice is fetched from a CLN node, + * because listoffers_done in offers_invrek_hook.c sets invoice_node_id + * to offer_issuer_id regardless. + */ if (!inv->invoice_node_id) { badfield = "invoice_node_id"; goto badinv; diff --git a/plugins/offers_invreq_hook.c b/plugins/offers_invreq_hook.c index 5cefec997537..2a94214780b2 100644 --- a/plugins/offers_invreq_hook.c +++ b/plugins/offers_invreq_hook.c @@ -935,6 +935,11 @@ static struct command_result *listoffers_done(struct command *cmd, * - MUST set `invoice_node_id` to the `offer_issuer_id` */ /* FIXME: We always provide an offer_issuer_id! */ + /* The following line is wrong when offer_issuer_id is not used. + * According to fetchinvoice.c, it should be "equal to the final + * `blinded_node_id` it [the payer] sent the invoice request to", when + * offer_issuer_id is not set and offer_paths is set + */ ir->inv->invoice_node_id = ir->inv->offer_issuer_id; /* BOLT #12: diff --git a/plugins/offers_offer.c b/plugins/offers_offer.c index a50052cb13b1..ab9b42d206c6 100644 --- a/plugins/offers_offer.c +++ b/plugins/offers_offer.c @@ -296,6 +296,12 @@ static struct command_result *found_best_peer(struct command *cmd, struct secret blinding_path_secret; struct sha256 offer_id; + /* offer_issuer_id is not needed when offer_paths are used. + * The following line seems to produce a valid offer with + * offer_issuer_id removed. + */ + offinfo->offer->offer_issuer_id = NULL; + /* Note: "id" of offer minus paths */ offer_offer_id(offinfo->offer, &offer_id); From 5c537297c71d59038f3a8d699c1fde88979aabab Mon Sep 17 00:00:00 2001 From: 21M4TW <21m4tw@proton.me> Date: Mon, 25 Aug 2025 15:15:48 -0400 Subject: [PATCH 2/2] listoffers_done: Fix invoice_node_id so it is set to the final blinded_node_id when offer_issuer_id is not present and offers_path is present. --- plugins/fetchinvoice.c | 5 ----- plugins/offers_invreq_hook.c | 15 +++++++-------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index e566101cc19c..c40889763d95 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -240,11 +240,6 @@ static struct command_result *handle_invreq_response(struct command *cmd, badfield = "invoice_payment_hash"; goto badinv; } - /* Currently the following check fails for offers that do not contain - * offer_issuer_id and for which an invoice is fetched from a CLN node, - * because listoffers_done in offers_invrek_hook.c sets invoice_node_id - * to offer_issuer_id regardless. - */ if (!inv->invoice_node_id) { badfield = "invoice_node_id"; goto badinv; diff --git a/plugins/offers_invreq_hook.c b/plugins/offers_invreq_hook.c index 2a94214780b2..0aa8dc2cae3a 100644 --- a/plugins/offers_invreq_hook.c +++ b/plugins/offers_invreq_hook.c @@ -931,16 +931,15 @@ static struct command_result *listoffers_done(struct command *cmd, assert(ir->inv->invreq_payer_id); /* BOLT #12: - * - if `offer_issuer_id` is present: + * - if `offer_issuer_id` is present or if `offer_paths` is not present: * - MUST set `invoice_node_id` to the `offer_issuer_id` + * - else: + * - MUST set `invoice_node_id` to the final `blinded_node_id` */ - /* FIXME: We always provide an offer_issuer_id! */ - /* The following line is wrong when offer_issuer_id is not used. - * According to fetchinvoice.c, it should be "equal to the final - * `blinded_node_id` it [the payer] sent the invoice request to", when - * offer_issuer_id is not set and offer_paths is set - */ - ir->inv->invoice_node_id = ir->inv->offer_issuer_id; + if(!ir->inv->offer_issuer_id && ir->invreq->offer_paths) { + ir->inv->invoice_node_id = &(*ir->invreq->offer_paths)->path[tal_count((*ir->invreq->offer_paths)->path)-1]->blinded_node_id; + + } else ir->inv->invoice_node_id = ir->inv->offer_issuer_id; /* BOLT #12: * - MUST set `invoice_created_at` to the number of seconds since