From 5211b31a492db730dfb3f86e265415a5a93ae25b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 20 Aug 2020 16:19:27 +0930 Subject: [PATCH 1/5] doc: update bolt version And sweep through and remove git qualifiers from many BOLT strings. Signed-off-by: Rusty Russell --- Makefile | 2 +- common/bolt11.c | 2 +- common/sphinx.c | 6 +++--- common/test/run-bolt11.c | 21 +++++++++++---------- connectd/peer_exchange_initmsg.c | 4 ++-- lightningd/peer_control.c | 19 +++++++++---------- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index b5a3eda677ba..fdb163f49dfa 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ CCANDIR := ccan # Where we keep the BOLT RFCs BOLTDIR := ../lightning-rfc/ -BOLTVERSION := 9e8e29af9b9a922eb114b2c716205d0772946e56 +BOLTVERSION := f8ef3b42221295f3913aa1b0663221dadd5776f6 -include config.vars diff --git a/common/bolt11.c b/common/bolt11.c index fb1be40e13d9..f6aa4689bf5e 100644 --- a/common/bolt11.c +++ b/common/bolt11.c @@ -651,7 +651,7 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str, * amount required for payment. */ b11->msat = tal(b11, struct amount_msat); - /* BOLT-50143e388e16a449a92ed574fc16eb35b51426b9 #11: + /* BOLT #11: * * - if multiplier is `p` and the last decimal of `amount` is * not 0: diff --git a/common/sphinx.c b/common/sphinx.c index 472ad37f59cd..31a7d623551a 100644 --- a/common/sphinx.c +++ b/common/sphinx.c @@ -479,10 +479,10 @@ struct onionpacket *create_onionpacket( packet->version = 0; memset(nexthmac.bytes, 0, sizeof(nexthmac.bytes)); - /* BOLT-e116441ee836447ac3f24cdca62bac1e0f223d5f #4: + /* BOLT #4: * - * The packet is initialized with 1366 _random_ bytes derived from a - * CSPRNG. + * The packet is initialized with 1300 _random_ bytes derived from a + * CSPRNG */ /* Note that this is just hop_payloads: the rest of the packet is * overwritten below or above anyway. */ diff --git a/common/test/run-bolt11.c b/common/test/run-bolt11.c index 5068ab3bbde1..9b2258e4a02b 100644 --- a/common/test/run-bolt11.c +++ b/common/test/run-bolt11.c @@ -349,7 +349,7 @@ int main(void) test_b11("lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeessp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q5sqqqqqqqqqqqqqqqpqsq67gye39hfg3zd8rgc80k32tvy9xk2xunwm5lzexnvpx6fd77en8qaq424dxgt56cag2dpt359k3ssyhetktkpqh24jqnjyw6uqd08sgptq44qu", b11, NULL); - /* BOLT-4e228a7fb4ea78af914d1ce82a63cbce8026279e #11 + /* BOLT #11 * * > ### Same, but including fields which must be ignored. * > lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeessp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q5sqqqqqqqqqqqqqqqpqsq2qrqqqfppnqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqppnqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpp4qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhpnqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhp4qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqspnqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqsp4qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnp5qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnpkqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq2jxxfsnucm4jf4zwtznpaxphce606fvhvje5x7d4gw7n73994hgs7nteqvenq8a4ml8aqtchv5d9pf7l558889hp4yyrqv6a7zpq9fgpskqhza @@ -472,7 +472,8 @@ int main(void) set_feature_bit(&fset->bits[BOLT11_FEATURE], 101); assert(bolt11_decode(tmpctx, badstr, fset, NULL, &fail)); - /* BOLT-1fbccd30bb503203e4a255de67f9adb504563425 #11: + /* FIXME: quoting description in here causes a spurious mismatch! */ + /* BOLT #11: * * > ### Please send 0.00967878534 BTC for a list of items within one week, amount in pico-BTC * > lnbc9678785340p1pwmna7lpp5gc3xfm08u9qy06djf8dfflhugl6p7lgza6dsjxq454gxhj9t7a0sd8dgfkx7cmtwd68yetpd5s9xar0wfjn5gpc8qhrsdfq24f5ggrxdaezqsnvda3kkum5wfjkzmfqf3jkgem9wgsyuctwdus9xgrcyqcjcgpzgfskx6eqf9hzqnteypzxz7fzypfhg6trddjhygrcyqezcgpzfysywmm5ypxxjemgw3hxjmn8yptk7untd9hxwg3q2d6xjcmtv4ezq7pqxgsxzmnyyqcjqmt0wfjjq6t5v4khxxqyjw5qcqp2rzjq0gxwkzc8w6323m55m4jyxcjwmy7stt9hwkwe2qxmy8zpsgg7jcuwz87fcqqeuqqqyqqqqlgqqqqn3qq9qn07ytgrxxzad9hc4xt3mawjjt8znfv8xzscs7007v9gh9j569lencxa8xeujzkxs0uamak9aln6ez02uunw6rd2ht2sqe4hz8thcdagpleym0j @@ -488,7 +489,7 @@ int main(void) * * `gc3xfm08u9qy06djf8dfflhugl6p7lgza6dsjxq454gxhj9t7a0s`: payment hash 462264ede7e14047e9b249da94fefc47f41f7d02ee9b091815a5506bc8abf75f * * `d`: short description * * `8d`: `data_length` (`8` = 7, `d` = 13; 7 * 32 + 13 == 237) - * * `gfkx7cmtwd68yetpd5s9xar0wfjn5gpc8qhrsdfq24f5ggrxdaezqsnvda3kkum5wfjkzmfqf3jkgem9wgsyuctwdus9xgrcyqcjcgpzgfskx6eqf9hzqnteypzxz7fzypfhg6trddjhygrcyqezcgpzfysywmm5ypxxjemgw3hxjmn8yptk7untd9hxwg3q2d6xjcmtv4ezq7pqxgsxzmnyyqcjqmt0wfjjq6t5v4khx`: 'Blockstream Store: 88.85 USD for Blockstream Ledger Nano S x 1, \"Back In My Day\" Sticker x 2, \"I Got Lightning Working\" Sticker x 2 and 1 more items' + * * `gfkx7cmtwd68yetpd5s9xar0wfjn5gpc8qhrsdfq24f5ggrxdaezqsnvda3kkum5wfjkzmfqf3jkgem9wgsyuctwdus9xgrcyqcjcgpzgfskx6eqf9hzqnteypzxz7fzypfhg6trddjhygrcyqezcgpzfysywmm5ypxxjemgw3hxjmn8yptk7untd9hxwg3q2d6xjcmtv4ezq7pqxgsxzmnyyqcjqmt0wfjjq6t5v4khx`: ... * * `x`: expiry time * * `qy`: `data_length` (`q` = 0, `y` = 2; 0 * 32 + 4 == 4) * * `jw5q`: 604800 seconds (`j` = 18, `w` = 14, `5` = 20, `q` = 0; 18 * 32^3 + 14 * 32^2 + 20 * 32 + 0 == 604800) @@ -530,7 +531,7 @@ int main(void) b11->routes[0]->cltv_expiry_delta = 40; test_b11("lnbc9678785340p1pwmna7lpp5gc3xfm08u9qy06djf8dfflhugl6p7lgza6dsjxq454gxhj9t7a0sd8dgfkx7cmtwd68yetpd5s9xar0wfjn5gpc8qhrsdfq24f5ggrxdaezqsnvda3kkum5wfjkzmfqf3jkgem9wgsyuctwdus9xgrcyqcjcgpzgfskx6eqf9hzqnteypzxz7fzypfhg6trddjhygrcyqezcgpzfysywmm5ypxxjemgw3hxjmn8yptk7untd9hxwg3q2d6xjcmtv4ezq7pqxgsxzmnyyqcjqmt0wfjjq6t5v4khxxqyjw5qcqp2rzjq0gxwkzc8w6323m55m4jyxcjwmy7stt9hwkwe2qxmy8zpsgg7jcuwz87fcqqeuqqqyqqqqlgqqqqn3qq9qn07ytgrxxzad9hc4xt3mawjjt8znfv8xzscs7007v9gh9j569lencxa8xeujzkxs0uamak9aln6ez02uunw6rd2ht2sqe4hz8thcdagpleym0j", b11, NULL); - /* BOLT-4e228a7fb4ea78af914d1ce82a63cbce8026279e #11: + /* BOLT #11: * * > ### Bech32 checksum is invalid. * > lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrnt @@ -538,41 +539,41 @@ int main(void) assert(!bolt11_decode(tmpctx, "lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrnt", NULL, NULL, &fail)); assert(streq(fail, "Bad bech32 string")); - /* BOLT-4e228a7fb4ea78af914d1ce82a63cbce8026279e #11: + /* BOLT #11: * > ### Malformed bech32 string (no 1) * > pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny */ assert(!bolt11_decode(tmpctx, "pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny", NULL, NULL, &fail)); assert(streq(fail, "Bad bech32 string")); - /* BOLT-4e228a7fb4ea78af914d1ce82a63cbce8026279e #11: + /* BOLT #11: * > ### Malformed bech32 string (mixed case) * > LNBC2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny */ assert(!bolt11_decode(tmpctx, "LNBC2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny", NULL, NULL, &fail)); assert(streq(fail, "Bad bech32 string")); - /* BOLT-4e228a7fb4ea78af914d1ce82a63cbce8026279e #11: + /* BOLT #11: * > ### Signature is not recoverable. * > lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaxtrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspk28uwq */ assert(!bolt11_decode(tmpctx, "lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaxtrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspk28uwq", NULL, NULL, &fail)); assert(streq(fail, "signature recovery failed")); - /* BOLT-4e228a7fb4ea78af914d1ce82a63cbce8026279e #11: + /* BOLT #11: * > ### String is too short. * > lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6na6hlh */ assert(!bolt11_decode(tmpctx, "lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6na6hlh", NULL, NULL, &fail)); - /* BOLT-4e228a7fb4ea78af914d1ce82a63cbce8026279e #11: + /* BOLT #11: * > ### Invalid multiplier * > lnbc2500x1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpujr6jxr9gq9pv6g46y7d20jfkegkg4gljz2ea2a3m9lmvvr95tq2s0kvu70u3axgelz3kyvtp2ywwt0y8hkx2869zq5dll9nelr83zzqqpgl2zg */ assert(!bolt11_decode(tmpctx, "lnbc2500x1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpujr6jxr9gq9pv6g46y7d20jfkegkg4gljz2ea2a3m9lmvvr95tq2s0kvu70u3axgelz3kyvtp2ywwt0y8hkx2869zq5dll9nelr83zzqqpgl2zg", NULL, NULL, &fail)); assert(streq(fail, "Invalid amount postfix 'x'")); - /* BOLT- #11: + /* BOLT #11: * > ### Invalid sub-millisatoshi precision. * > lnbc2500000001p1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpu7hqtk93pkf7sw55rdv4k9z2vj050rxdr6za9ekfs3nlt5lr89jqpdmxsmlj9urqumg0h9wzpqecw7th56tdms40p2ny9q4ddvjsedzcplva53s */ diff --git a/connectd/peer_exchange_initmsg.c b/connectd/peer_exchange_initmsg.c index 78114b1f3c37..06d748f66314 100644 --- a/connectd/peer_exchange_initmsg.c +++ b/connectd/peer_exchange_initmsg.c @@ -68,7 +68,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn, return io_close(conn); } - /* BOLT-ef7c97c02b6fa67a1df1af30b3843eb576100ebd #1: + /* BOLT #1: * The receiving node: * ... * - upon receiving `networks` containing no common chains @@ -151,7 +151,7 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn, peer->addr = *addr; peer->cs = *cs; - /* BOLT-ef7c97c02b6fa67a1df1af30b3843eb576100ebd #1: + /* BOLT #1: * * The sending node: * - MUST send `init` as the first Lightning message for any diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 79d280b685c5..84532ddeabfc 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -563,17 +563,16 @@ static struct amount_sat commit_txfee(const struct channel *channel, /* * BOLT-f5490f17d17ff49dc26ee459432b3c9db4fda8a9 #2: - * Adding an HTLC: update_add_htlc - * * A sending node: - * - if it is responsible for paying the Bitcoin fee: - * - SHOULD NOT offer amount_msat if, after adding that HTLC to its - * commitment transaction, its remaining balance doesn't allow it - * to pay the fee for a future additional non-dust HTLC at a - * higher feerate while maintaining its channel reserve - * ("fee spike buffer"). A buffer of 2*feerate_per_kw is - * recommended to ensure predictability. - */ + *... + * - SHOULD NOT offer `amount_msat` if, after adding that HTLC to its + * commitment transaction, its remaining balance doesn't allow it to + * pay the commitment transaction fee when receiving or sending a + * future additional non-dust HTLC while maintaining its channel + * reserve. It is recommended that this "fee spike buffer" can + * handle twice the current `feerate_per_kw` to ensure + * predictability between implementations. + */ fee = commit_tx_base_fee(2 * feerate, num_untrimmed_htlcs + 1, channel->option_anchor_outputs); From 203e3d602eea4d26d5d72760e6fa2b31bc2b206f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 20 Aug 2020 16:19:47 +0930 Subject: [PATCH 2/5] doc: update BOLT now option_anchor_outputs is merged. Signed-off-by: Rusty Russell --- Makefile | 2 +- bitcoin/psbt.c | 6 +++--- bitcoin/script.c | 16 ++++++++-------- channeld/channeld.c | 2 +- channeld/commit_tx.c | 30 ++++++++++++++++-------------- channeld/full_channel.c | 8 ++++---- channeld/test/run-commit_tx.c | 2 +- common/features.c | 2 +- common/features.h | 6 +----- common/htlc_tx.c | 2 +- common/htlc_tx.h | 4 ++-- common/initial_commit_tx.c | 34 +++++++++++++++++++--------------- common/initial_commit_tx.h | 2 +- common/key_derive.c | 7 ++++--- common/keyset.c | 8 +++++--- hsmd/hsmd.c | 7 ++++--- onchaind/onchaind.c | 12 +++++++----- 17 files changed, 79 insertions(+), 71 deletions(-) diff --git a/Makefile b/Makefile index fdb163f49dfa..991b146e60a9 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ CCANDIR := ccan # Where we keep the BOLT RFCs BOLTDIR := ../lightning-rfc/ -BOLTVERSION := f8ef3b42221295f3913aa1b0663221dadd5776f6 +BOLTVERSION := c053ce7afb4cbf88615877a0d5fc7b8dbe2b9ba0 -include config.vars diff --git a/bitcoin/psbt.c b/bitcoin/psbt.c index e417c5d47c30..319c5cf391da 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -552,9 +552,8 @@ struct wally_tx *psbt_finalize(struct wally_psbt *psbt, bool finalize_in_place) if (input->signatures.num_items != 1) continue; - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + /* BOLT #3: * #### `to_remote` Output - *... * * If `option_anchor_outputs` applies to the commitment * transaction, the `to_remote` output is encumbered by a one @@ -562,7 +561,8 @@ struct wally_tx *psbt_finalize(struct wally_psbt *psbt, bool finalize_in_place) * * OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY * - * The output is spent by a transaction with `nSequence` field set to `1` and witness: + * The output is spent by an input with `nSequence` + * field set to `1` and witness: * * */ diff --git a/bitcoin/script.c b/bitcoin/script.c index 1f4f03b301d3..d10fa6b5f946 100644 --- a/bitcoin/script.c +++ b/bitcoin/script.c @@ -322,7 +322,7 @@ u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version, return script; } -/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: +/* BOLT #3: * * #### `to_remote` Output * @@ -537,7 +537,8 @@ u8 *bitcoin_wscript_to_local(const tal_t *ctx, u16 to_self_delay, * * This output sends funds to either an HTLC-timeout transaction after the * HTLC-timeout or to the remote node using the payment preimage or the - * revocation key. The output is a P2WSH, with a witness script: + * revocation key. The output is a P2WSH, with a witness script (no + * option_anchor_outputs): * * # To remote node with revocation key * OP_DUP OP_HASH160 OP_EQUAL @@ -554,8 +555,7 @@ u8 *bitcoin_wscript_to_local(const tal_t *ctx, u16 to_self_delay, * OP_CHECKSIG * OP_ENDIF * OP_ENDIF - */ -/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + * * Or, with `option_anchor_outputs`: * * # To remote node with revocation key @@ -644,7 +644,8 @@ u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx, * * This output sends funds to either the remote node after the HTLC-timeout or * using the revocation key, or to an HTLC-success transaction with a - * successful payment preimage. The output is a P2WSH, with a witness script: + * successful payment preimage. The output is a P2WSH, with a witness script + * (no `option_anchor_outputs`): * * # To remote node with revocation key * OP_DUP OP_HASH160 OP_EQUAL @@ -663,8 +664,7 @@ u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx, * OP_CHECKSIG * OP_ENDIF * OP_ENDIF - */ -/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + * * Or, with `option_anchor_outputs`: * * # To remote node with revocation key @@ -832,7 +832,7 @@ u8 *bitcoin_wscript_anchor(const tal_t *ctx, { u8 *script = tal_arr(ctx, u8, 0); - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + /* BOLT #3: * #### `to_local_anchor` and `to_remote_anchor` Output (option_anchor_outputs) *... * OP_CHECKSIG OP_IFDUP diff --git a/channeld/channeld.c b/channeld/channeld.c index a89e1903cb61..1a34b90c03c7 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -949,7 +949,7 @@ static struct bitcoin_signature *unraw_sigs(const tal_t *ctx, for (size_t i = 0; i < tal_count(raw); i++) { sigs[i].s = raw[i]; - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + /* BOLT #3: * ## HTLC-Timeout and HTLC-Success Transactions *... * * if `option_anchor_outputs` applies to this commitment diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index f9d8508b4420..16ec4df62d1d 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -141,7 +141,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, SUPERVERBOSE("# base commitment transaction fee = %s\n", type_to_string(tmpctx, struct amount_sat, &base_fee)); - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1: + /* BOLT #3: * If `option_anchor_outputs` applies to the commitment * transaction, also subtract two times the fixed anchor size * of 330 sats from the funder (either `to_local` or @@ -155,7 +155,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, /* BOLT #3: * * 3. Subtract this base fee from the funder (either `to_local` or - * `to_remote`), with a floor of 0 (see [Fee Payment](#fee-payment)). + * `to_remote`). */ try_subtract_fee(opener, side, base_fee, &self_pay, &other_pay); @@ -194,7 +194,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, n = 0; /* BOLT #3: * - * 3. For every offered HTLC, if it is not trimmed, add an + * 4. For every offered HTLC, if it is not trimmed, add an * [offered HTLC output](#offered-htlc-outputs). */ for (i = 0; i < tal_count(htlcs); i++) { @@ -212,7 +212,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, /* BOLT #3: * - * 4. For every received HTLC, if it is not trimmed, add an + * 5. For every received HTLC, if it is not trimmed, add an * [received HTLC output](#received-htlc-outputs). */ for (i = 0; i < tal_count(htlcs); i++) { @@ -230,7 +230,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, /* BOLT #3: * - * 5. If the `to_local` amount is greater or equal to + * 6. If the `to_local` amount is greater or equal to * `dust_limit_satoshis`, add a [`to_local` * output](#to_local-output). */ @@ -254,7 +254,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, /* BOLT #3: * - * 6. If the `to_remote` amount is greater or equal to + * 7. If the `to_remote` amount is greater or equal to * `dust_limit_satoshis`, add a [`to_remote` * output](#to_remote-output). */ @@ -263,7 +263,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, u8 *scriptpubkey; int pos; - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + /* BOLT #3: * * #### `to_remote` Output * @@ -298,19 +298,21 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, } else to_remote = false; + /* BOLT #3: + * + * 8. If `option_anchor_outputs` applies to the commitment transaction: + * * if `to_local` exists or there are untrimmed HTLCs, add a + * `to_local_anchor` output + * * if `to_remote` exists or there are untrimmed HTLCs, add a + * `to_remote_anchor` output + */ if (option_anchor_outputs) { - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: - * if `to_local` exists or there are untrimmed HTLCs, add a `to_local_anchor` output - */ if (to_local || untrimmed != 0) { tx_add_anchor_output(tx, local_funding_key); (*htlcmap)[n] = NULL; n++; } - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: - * if `to_remote` exists or there are untrimmed HTLCs, add a `to_remote_anchor` output - */ if (to_remote || untrimmed != 0) { tx_add_anchor_output(tx, remote_funding_key); (*htlcmap)[n] = NULL; @@ -331,7 +333,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, /* BOLT #3: * - * 7. Sort the outputs into [BIP 69+CLTV + * 9. Sort the outputs into [BIP 69+CLTV * order](#transaction-input-and-output-ordering) */ permute_outputs(tx, cltvs, (const void **)*htlcmap); diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 94ae93126ff5..32de0420d5ec 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -618,7 +618,7 @@ static enum channel_add_err add_htlc(struct channel *channel, *... * - receiving an `amount_msat` that the sending node cannot afford at * the current `feerate_per_kw` (while maintaining its channel - * reserve): + * reserve and any `to_local_anchor` and `to_remote_anchor` costs): * - SHOULD fail the channel. */ if (enforce_aggregate_limits) { @@ -643,7 +643,7 @@ static enum channel_add_err add_htlc(struct channel *channel, &remainder)) return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED; - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1: + /* BOLT #3: * If `option_anchor_outputs` applies to the commitment * transaction, also subtract two times the fixed anchor size * of 330 sats from the funder (either `to_local` or @@ -1027,7 +1027,7 @@ u32 approx_max_feerate(const struct channel *channel) /* Available is their view */ avail = amount_msat_to_sat_round_down(channel->view[!channel->opener].owed[channel->opener]); - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1: + /* BOLT #3: * If `option_anchor_outputs` applies to the commitment * transaction, also subtract two times the fixed anchor size * of 330 sats from the funder (either `to_local` or @@ -1068,7 +1068,7 @@ bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw fee = commit_tx_base_fee(feerate_per_kw, untrimmed, channel->option_anchor_outputs); - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1: + /* BOLT #3: * If `option_anchor_outputs` applies to the commitment * transaction, also subtract two times the fixed anchor size * of 330 sats from the funder (either `to_local` or diff --git a/channeld/test/run-commit_tx.c b/channeld/test/run-commit_tx.c index 85391b8f40f6..3204a15006f7 100644 --- a/channeld/test/run-commit_tx.c +++ b/channeld/test/run-commit_tx.c @@ -994,7 +994,7 @@ int main(int argc, const char *argv[]) = commit_tx_base_fee(feerate_per_kw, 0, option_anchor_outputs); - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1: + /* BOLT #3: * If `option_anchor_outputs` applies to the commitment * transaction, also subtract two times the fixed anchor size * of 330 sats from the funder (either `to_local` or diff --git a/common/features.c b/common/features.c index 1b2ecdd27001..6a022079d563 100644 --- a/common/features.c +++ b/common/features.c @@ -99,7 +99,7 @@ static const struct dependency feature_deps[] = { { OPT_GOSSIP_QUERIES_EX, OPT_GOSSIP_QUERIES }, { OPT_PAYMENT_SECRET, OPT_VAR_ONION }, { OPT_BASIC_MPP, OPT_PAYMENT_SECRET }, - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #9: + /* BOLT #9: * Name | Description | Context | Dependencies | *... * `option_anchor_outputs` | ... | ... | `option_static_remotekey` diff --git a/common/features.h b/common/features.h index f346fd016c37..a1af6b71867f 100644 --- a/common/features.h +++ b/common/features.h @@ -102,15 +102,11 @@ u8 *featurebits_or(const tal_t *ctx, const u8 *f1 TAKES, const u8 *f2 TAKES); * | 14/15 | `payment_secret` |... IN9 ... * | 16/17 | `basic_mpp` |... IN9 ... * | 18/19 | `option_support_large_channel` |... IN ... + * | 20/21 | `option_anchor_outputs` |... IN ... */ #define OPT_PAYMENT_SECRET 14 #define OPT_BASIC_MPP 16 #define OPT_LARGE_CHANNELS 18 - -/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #9: - * - * | 20/21 | `option_anchor_outputs` |... IN ... - */ #define OPT_ANCHOR_OUTPUTS 20 /* BOLT-9fc25cfd2895578c0b1ab701ebe6c1eb67a19623 #9: diff --git a/common/htlc_tx.c b/common/htlc_tx.c index 5dde9fac7bbb..030ae70fcf6e 100644 --- a/common/htlc_tx.c +++ b/common/htlc_tx.c @@ -39,7 +39,7 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx, */ assert(tx->wtx->version == 2); - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + /* BOLT #3: * * txin count: 1 * * `txin[0]` outpoint: `txid` of the commitment transaction and * `output_index` of the matching HTLC output for the HTLC diff --git a/common/htlc_tx.h b/common/htlc_tx.h index 963e167f0f19..018013c8aff1 100644 --- a/common/htlc_tx.h +++ b/common/htlc_tx.h @@ -44,7 +44,7 @@ static inline size_t elements_add_overhead(size_t weight, size_t incount, static inline struct amount_sat htlc_timeout_fee(u32 feerate_per_kw, bool option_anchor_outputs) { - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + /* BOLT #3: * * The fee for an HTLC-timeout transaction: * - MUST BE calculated to match: @@ -62,7 +62,7 @@ static inline struct amount_sat htlc_timeout_fee(u32 feerate_per_kw, static inline struct amount_sat htlc_success_fee(u32 feerate_per_kw, bool option_anchor_outputs) { - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + /* BOLT #3: * * The fee for an HTLC-success transaction: * - MUST BE calculated to match: diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index 7560bb1e1f13..15a34b391d03 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -64,7 +64,7 @@ void tx_add_anchor_output(struct bitcoin_tx *tx, u8 *wscript = bitcoin_wscript_anchor(tmpctx, funding_key); u8 *p2wsh = scriptpubkey_p2wsh(tmpctx, wscript); - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + /* BOLT #3: * The amount of the output is fixed at 330 sats, the default * dust limit for P2WSH. */ @@ -122,7 +122,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, base_fee = commit_tx_base_fee(feerate_per_kw, untrimmed, option_anchor_outputs); - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1: + /* BOLT: * If `option_anchor_outputs` applies to the commitment * transaction, also subtract two times the fixed anchor size * of 330 sats from the funder (either `to_local` or @@ -137,7 +137,10 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, /* BOLT #3: * * 3. Subtract this base fee from the funder (either `to_local` or - * `to_remote`), with a floor of 0 (see [Fee Payment](#fee-payment)). + * `to_remote`). + * If `option_anchor_outputs` applies to the commitment transaction, + * also subtract two times the fixed anchor size of 330 sats from the + * funder (either `to_local` or `to_remote`). */ if (!try_subtract_fee(opener, side, base_fee, &self_pay, &other_pay)) { /* BOLT #2: @@ -188,19 +191,19 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, n = 0; /* BOLT #3: * - * 3. For every offered HTLC, if it is not trimmed, add an + * 4. For every offered HTLC, if it is not trimmed, add an * [offered HTLC output](#offered-htlc-outputs). */ /* BOLT #3: * - * 4. For every received HTLC, if it is not trimmed, add an + * 5. For every received HTLC, if it is not trimmed, add an * [received HTLC output](#received-htlc-outputs). */ /* BOLT #3: * - * 5. If the `to_local` amount is greater or equal to + * 6. If the `to_local` amount is greater or equal to * `dust_limit_satoshis`, add a [`to_local` * output](#to_local-output). */ @@ -218,12 +221,12 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, /* BOLT #3: * - * 6. If the `to_remote` amount is greater or equal to + * 7. If the `to_remote` amount is greater or equal to * `dust_limit_satoshis`, add a [`to_remote` * output](#to_remote-output). */ if (amount_msat_greater_eq_sat(other_pay, dust_limit)) { - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + /* BOLT #3: * * If `option_anchor_outputs` applies to the commitment * transaction, the `to_remote` output is encumbered by a one @@ -252,19 +255,20 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, } else to_remote = false; + /* BOLT #3: + * 8. If `option_anchor_outputs` applies to the commitment transaction: + * * if `to_local` exists or there are untrimmed HTLCs, add a + * `to_local_anchor` output + * * if `to_remote` exists or there are untrimmed HTLCs, add a + * `to_remote_anchor` output + */ if (option_anchor_outputs) { - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: - * if `to_local` exists or there are untrimmed HTLCs, add a `to_local_anchor` output - */ if (to_local || untrimmed != 0) { tx_add_anchor_output(tx, &funding_key[side]); output_order[n] = NULL; n++; } - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: - * if `to_remote` exists or there are untrimmed HTLCs, add a `to_remote_anchor` output - */ if (to_remote || untrimmed != 0) { tx_add_anchor_output(tx, &funding_key[!side]); output_order[n] = NULL; @@ -276,7 +280,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, /* BOLT #3: * - * 7. Sort the outputs into [BIP 69+CLTV + * 9. Sort the outputs into [BIP 69+CLTV * order](#transaction-input-and-output-ordering) */ permute_outputs(tx, NULL, output_order); diff --git a/common/initial_commit_tx.h b/common/initial_commit_tx.h index 46da1a33457f..f5f1bfdfbac8 100644 --- a/common/initial_commit_tx.h +++ b/common/initial_commit_tx.h @@ -28,7 +28,7 @@ static inline size_t commit_tx_base_weight(size_t num_untrimmed_htlcs, { size_t weight; - /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: + /* BOLT #3: * * The base fee for a commitment transaction: * - MUST be calculated to match: diff --git a/common/key_derive.c b/common/key_derive.c index 79dc1d05be57..17c14072b1ac 100644 --- a/common/key_derive.c +++ b/common/key_derive.c @@ -14,14 +14,15 @@ * pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G * * The `localpubkey` uses the local node's `payment_basepoint`; + * The `remotepubkey` uses the remote node's `payment_basepoint`; * the `local_htlcpubkey` uses the local node's `htlc_basepoint`; * the `remote_htlcpubkey` uses the remote node's `htlc_basepoint`; * the `local_delayedpubkey` uses the local node's `delayed_payment_basepoint`; * and the `remote_delayedpubkey` uses the remote node's `delayed_payment_basepoint`. *... - * If `option_static_remotekey` is negotiated the `remotepubkey` is simply the - * remote node's `payment_basepoint`, otherwise it is calculated as above using - * the remote node's `payment_basepoint`. + * If `option_static_remotekey` or `option_anchor_outputs` is negotiated, the + * `remotepubkey` is simply the remote node's `payment_basepoint`, otherwise + * it is calculated as above using the remote node's `payment_basepoint`. */ bool derive_simple_key(const struct pubkey *basepoint, const struct pubkey *per_commitment_point, diff --git a/common/keyset.c b/common/keyset.c index bf35656ff64e..41c770ebf5d7 100644 --- a/common/keyset.c +++ b/common/keyset.c @@ -17,6 +17,7 @@ bool derive_keyset(const struct pubkey *per_commitment_point, * pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G * * The `localpubkey` uses the local node's `payment_basepoint`; + * The `remotepubkey` uses the remote node's `payment_basepoint`; * the `local_htlcpubkey` uses the local node's `htlc_basepoint`; * the `remote_htlcpubkey` uses the remote node's `htlc_basepoint`; * the `local_delayedpubkey` uses the local node's `delayed_payment_basepoint`; @@ -31,9 +32,10 @@ bool derive_keyset(const struct pubkey *per_commitment_point, * * ### `remotepubkey` Derivation * - * If `option_static_remotekey` is negotiated the `remotepubkey` - * is simply the remote node's `payment_basepoint`, otherwise it is - * calculated as above using the remote node's `payment_basepoint`. + * If `option_static_remotekey` or `option_anchor_outputs` is + * negotiated, the `remotepubkey` is simply the remote node's + * `payment_basepoint`, otherwise it is calculated as above using the + * remote node's `payment_basepoint`. */ if (option_static_remotekey) keyset->other_payment_key = other->payment; diff --git a/hsmd/hsmd.c b/hsmd/hsmd.c index 1760cf971f5b..bcd74c7768a8 100644 --- a/hsmd/hsmd.c +++ b/hsmd/hsmd.c @@ -1513,9 +1513,10 @@ static void hsm_unilateral_close_privkey(struct privkey *dst, /* BOLT #3: * - * If `option_static_remotekey` is negotiated the `remotepubkey` - * is simply the remote node's `payment_basepoint`, otherwise it is - * calculated as above using the remote node's `payment_basepoint`. + * If `option_static_remotekey` or `option_anchor_outputs` is + * negotiated, the `remotepubkey` is simply the remote node's + * `payment_basepoint`, otherwise it is calculated as above using the + * remote node's `payment_basepoint`. */ /* In our UTXO representation, this is indicated by a NULL * commitment_point. */ diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index 5ad791ab2680..ecef2acd64c0 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -415,13 +415,15 @@ static bool grind_htlc_tx_fee(struct amount_sat *fee, * * The fee for an HTLC-timeout transaction: * - MUST BE calculated to match: - * 1. Multiply `feerate_per_kw` by 663 and divide by 1000 - * (rounding down). + * 1. Multiply `feerate_per_kw` by 663 + * (666 if `option_anchor_outputs` applies) + * and divide by 1000 (rounding down). * * The fee for an HTLC-success transaction: * - MUST BE calculated to match: - * 1. Multiply `feerate_per_kw` by 703 and divide by 1000 - * (rounding down). + * 1. Multiply `feerate_per_kw` by 703 + * (706 if `option_anchor_outputs` applies) + * and divide by 1000 (rounding down). */ struct amount_sat out; @@ -2335,7 +2337,7 @@ static void handle_our_unilateral(const struct tx_parts *tx, NULL, NULL, NULL); /* BOLT #3: * - * The output is spent by a transaction with + * The output is spent by an input with * `nSequence` field set to `to_self_delay` (which can * only be valid after that duration has passed) and * witness: From 24ca7fa29156fb10a322889318c4743df0790fe1 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 20 Aug 2020 16:20:47 +0930 Subject: [PATCH 3/5] options: be more conservative with timeouts on mainnet. As per https://github.com/lightningnetwork/lightning-rfc/pull/785 Signed-off-by: Rusty Russell Changelog-Changed: config: the default CLTV expiry is now 34 blocks, and final expiry 18 blocks as per new BOLT recommendations. --- Makefile | 2 +- lightningd/options.c | 8 ++++---- lightningd/peer_htlcs.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 991b146e60a9..fc7b0fa21339 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ CCANDIR := ccan # Where we keep the BOLT RFCs BOLTDIR := ../lightning-rfc/ -BOLTVERSION := c053ce7afb4cbf88615877a0d5fc7b8dbe2b9ba0 +BOLTVERSION := 886bf7a430db706b483b7b02d64a82bf175c0b46 -include config.vars diff --git a/lightningd/options.c b/lightningd/options.c index a1dad4f2248c..2614a73ca0ba 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -639,16 +639,16 @@ static const struct config mainnet_config = { /* BOLT #2: * * 1. the `cltv_expiry_delta` for channels, `3R+2G+2S`: if in doubt, a - * `cltv_expiry_delta` of 12 is reasonable (R=2, G=1, S=2) + * `cltv_expiry_delta` of at least 34 is reasonable (R=2, G=2, S=12) */ - /* R = 2, G = 1, S = 3 */ - .cltv_expiry_delta = 14, + /* R = 2, G = 2, S = 12 */ + .cltv_expiry_delta = 34, /* BOLT #2: * * 4. the minimum `cltv_expiry` accepted for terminal payments: the * worst case for the terminal node C is `2R+G+S` blocks */ - .cltv_final = 10, + .cltv_final = 18, /* Send commit 10msec after receiving; almost immediately. */ .commit_time_ms = 10, diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 128b19269b54..e692175a3edb 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -2278,7 +2278,7 @@ void free_htlcs(struct lightningd *ld, const struct channel *channel) * * 2. the deadline for offered HTLCs: the deadline after which the channel has * to be failed and timed out on-chain. This is `G` blocks after the HTLC's - * `cltv_expiry`: 1 block is reasonable. + * `cltv_expiry`: 1 or 2 blocks is reasonable. */ static u32 htlc_out_deadline(const struct htlc_out *hout) { @@ -2290,7 +2290,7 @@ static u32 htlc_out_deadline(const struct htlc_out *hout) * 3. the deadline for received HTLCs this node has fulfilled: the deadline * after which the channel has to be failed and the HTLC fulfilled on-chain * before its `cltv_expiry`. See steps 4-7 above, which imply a deadline of - * `2R+G+S` blocks before `cltv_expiry`: 7 blocks is reasonable. + * `2R+G+S` blocks before `cltv_expiry`: 18 blocks is reasonable. */ /* We approximate this, by using half the cltv_expiry_delta (3R+2G+2S), * rounded up. */ From 0d23d490ef9bec59cf626e3824d07dd4b99acc75 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 20 Aug 2020 16:21:03 +0930 Subject: [PATCH 4/5] bolt11: update ctlv expiry, always write it. As per https://github.com/lightningnetwork/lightning-rfc/pull/785 Signed-off-by: Rusty Russell Changelog-Changed: protocol: bolt11 invoices always include CLTV fields (see lightning-rfc#785) --- Makefile | 2 +- common/bolt11.c | 17 +++++++++++------ common/test/run-bolt11.c | 8 ++++++-- tests/test_invoices.py | 2 +- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index fc7b0fa21339..439cca863141 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ CCANDIR := ccan # Where we keep the BOLT RFCs BOLTDIR := ../lightning-rfc/ -BOLTVERSION := 886bf7a430db706b483b7b02d64a82bf175c0b46 +BOLTVERSION := b4132ff24025742ad8e175d52b68380520e9f0b7 -include config.vars diff --git a/common/bolt11.c b/common/bolt11.c index f6aa4689bf5e..b69d875a3baa 100644 --- a/common/bolt11.c +++ b/common/bolt11.c @@ -248,9 +248,8 @@ static char *decode_x(struct bolt11 *b11, /* BOLT #11: * * `c` (24): `data_length` variable. `min_final_cltv_expiry` to use for the - * last HTLC in the route. Default is 9 if not specified. + * last HTLC in the route. Default is 18 if not specified. */ -#define DEFAULT_C 9 static char *decode_c(struct bolt11 *b11, struct hash_u5 *hu5, u5 **data, size_t *data_len, @@ -536,7 +535,11 @@ struct bolt11 *new_bolt11(const tal_t *ctx, b11->msat = NULL; b11->expiry = DEFAULT_X; b11->features = tal_arr(b11, u8, 0); - b11->min_final_cltv_expiry = DEFAULT_C; + /* BOLT #11: + * - if the `c` field (`min_final_cltv_expiry`) is not provided: + * - MUST use an expiry delta of at least 18 when making the payment + */ + b11->min_final_cltv_expiry = 18; b11->payment_secret = NULL; if (msat) @@ -861,8 +864,8 @@ static void push_field(u5 **data, char type, const void *src, size_t nbits) * * - if `x` is included: * - SHOULD use the minimum `data_length` possible. + * - MUST include one `c` field (`min_final_cltv_expiry`). *... - * - if `c` is included: * - SHOULD use the minimum `data_length` possible. */ static void push_varlen_field(u5 **data, char type, u64 val) @@ -1095,8 +1098,10 @@ char *bolt11_encode_(const tal_t *ctx, if (b11->expiry != DEFAULT_X) encode_x(&data, b11->expiry); - if (b11->min_final_cltv_expiry != DEFAULT_C) - encode_c(&data, b11->min_final_cltv_expiry); + /* BOLT #11: + * - MUST include one `c` field (`min_final_cltv_expiry`). + */ + encode_c(&data, b11->min_final_cltv_expiry); if (b11->payment_secret) encode_s(&data, b11->payment_secret); diff --git a/common/test/run-bolt11.c b/common/test/run-bolt11.c index 9b2258e4a02b..d8085b90ada9 100644 --- a/common/test/run-bolt11.c +++ b/common/test/run-bolt11.c @@ -119,6 +119,10 @@ static void test_b11(const char *b11str, } assert(!expect_extra); + /* FIXME: Spec changed to require c fields, but test vectors don't! */ + if (b11->min_final_cltv_expiry == 18) + return; + /* Re-encode to check */ reproduce = bolt11_encode(tmpctx, b11, false, test_sign, NULL); for (size_t i = 0; i < strlen(reproduce); i++) { @@ -294,7 +298,7 @@ int main(void) strlen("850aeaf5f69670e8889936fc2e0cff3ceb0c3b5eab8f04ae57767118db673a91"), &b11->payment_hash, sizeof(b11->payment_hash))) abort(); - b11->min_final_cltv_expiry = 9; + b11->min_final_cltv_expiry = 18; b11->receiver_id = node; b11->description = "Payment request with multipart support"; b11->expiry = 28800; @@ -454,7 +458,7 @@ int main(void) /* This one can be encoded, but not decoded */ set_feature_bit(&b11->features, 100); badstr = bolt11_encode(tmpctx, b11, false, test_sign, NULL); - assert(streq(badstr, "lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeessp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q4psqqqqqqqqqqqqqqqpqsqq40wa3khl49yue3zsgm26jrepqr2eghqlx86rttutve3ugd05em86nsefzh4pfurpd9ek9w2vp95zxqnfe2u7ckudyahsa52q66tgzcp6t2dyk")); + assert(streq(badstr, "lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeescqpjsp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q4psqqqqqqqqqqqqqqqpqsq0hxcz4sktfhmyqsedyuf79vyhah4kv3ruth2hrpvd8tnsceqwj592r4a6w5x2vh5cr4jadanl6qu8lqs8ggxr0pax8mdlwjm2hyyg7gpe7cxue")); /* Empty set of allowed bits, ensures this fails! */ fset = tal(tmpctx, struct feature_set); fset->bits[BOLT11_FEATURE] = tal_arr(fset, u8, 0); diff --git a/tests/test_invoices.py b/tests/test_invoices.py index ef0ac1241b20..83809e7dc491 100644 --- a/tests/test_invoices.py +++ b/tests/test_invoices.py @@ -584,7 +584,7 @@ def test_decode_unknown(node_factory): assert b11['description'] == 'Payment request with multipart support' assert b11['expiry'] == 28800 assert b11['payee'] == '02330d13587b67a85c0a36ea001c4dba14bcd48dda8988f7303275b040bffb6abd' - assert b11['min_final_cltv_expiry'] == 9 + assert b11['min_final_cltv_expiry'] == 18 extra = only_one(b11['extra']) assert extra['tag'] == 'v' assert extra['data'] == 'dp68gup69uhnzwfj9cejuvf3xshrwde68qcrswf0d46kcarfwpshyaplw3skw0tdw4k8g6tsv9e8g' From 6fd1cfb3c1e7484cbaa99715d6de17ea4423375b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 20 Aug 2020 16:25:22 +0930 Subject: [PATCH 5/5] gossipd: prune channels unless *both* peers have refreshed. See https://github.com/lightningnetwork/lightning-rfc/pull/767 Signed-off-by: Rusty Russell Changelog-Changed: Protocol: channels now pruned after two weeks unless both peers refresh it (see lightning-rfc#767) --- Makefile | 2 +- common/gossip_constants.h | 2 +- gossipd/gossipd.c | 2 +- gossipd/routing.c | 14 ++++++++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 439cca863141..dd28401e3623 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ CCANDIR := ccan # Where we keep the BOLT RFCs BOLTDIR := ../lightning-rfc/ -BOLTVERSION := b4132ff24025742ad8e175d52b68380520e9f0b7 +BOLTVERSION := 7e8c478aef0d23a445845b7d297b0e804583697c -include config.vars diff --git a/common/gossip_constants.h b/common/gossip_constants.h index 914dcd24f871..d23ac2d5f39a 100644 --- a/common/gossip_constants.h +++ b/common/gossip_constants.h @@ -58,7 +58,7 @@ /* BOLT #7: * * A node: - * - if a channel's latest `channel_update`s `timestamp` is older than two weeks + * - if a channel's oldest `channel_update`s `timestamp` is older than two weeks * (1209600 seconds): * - MAY prune the channel. * - MAY ignore the channel. diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index c838d4e33716..398dd7614cb4 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -725,7 +725,7 @@ static void gossip_send_keepalive_update(struct daemon *daemon, /* BOLT #7: * * A node: - * - if a channel's latest `channel_update`s `timestamp` is older than two weeks + * - if a channel's oldest `channel_update`s `timestamp` is older than two weeks * (1209600 seconds): * - MAY prune the channel. * - MAY ignore the channel. diff --git a/gossipd/routing.c b/gossipd/routing.c index 15704a43fb5a..26e8df2118bd 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -2777,10 +2777,16 @@ void route_prune(struct routing_state *rstate) if (!is_chan_public(chan)) continue; - if ((!is_halfchan_defined(&chan->half[0]) - || chan->half[0].bcast.timestamp < highwater) - && (!is_halfchan_defined(&chan->half[1]) - || chan->half[1].bcast.timestamp < highwater)) { + /* BOLT #7: + * - if a channel's oldest `channel_update`s `timestamp` is + * older than two weeks (1209600 seconds): + * - MAY prune the channel. + */ + /* This is a fancy way of saying "both ends must refresh!" */ + if (!is_halfchan_defined(&chan->half[0]) + || chan->half[0].bcast.timestamp < highwater + || !is_halfchan_defined(&chan->half[1]) + || chan->half[1].bcast.timestamp < highwater) { status_debug( "Pruning channel %s from network view (ages %"PRIu64" and %"PRIu64"s)", type_to_string(tmpctx, struct short_channel_id,