Skip to content

Commit 7ad8fde

Browse files
committed
bolt11: update ctlv expiry, always write it.
As per lightning/bolts#785 Signed-off-by: Rusty Russell <[email protected]> Changelog-Changed: protocol: bolt11 invoices always include CLTV fields (see lightning-rfc#785)
1 parent b09e519 commit 7ad8fde

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ CCANDIR := ccan
2424

2525
# Where we keep the BOLT RFCs
2626
BOLTDIR := ../lightning-rfc/
27-
BOLTVERSION := 886bf7a430db706b483b7b02d64a82bf175c0b46
27+
BOLTVERSION := b4132ff24025742ad8e175d52b68380520e9f0b7
2828

2929
-include config.vars
3030

common/bolt11.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,8 @@ static char *decode_x(struct bolt11 *b11,
248248
/* BOLT #11:
249249
*
250250
* `c` (24): `data_length` variable. `min_final_cltv_expiry` to use for the
251-
* last HTLC in the route. Default is 9 if not specified.
251+
* last HTLC in the route. Default is 18 if not specified.
252252
*/
253-
#define DEFAULT_C 9
254253
static char *decode_c(struct bolt11 *b11,
255254
struct hash_u5 *hu5,
256255
u5 **data, size_t *data_len,
@@ -536,7 +535,11 @@ struct bolt11 *new_bolt11(const tal_t *ctx,
536535
b11->msat = NULL;
537536
b11->expiry = DEFAULT_X;
538537
b11->features = tal_arr(b11, u8, 0);
539-
b11->min_final_cltv_expiry = DEFAULT_C;
538+
/* BOLT #11:
539+
* - if the `c` field (`min_final_cltv_expiry`) is not provided:
540+
* - MUST use an expiry delta of at least 18 when making the payment
541+
*/
542+
b11->min_final_cltv_expiry = 18;
540543
b11->payment_secret = NULL;
541544

542545
if (msat)
@@ -861,8 +864,8 @@ static void push_field(u5 **data, char type, const void *src, size_t nbits)
861864
*
862865
* - if `x` is included:
863866
* - SHOULD use the minimum `data_length` possible.
867+
* - MUST include one `c` field (`min_final_cltv_expiry`).
864868
*...
865-
* - if `c` is included:
866869
* - SHOULD use the minimum `data_length` possible.
867870
*/
868871
static void push_varlen_field(u5 **data, char type, u64 val)
@@ -1095,8 +1098,10 @@ char *bolt11_encode_(const tal_t *ctx,
10951098
if (b11->expiry != DEFAULT_X)
10961099
encode_x(&data, b11->expiry);
10971100

1098-
if (b11->min_final_cltv_expiry != DEFAULT_C)
1099-
encode_c(&data, b11->min_final_cltv_expiry);
1101+
/* BOLT #11:
1102+
* - MUST include one `c` field (`min_final_cltv_expiry`).
1103+
*/
1104+
encode_c(&data, b11->min_final_cltv_expiry);
11001105

11011106
if (b11->payment_secret)
11021107
encode_s(&data, b11->payment_secret);

common/test/run-bolt11.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ static void test_b11(const char *b11str,
119119
}
120120
assert(!expect_extra);
121121

122+
/* FIXME: Spec changed to require c fields, but test vectors don't! */
123+
if (b11->min_final_cltv_expiry == 18)
124+
return;
125+
122126
/* Re-encode to check */
123127
reproduce = bolt11_encode(tmpctx, b11, false, test_sign, NULL);
124128
for (size_t i = 0; i < strlen(reproduce); i++) {
@@ -294,7 +298,7 @@ int main(void)
294298
strlen("850aeaf5f69670e8889936fc2e0cff3ceb0c3b5eab8f04ae57767118db673a91"),
295299
&b11->payment_hash, sizeof(b11->payment_hash)))
296300
abort();
297-
b11->min_final_cltv_expiry = 9;
301+
b11->min_final_cltv_expiry = 18;
298302
b11->receiver_id = node;
299303
b11->description = "Payment request with multipart support";
300304
b11->expiry = 28800;
@@ -454,7 +458,7 @@ int main(void)
454458
/* This one can be encoded, but not decoded */
455459
set_feature_bit(&b11->features, 100);
456460
badstr = bolt11_encode(tmpctx, b11, false, test_sign, NULL);
457-
assert(streq(badstr, "lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeessp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q4psqqqqqqqqqqqqqqqpqsqq40wa3khl49yue3zsgm26jrepqr2eghqlx86rttutve3ugd05em86nsefzh4pfurpd9ek9w2vp95zxqnfe2u7ckudyahsa52q66tgzcp6t2dyk"));
461+
assert(streq(badstr, "lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeescqpjsp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q4psqqqqqqqqqqqqqqqpqsq0hxcz4sktfhmyqsedyuf79vyhah4kv3ruth2hrpvd8tnsceqwj592r4a6w5x2vh5cr4jadanl6qu8lqs8ggxr0pax8mdlwjm2hyyg7gpe7cxue"));
458462
/* Empty set of allowed bits, ensures this fails! */
459463
fset = tal(tmpctx, struct feature_set);
460464
fset->bits[BOLT11_FEATURE] = tal_arr(fset, u8, 0);

tests/test_invoices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def test_decode_unknown(node_factory):
584584
assert b11['description'] == 'Payment request with multipart support'
585585
assert b11['expiry'] == 28800
586586
assert b11['payee'] == '02330d13587b67a85c0a36ea001c4dba14bcd48dda8988f7303275b040bffb6abd'
587-
assert b11['min_final_cltv_expiry'] == 9
587+
assert b11['min_final_cltv_expiry'] == 18
588588
extra = only_one(b11['extra'])
589589
assert extra['tag'] == 'v'
590590
assert extra['data'] == 'dp68gup69uhnzwfj9cejuvf3xshrwde68qcrswf0d46kcarfwpshyaplw3skw0tdw4k8g6tsv9e8g'

0 commit comments

Comments
 (0)