diff --git a/Makefile b/Makefile index 4c3dd6475..7425037fb 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ CCANDIR := ccan # Where we keep the BOLT RFCs BOLTDIR := ../lightning-rfc/ -DEFAULT_BOLTVERSION := 07c7caed516f3a39370d2467685b1a48a12e50ad +DEFAULT_BOLTVERSION := fdc078f845e1e12069a0b881e95389b3a88c4ff7 # Can be overridden on cmdline. BOLTVERSION := $(DEFAULT_BOLTVERSION) diff --git a/channeld/channeld.c b/channeld/channeld.c index 4102ddf77..67e994d78 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -1173,7 +1173,7 @@ static struct bitcoin_signature *unraw_sigs(const tal_t *ctx, /* BOLT #3: * ## HTLC-Timeout and HTLC-Success Transactions *... - * * if `option_anchor_outputs` applies to this commitment + * * if `option_anchors` applies to this commitment * transaction, `SIGHASH_SINGLE|SIGHASH_ANYONECANPAY` is * used. */ @@ -2489,7 +2489,8 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last) /* BOLT #2: * * A receiving node: - * - if `option_static_remotekey` applies to the commitment transaction: + * - if `option_static_remotekey` or `option_anchors` applies to the + * commitment transaction: * - if `next_revocation_number` is greater than expected above, AND * `your_last_per_commitment_secret` is correct for that * `next_revocation_number` minus 1: @@ -2552,7 +2553,8 @@ static void check_future_dataloss_fields(struct peer *peer, /* BOLT #2: * * A receiving node: - * - if `option_static_remotekey` applies to the commitment transaction: + * - if `option_static_remotekey` or `option_anchors` applies to the + * commitment transaction: * ... * - if `your_last_per_commitment_secret` does not match the expected values: * - SHOULD fail the channel. @@ -2764,7 +2766,7 @@ static void peer_reconnect(struct peer *peer, * of the next `commitment_signed` it expects to receive. * - MUST set `next_revocation_number` to the commitment number * of the next `revoke_and_ack` message it expects to receive. - * - if `option_static_remotekey` applies to the commitment transaction: + * - if `option_static_remotekey` or `option_anchors` applies to the commitment transaction: * - MUST set `my_current_per_commitment_point` to a valid point. * - otherwise: * - MUST set `my_current_per_commitment_point` to its commitment diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index 8718d7577..26c8cf1f8 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -147,7 +147,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, base_fee.satoshis /* Raw: spec uses raw numbers */); /* BOLT #3: - * If `option_anchor_outputs` applies to the commitment + * If `option_anchors` 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`). @@ -281,7 +281,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, * * #### `to_remote` Output * - * If `option_anchor_outputs` applies to the commitment + * If `option_anchors` applies to the commitment * transaction, the `to_remote` output is encumbered by a one * block csv lock. * OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY @@ -329,7 +329,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, /* BOLT #3: * - * 8. If `option_anchor_outputs` applies to the commitment transaction: + * 8. If `option_anchors` 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 diff --git a/channeld/full_channel.c b/channeld/full_channel.c index d3650fbbd..39fb3dacb 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -680,7 +680,7 @@ static enum channel_add_err add_htlc(struct channel *channel, return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED; /* BOLT #3: - * If `option_anchor_outputs` applies to the commitment + * If `option_anchors` 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`). @@ -1102,7 +1102,7 @@ u32 approx_max_feerate(const struct channel *channel) avail = amount_msat_to_sat_round_down(channel->view[!channel->opener].owed[channel->opener]); /* BOLT #3: - * If `option_anchor_outputs` applies to the commitment + * If `option_anchors` 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`). @@ -1143,7 +1143,7 @@ bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw channel->option_anchor_outputs); /* BOLT #3: - * If `option_anchor_outputs` applies to the commitment + * If `option_anchors` 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`). diff --git a/channeld/test/run-commit_tx.c b/channeld/test/run-commit_tx.c index 2006d7194..eb167f7d2 100644 --- a/channeld/test/run-commit_tx.c +++ b/channeld/test/run-commit_tx.c @@ -1067,7 +1067,7 @@ int main(int argc, const char *argv[]) option_anchor_outputs); /* BOLT #3: - * If `option_anchor_outputs` applies to the commitment + * If `option_anchors` 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`). diff --git a/common/htlc_tx.c b/common/htlc_tx.c index 030ae70fc..2a18dbd63 100644 --- a/common/htlc_tx.c +++ b/common/htlc_tx.c @@ -44,7 +44,7 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx, * * `txin[0]` outpoint: `txid` of the commitment transaction and * `output_index` of the matching HTLC output for the HTLC * transaction - * * `txin[0]` sequence: `0` (set to `1` for `option_anchor_outputs`) + * * `txin[0]` sequence: `0` (set to `1` for `option_anchors`) */ amount = amount_msat_to_sat_round_down(msat); bitcoin_tx_add_input(tx, commit_txid, commit_output_number, diff --git a/common/htlc_tx.h b/common/htlc_tx.h index 018013c8a..2ab1f1c42 100644 --- a/common/htlc_tx.h +++ b/common/htlc_tx.h @@ -47,7 +47,8 @@ static inline struct amount_sat htlc_timeout_fee(u32 feerate_per_kw, /* BOLT #3: * * The fee for an HTLC-timeout transaction: - * - MUST BE calculated to match: + *... + * - Otherwise, MUST BE calculated to match: * 1. Multiply `feerate_per_kw` by 663 (666 if `option_anchor_outputs` * applies) and divide by 1000 (rounding down). */ @@ -65,6 +66,7 @@ static inline struct amount_sat htlc_success_fee(u32 feerate_per_kw, /* BOLT #3: * * The fee for an HTLC-success transaction: + *... * - MUST BE calculated to match: * 1. Multiply `feerate_per_kw` by 703 (706 if `option_anchor_outputs` * applies) and divide by 1000 (rounding down). diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index ec515f06d..4cb47032a 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -143,7 +143,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, * * 3. Subtract this base fee from the funder (either `to_local` or * `to_remote`). - * If `option_anchor_outputs` applies to the commitment transaction, + * If `option_anchors` 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`). */ @@ -236,7 +236,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, if (amount_msat_greater_eq_sat(other_pay, dust_limit)) { /* BOLT #3: * - * If `option_anchor_outputs` applies to the commitment + * If `option_anchors` applies to the commitment * transaction, the `to_remote` output is encumbered by a one * block csv lock. * OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY @@ -267,7 +267,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, to_remote = false; /* BOLT #3: - * 8. If `option_anchor_outputs` applies to the commitment transaction: + * 8. If `option_anchors` 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 diff --git a/common/initial_commit_tx.h b/common/initial_commit_tx.h index 90f7dbda4..4e89f2d4d 100644 --- a/common/initial_commit_tx.h +++ b/common/initial_commit_tx.h @@ -33,7 +33,7 @@ static inline size_t commit_tx_base_weight(size_t num_untrimmed_htlcs, * * The base fee for a commitment transaction: * - MUST be calculated to match: - * 1. Start with `weight` = 724 (1124 if `option_anchor_outputs` applies). + * 1. Start with `weight` = 724 (1124 if `option_anchors` applies). */ if (option_anchor_outputs) weight = 1124; diff --git a/common/key_derive.c b/common/key_derive.c index 17c14072b..2ed74198e 100644 --- a/common/key_derive.c +++ b/common/key_derive.c @@ -20,7 +20,7 @@ * 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` or `option_anchor_outputs` is negotiated, the + * If `option_static_remotekey` or `option_anchors` 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`. */ diff --git a/common/keyset.c b/common/keyset.c index 41c770ebf..680d891c4 100644 --- a/common/keyset.c +++ b/common/keyset.c @@ -32,7 +32,7 @@ bool derive_keyset(const struct pubkey *per_commitment_point, * * ### `remotepubkey` Derivation * - * If `option_static_remotekey` or `option_anchor_outputs` is + * If `option_static_remotekey` or `option_anchors` 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`. diff --git a/devtools/mkclose.c b/devtools/mkclose.c index 3f0ebb5c1..a93e94458 100644 --- a/devtools/mkclose.c +++ b/devtools/mkclose.c @@ -121,7 +121,7 @@ int main(int argc, char *argv[]) fee = commit_tx_base_fee(feerate_per_kw, 0, option_anchor_outputs); /* BOLT #3: - * If `option_anchor_outputs` applies to the commitment + * If `option_anchors` 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`). diff --git a/hsmd/libhsmd.c b/hsmd/libhsmd.c index b1db7aac5..d43edee78 100644 --- a/hsmd/libhsmd.c +++ b/hsmd/libhsmd.c @@ -292,7 +292,7 @@ static void hsm_unilateral_close_privkey(struct privkey *dst, /* BOLT #3: * - * If `option_static_remotekey` or `option_anchor_outputs` is + * If `option_static_remotekey` or `option_anchors` 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`. @@ -1041,7 +1041,7 @@ static u8 *handle_sign_local_htlc_tx(struct hsmd_client *c, const u8 *msg_in) /* BOLT #3: * ## HTLC-Timeout and HTLC-Success Transactions *... - * * if `option_anchor_outputs` applies to this commitment transaction, + * * if `option_anchors` applies to this commitment transaction, * `SIGHASH_SINGLE|SIGHASH_ANYONECANPAY` is used. */ sign_tx_input(tx, 0, NULL, wscript, &htlc_privkey, &htlc_pubkey, @@ -1094,7 +1094,7 @@ static u8 *handle_sign_remote_htlc_tx(struct hsmd_client *c, const u8 *msg_in) /* BOLT #3: * ## HTLC-Timeout and HTLC-Success Transactions *... - * * if `option_anchor_outputs` applies to this commitment transaction, + * * if `option_anchors` applies to this commitment transaction, * `SIGHASH_SINGLE|SIGHASH_ANYONECANPAY` is used. */ sign_tx_input(tx, 0, NULL, wscript, &htlc_privkey, &htlc_pubkey, @@ -1289,7 +1289,7 @@ static u8 *handle_sign_remote_htlc_to_us(struct hsmd_client *c, /* BOLT #3: * ## HTLC-Timeout and HTLC-Success Transactions *... - * * if `option_anchor_outputs` applies to this commitment transaction, + * * if `option_anchors` applies to this commitment transaction, * `SIGHASH_SINGLE|SIGHASH_ANYONECANPAY` is used. */ return handle_sign_to_us_tx( diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 4574c5580..2a7017b13 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -231,7 +231,8 @@ void peer_start_closingd(struct channel *channel, return; } - /* BOLT #2: + /* FIXME: This is the old BOLT 2 text, which restricted the closing + * fee to cap at the final commitment fee. We still do this for now. * * The sending node: * - MUST set `fee_satoshis` less than or equal to the base diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 995acc762..fcb9fe572 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -147,12 +147,14 @@ wallet_commit_channel(struct lightningd *ld, * #### Requirements * * Both peers: - * - if `option_static_remotekey` or `option_anchor_outputs` was negotiated: - * - `option_static_remotekey` or `option_anchor_outputs` applies to all commitment - * transactions + * - if `option_static_remotekey`, `option_anchor_outputs` or + * `option_anchors_zero_fee_htlc_tx` was negotiated: + * - `option_static_remotekey`, `option_anchor_outputs` or + * `option_anchors_zero_fee_htlc_tx` applies to all commitment transactions * - otherwise: - * - `option_static_remotekey` or `option_anchor_outputs` does not apply to any commitment - * transactions + * - `option_static_remotekey`, `option_anchor_outputs` or + * `option_anchors_zero_fee_htlc_tx` does not apply to any commitment + * transactions */ /* i.e. We set it now for the channel permanently. */ if (feature_negotiated(ld->our_features, diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index b8566946f..d8a6a8152 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -612,7 +612,7 @@ static struct amount_sat commit_txfee(const struct channel *channel, if (channel->option_anchor_outputs) { /* BOLT #3: - * If `option_anchor_outputs` applies to the commitment + * If `option_anchors` 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`). diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index 5e29fafde..823247678 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -470,13 +470,17 @@ static bool grind_htlc_tx_fee(struct amount_sat *fee, /* BOLT #3: * * The fee for an HTLC-timeout transaction: - * - MUST BE calculated to match: + * - If `option_anchors_zero_fee_htlc_tx` applies: + * 1. MUST BE 0. + * - Otherwise, MUST BE calculated to match: * 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: + * - If `option_anchors_zero_fee_htlc_tx` applies: + * 1. MUST BE 0. + * - MUST BE calculated to match: * 1. Multiply `feerate_per_kw` by 703 * (706 if `option_anchor_outputs` applies) * and divide by 1000 (rounding down). @@ -517,7 +521,9 @@ static bool set_htlc_timeout_fee(struct bitcoin_tx *tx, /* BOLT #3: * * The fee for an HTLC-timeout transaction: - * - MUST BE calculated to match: + * - If `option_anchors_zero_fee_htlc_tx` applies: + * 1. MUST BE 0. + * - Otherwise, MUST BE calculated to match: * 1. Multiply `feerate_per_kw` by 663 (666 if `option_anchor_outputs` * applies) and divide by 1000 (rounding down). */ @@ -564,6 +570,8 @@ static void set_htlc_success_fee(struct bitcoin_tx *tx, /* BOLT #3: * * The fee for an HTLC-success transaction: + * - If `option_anchors_zero_fee_htlc_tx` applies: + * 1. MUST BE 0. * - MUST BE calculated to match: * 1. Multiply `feerate_per_kw` by 703 (706 if `option_anchor_outputs` * applies) and divide by 1000 (rounding down). @@ -2566,7 +2574,7 @@ static u8 *scriptpubkey_to_remote(const tal_t *ctx, * * #### `to_remote` Output * - * If `option_anchor_outputs` applies to the commitment + * If `option_anchors` applies to the commitment * transaction, the `to_remote` output is encumbered by a one * block csv lock. * OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY diff --git a/openingd/common.c b/openingd/common.c index 6bc3dd534..7326bc48b 100644 --- a/openingd/common.c +++ b/openingd/common.c @@ -63,7 +63,7 @@ bool check_config_bounds(const tal_t *ctx, } /* BOLT #2: - * - if `option_anchor_outputs` applies to this commitment + * - if `option_anchors` applies to this commitment * transaction and the sending node is the funder: * - MUST be able to additionally pay for `to_local_anchor` and * `to_remote_anchor` above its reserve. diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 55da00598..342eacbd8 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -3417,7 +3417,7 @@ static bool dualopend_handle_custommsg(const u8 *msg) /* BOLT #2: * * A receiving node: - * - if `option_static_remotekey` applies to the commitment transaction: + * - if `option_static_remotekey` or `option_anchors` applies to the commitment transaction: * - if `next_revocation_number` is greater than expected above, AND * `your_last_per_commitment_secret` is correct for that * `next_revocation_number` minus 1: diff --git a/wallet/wallet.c b/wallet/wallet.c index ab3df12ec..fc85bd982 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -896,7 +896,7 @@ wallet_htlc_sigs_load(const tal_t *ctx, struct wallet *w, u64 channelid, /* BOLT #3: * ## HTLC-Timeout and HTLC-Success Transactions *... - * * if `option_anchor_outputs` applies to this commitment + * * if `option_anchors` applies to this commitment * transaction, `SIGHASH_SINGLE|SIGHASH_ANYONECANPAY` is * used. */