diff --git a/Makefile b/Makefile index fdb163f49..991b146e6 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 e7c0c6816..6f91e7913 100644 --- a/bitcoin/psbt.c +++ b/bitcoin/psbt.c @@ -618,9 +618,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 @@ -628,7 +627,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 1f4f03b30..d10fa6b5f 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 a89e1903c..1a34b90c0 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 f9d8508b4..16ec4df62 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 94ae93126..32de0420d 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 85391b8f4..3204a1500 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 1b2ecdd27..6a022079d 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 f346fd016..a1af6b718 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 5dde9fac7..030ae70fc 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 963e167f0..018013c8a 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 7560bb1e1..15a34b391 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 46da1a334..f5f1bfdfb 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 79dc1d05b..17c14072b 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 bf35656ff..41c770ebf 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 1760cf971..bcd74c776 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 5ad791ab2..ecef2acd6 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: