Skip to content

Commit

Permalink
pay: fix bolt12 blinded path cltv logic.
Browse files Browse the repository at this point in the history
The spec has moved a bit here: the `outgoing_cltv_value` in the final onion
is basically the blockheight now (plus the 1 block delta we give ourselves).

Also, we were doubling ours, since p->min_final_cltv_expiry was already set
to p->blindedpay->cltv_expiry_delta above.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and endothermicdev committed May 14, 2024
1 parent e2ee352 commit e0275a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
15 changes: 14 additions & 1 deletion plugins/libplugin-pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1869,11 +1869,24 @@ static void payment_compute_onion_payloads(struct payment *p)

/* If we're headed to a blinded path, connect that now. */
if (root->blindedpath) {
/* This final_cltv matches our payment heuristic of adding 1 block. */

/* BOLT #4:
* - For every node inside a blinded route:
*...
* - If it is the final node:
*...
* - The value set for `outgoing_cltv_value`:
* - MUST use the current block height as a baseline value.
* - if a [random offset](07-routing-gossip.md#recommendations-for-routing) was added to improve privacy:
* - SHOULD add the offset to the baseline value.
*/
u32 final_cltv = p->start_block + 1;
payment_add_blindedpath(cr->hops, cr->hops + hopcount - 1,
root->blindedpath,
root->blindedouramount,
root->blindedfinalamount,
root->blindedfinalcltv);
final_cltv);
tal_append_fmt(&routetxt, "%s -> blinded path (%zu hops)",
fmt_short_channel_id(tmpctx,
p->route[hopcount-1].scid),
Expand Down
1 change: 0 additions & 1 deletion plugins/libplugin-pay.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ struct payment {
struct blinded_payinfo *blindedpay;
struct amount_msat blindedouramount;
struct amount_msat blindedfinalamount;
u32 blindedfinalcltv;

u64 groupid;
u32 partid;
Expand Down
2 changes: 0 additions & 2 deletions plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1255,11 +1255,9 @@ static struct command_result *json_pay(struct command *cmd,

/* We replace real final values if we're using a blinded path */
if (p->blindedpath) {
p->blindedfinalcltv = p->min_final_cltv_expiry;
p->blindedouramount = p->our_amount;
p->blindedfinalamount = p->final_amount;

p->min_final_cltv_expiry += p->blindedpay->cltv_expiry_delta;
if (!amount_msat_add_fee(&p->final_amount,
p->blindedpay->fee_base_msat,
p->blindedpay->fee_proportional_millionths)
Expand Down

0 comments on commit e0275a7

Please sign in to comment.