Browse Source

doc: update BOLT now option_anchor_outputs is merged.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
bump-pyln-proto
Rusty Russell 4 years ago
parent
commit
6e4e267f2c
  1. 2
      Makefile
  2. 6
      bitcoin/psbt.c
  3. 16
      bitcoin/script.c
  4. 2
      channeld/channeld.c
  5. 30
      channeld/commit_tx.c
  6. 8
      channeld/full_channel.c
  7. 2
      channeld/test/run-commit_tx.c
  8. 2
      common/features.c
  9. 6
      common/features.h
  10. 2
      common/htlc_tx.c
  11. 4
      common/htlc_tx.h
  12. 34
      common/initial_commit_tx.c
  13. 2
      common/initial_commit_tx.h
  14. 7
      common/key_derive.c
  15. 8
      common/keyset.c
  16. 7
      hsmd/hsmd.c
  17. 12
      onchaind/onchaind.c

2
Makefile

@ -24,7 +24,7 @@ CCANDIR := ccan
# Where we keep the BOLT RFCs # Where we keep the BOLT RFCs
BOLTDIR := ../lightning-rfc/ BOLTDIR := ../lightning-rfc/
BOLTVERSION := f8ef3b42221295f3913aa1b0663221dadd5776f6 BOLTVERSION := c053ce7afb4cbf88615877a0d5fc7b8dbe2b9ba0
-include config.vars -include config.vars

6
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) if (input->signatures.num_items != 1)
continue; continue;
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: /* BOLT #3:
* #### `to_remote` Output * #### `to_remote` Output
*...
* *
* If `option_anchor_outputs` applies to the commitment * If `option_anchor_outputs` applies to the commitment
* transaction, the `to_remote` output is encumbered by a one * 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)
* *
* <remote_pubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY * <remote_pubkey> 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:
* *
* <remote_sig> * <remote_sig>
*/ */

16
bitcoin/script.c

@ -322,7 +322,7 @@ u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version,
return script; return script;
} }
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: /* BOLT #3:
* *
* #### `to_remote` Output * #### `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 * 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 * 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 * # To remote node with revocation key
* OP_DUP OP_HASH160 <RIPEMD160(SHA256(revocationpubkey))> OP_EQUAL * OP_DUP OP_HASH160 <RIPEMD160(SHA256(revocationpubkey))> OP_EQUAL
@ -554,8 +555,7 @@ u8 *bitcoin_wscript_to_local(const tal_t *ctx, u16 to_self_delay,
* OP_CHECKSIG * OP_CHECKSIG
* OP_ENDIF * OP_ENDIF
* OP_ENDIF * OP_ENDIF
*/ *
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3:
* Or, with `option_anchor_outputs`: * Or, with `option_anchor_outputs`:
* *
* # To remote node with revocation key * # 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 * 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 * 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 * # To remote node with revocation key
* OP_DUP OP_HASH160 <RIPEMD160(SHA256(revocationpubkey))> OP_EQUAL * OP_DUP OP_HASH160 <RIPEMD160(SHA256(revocationpubkey))> OP_EQUAL
@ -663,8 +664,7 @@ u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx,
* OP_CHECKSIG * OP_CHECKSIG
* OP_ENDIF * OP_ENDIF
* OP_ENDIF * OP_ENDIF
*/ *
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3:
* Or, with `option_anchor_outputs`: * Or, with `option_anchor_outputs`:
* *
* # To remote node with revocation key * # 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); u8 *script = tal_arr(ctx, u8, 0);
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: /* BOLT #3:
* #### `to_local_anchor` and `to_remote_anchor` Output (option_anchor_outputs) * #### `to_local_anchor` and `to_remote_anchor` Output (option_anchor_outputs)
*... *...
* <local_funding_pubkey/remote_funding_pubkey> OP_CHECKSIG OP_IFDUP * <local_funding_pubkey/remote_funding_pubkey> OP_CHECKSIG OP_IFDUP

2
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++) { for (size_t i = 0; i < tal_count(raw); i++) {
sigs[i].s = raw[i]; sigs[i].s = raw[i];
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: /* BOLT #3:
* ## HTLC-Timeout and HTLC-Success Transactions * ## HTLC-Timeout and HTLC-Success Transactions
*... *...
* * if `option_anchor_outputs` applies to this commitment * * if `option_anchor_outputs` applies to this commitment

30
channeld/commit_tx.c

@ -141,7 +141,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
SUPERVERBOSE("# base commitment transaction fee = %s\n", SUPERVERBOSE("# base commitment transaction fee = %s\n",
type_to_string(tmpctx, struct amount_sat, &base_fee)); type_to_string(tmpctx, struct amount_sat, &base_fee));
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1: /* BOLT #3:
* If `option_anchor_outputs` applies to the commitment * If `option_anchor_outputs` applies to the commitment
* transaction, also subtract two times the fixed anchor size * transaction, also subtract two times the fixed anchor size
* of 330 sats from the funder (either `to_local` or * 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: /* BOLT #3:
* *
* 3. Subtract this base fee from the funder (either `to_local` or * 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); 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; n = 0;
/* BOLT #3: /* 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). * [offered HTLC output](#offered-htlc-outputs).
*/ */
for (i = 0; i < tal_count(htlcs); i++) { for (i = 0; i < tal_count(htlcs); i++) {
@ -212,7 +212,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
/* BOLT #3: /* 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). * [received HTLC output](#received-htlc-outputs).
*/ */
for (i = 0; i < tal_count(htlcs); i++) { for (i = 0; i < tal_count(htlcs); i++) {
@ -230,7 +230,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
/* BOLT #3: /* 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` * `dust_limit_satoshis`, add a [`to_local`
* output](#to_local-output). * output](#to_local-output).
*/ */
@ -254,7 +254,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
/* BOLT #3: /* 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` * `dust_limit_satoshis`, add a [`to_remote`
* output](#to_remote-output). * output](#to_remote-output).
*/ */
@ -263,7 +263,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
u8 *scriptpubkey; u8 *scriptpubkey;
int pos; int pos;
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: /* BOLT #3:
* *
* #### `to_remote` Output * #### `to_remote` Output
* *
@ -298,19 +298,21 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
} else } else
to_remote = false; to_remote = false;
if (option_anchor_outputs) { /* BOLT #3:
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: *
* if `to_local` exists or there are untrimmed HTLCs, add a `to_local_anchor` output * 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) {
if (to_local || untrimmed != 0) { if (to_local || untrimmed != 0) {
tx_add_anchor_output(tx, local_funding_key); tx_add_anchor_output(tx, local_funding_key);
(*htlcmap)[n] = NULL; (*htlcmap)[n] = NULL;
n++; n++;
} }
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3:
* if `to_remote` exists or there are untrimmed HTLCs, add a `to_remote_anchor` output
*/
if (to_remote || untrimmed != 0) { if (to_remote || untrimmed != 0) {
tx_add_anchor_output(tx, remote_funding_key); tx_add_anchor_output(tx, remote_funding_key);
(*htlcmap)[n] = NULL; (*htlcmap)[n] = NULL;
@ -331,7 +333,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
/* BOLT #3: /* BOLT #3:
* *
* 7. Sort the outputs into [BIP 69+CLTV * 9. Sort the outputs into [BIP 69+CLTV
* order](#transaction-input-and-output-ordering) * order](#transaction-input-and-output-ordering)
*/ */
permute_outputs(tx, cltvs, (const void **)*htlcmap); permute_outputs(tx, cltvs, (const void **)*htlcmap);

8
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 * - receiving an `amount_msat` that the sending node cannot afford at
* the current `feerate_per_kw` (while maintaining its channel * 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. * - SHOULD fail the channel.
*/ */
if (enforce_aggregate_limits) { if (enforce_aggregate_limits) {
@ -643,7 +643,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
&remainder)) &remainder))
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED; return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1: /* BOLT #3:
* If `option_anchor_outputs` applies to the commitment * If `option_anchor_outputs` applies to the commitment
* transaction, also subtract two times the fixed anchor size * transaction, also subtract two times the fixed anchor size
* of 330 sats from the funder (either `to_local` or * 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 */ /* Available is their view */
avail = amount_msat_to_sat_round_down(channel->view[!channel->opener].owed[channel->opener]); 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 * If `option_anchor_outputs` applies to the commitment
* transaction, also subtract two times the fixed anchor size * transaction, also subtract two times the fixed anchor size
* of 330 sats from the funder (either `to_local` or * 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, fee = commit_tx_base_fee(feerate_per_kw, untrimmed,
channel->option_anchor_outputs); channel->option_anchor_outputs);
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1: /* BOLT #3:
* If `option_anchor_outputs` applies to the commitment * If `option_anchor_outputs` applies to the commitment
* transaction, also subtract two times the fixed anchor size * transaction, also subtract two times the fixed anchor size
* of 330 sats from the funder (either `to_local` or * of 330 sats from the funder (either `to_local` or

2
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, = commit_tx_base_fee(feerate_per_kw, 0,
option_anchor_outputs); option_anchor_outputs);
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1: /* BOLT #3:
* If `option_anchor_outputs` applies to the commitment * If `option_anchor_outputs` applies to the commitment
* transaction, also subtract two times the fixed anchor size * transaction, also subtract two times the fixed anchor size
* of 330 sats from the funder (either `to_local` or * of 330 sats from the funder (either `to_local` or

2
common/features.c

@ -99,7 +99,7 @@ static const struct dependency feature_deps[] = {
{ OPT_GOSSIP_QUERIES_EX, OPT_GOSSIP_QUERIES }, { OPT_GOSSIP_QUERIES_EX, OPT_GOSSIP_QUERIES },
{ OPT_PAYMENT_SECRET, OPT_VAR_ONION }, { OPT_PAYMENT_SECRET, OPT_VAR_ONION },
{ OPT_BASIC_MPP, OPT_PAYMENT_SECRET }, { OPT_BASIC_MPP, OPT_PAYMENT_SECRET },
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #9: /* BOLT #9:
* Name | Description | Context | Dependencies | * Name | Description | Context | Dependencies |
*... *...
* `option_anchor_outputs` | ... | ... | `option_static_remotekey` * `option_anchor_outputs` | ... | ... | `option_static_remotekey`

6
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 ... * | 14/15 | `payment_secret` |... IN9 ...
* | 16/17 | `basic_mpp` |... IN9 ... * | 16/17 | `basic_mpp` |... IN9 ...
* | 18/19 | `option_support_large_channel` |... IN ... * | 18/19 | `option_support_large_channel` |... IN ...
* | 20/21 | `option_anchor_outputs` |... IN ...
*/ */
#define OPT_PAYMENT_SECRET 14 #define OPT_PAYMENT_SECRET 14
#define OPT_BASIC_MPP 16 #define OPT_BASIC_MPP 16
#define OPT_LARGE_CHANNELS 18 #define OPT_LARGE_CHANNELS 18
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #9:
*
* | 20/21 | `option_anchor_outputs` |... IN ...
*/
#define OPT_ANCHOR_OUTPUTS 20 #define OPT_ANCHOR_OUTPUTS 20
/* BOLT-9fc25cfd2895578c0b1ab701ebe6c1eb67a19623 #9: /* BOLT-9fc25cfd2895578c0b1ab701ebe6c1eb67a19623 #9:

2
common/htlc_tx.c

@ -39,7 +39,7 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
*/ */
assert(tx->wtx->version == 2); assert(tx->wtx->version == 2);
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: /* BOLT #3:
* * txin count: 1 * * txin count: 1
* * `txin[0]` outpoint: `txid` of the commitment transaction and * * `txin[0]` outpoint: `txid` of the commitment transaction and
* `output_index` of the matching HTLC output for the HTLC * `output_index` of the matching HTLC output for the HTLC

4
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, static inline struct amount_sat htlc_timeout_fee(u32 feerate_per_kw,
bool option_anchor_outputs) bool option_anchor_outputs)
{ {
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: /* BOLT #3:
* *
* The fee for an HTLC-timeout transaction: * The fee for an HTLC-timeout transaction:
* - MUST BE calculated to match: * - 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, static inline struct amount_sat htlc_success_fee(u32 feerate_per_kw,
bool option_anchor_outputs) bool option_anchor_outputs)
{ {
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: /* BOLT #3:
* *
* The fee for an HTLC-success transaction: * The fee for an HTLC-success transaction:
* - MUST BE calculated to match: * - MUST BE calculated to match:

34
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 *wscript = bitcoin_wscript_anchor(tmpctx, funding_key);
u8 *p2wsh = scriptpubkey_p2wsh(tmpctx, wscript); u8 *p2wsh = scriptpubkey_p2wsh(tmpctx, wscript);
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: /* BOLT #3:
* The amount of the output is fixed at 330 sats, the default * The amount of the output is fixed at 330 sats, the default
* dust limit for P2WSH. * 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, base_fee = commit_tx_base_fee(feerate_per_kw, untrimmed,
option_anchor_outputs); option_anchor_outputs);
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1: /* BOLT:
* If `option_anchor_outputs` applies to the commitment * If `option_anchor_outputs` applies to the commitment
* transaction, also subtract two times the fixed anchor size * transaction, also subtract two times the fixed anchor size
* of 330 sats from the funder (either `to_local` or * 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: /* BOLT #3:
* *
* 3. Subtract this base fee from the funder (either `to_local` or * 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)) { if (!try_subtract_fee(opener, side, base_fee, &self_pay, &other_pay)) {
/* BOLT #2: /* BOLT #2:
@ -188,19 +191,19 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
n = 0; n = 0;
/* BOLT #3: /* 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). * [offered HTLC output](#offered-htlc-outputs).
*/ */
/* BOLT #3: /* 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). * [received HTLC output](#received-htlc-outputs).
*/ */
/* BOLT #3: /* 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` * `dust_limit_satoshis`, add a [`to_local`
* output](#to_local-output). * output](#to_local-output).
*/ */
@ -218,12 +221,12 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
/* BOLT #3: /* 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` * `dust_limit_satoshis`, add a [`to_remote`
* output](#to_remote-output). * output](#to_remote-output).
*/ */
if (amount_msat_greater_eq_sat(other_pay, dust_limit)) { if (amount_msat_greater_eq_sat(other_pay, dust_limit)) {
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: /* BOLT #3:
* *
* If `option_anchor_outputs` applies to the commitment * If `option_anchor_outputs` applies to the commitment
* transaction, the `to_remote` output is encumbered by a one * 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 } else
to_remote = false; to_remote = false;
if (option_anchor_outputs) { /* BOLT #3:
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #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_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) {
if (to_local || untrimmed != 0) { if (to_local || untrimmed != 0) {
tx_add_anchor_output(tx, &funding_key[side]); tx_add_anchor_output(tx, &funding_key[side]);
output_order[n] = NULL; output_order[n] = NULL;
n++; n++;
} }
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3:
* if `to_remote` exists or there are untrimmed HTLCs, add a `to_remote_anchor` output
*/
if (to_remote || untrimmed != 0) { if (to_remote || untrimmed != 0) {
tx_add_anchor_output(tx, &funding_key[!side]); tx_add_anchor_output(tx, &funding_key[!side]);
output_order[n] = NULL; output_order[n] = NULL;
@ -276,7 +280,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
/* BOLT #3: /* BOLT #3:
* *
* 7. Sort the outputs into [BIP 69+CLTV * 9. Sort the outputs into [BIP 69+CLTV
* order](#transaction-input-and-output-ordering) * order](#transaction-input-and-output-ordering)
*/ */
permute_outputs(tx, NULL, output_order); permute_outputs(tx, NULL, output_order);

2
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; size_t weight;
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3: /* BOLT #3:
* *
* The base fee for a commitment transaction: * The base fee for a commitment transaction:
* - MUST be calculated to match: * - MUST be calculated to match:

7
common/key_derive.c

@ -14,14 +14,15 @@
* pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G * pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G
* *
* The `localpubkey` uses the local node's `payment_basepoint`; * 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 `local_htlcpubkey` uses the local node's `htlc_basepoint`;
* the `remote_htlcpubkey` uses the remote 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`; * the `local_delayedpubkey` uses the local node's `delayed_payment_basepoint`;
* and the `remote_delayedpubkey` uses the remote 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 * If `option_static_remotekey` or `option_anchor_outputs` is negotiated, the
* remote node's `payment_basepoint`, otherwise it is calculated as above using * `remotepubkey` is simply the remote node's `payment_basepoint`, otherwise
* the remote node's `payment_basepoint`. * it is calculated as above using the remote node's `payment_basepoint`.
*/ */
bool derive_simple_key(const struct pubkey *basepoint, bool derive_simple_key(const struct pubkey *basepoint,
const struct pubkey *per_commitment_point, const struct pubkey *per_commitment_point,

8
common/keyset.c

@ -17,6 +17,7 @@ bool derive_keyset(const struct pubkey *per_commitment_point,
* pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G * pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G
* *
* The `localpubkey` uses the local node's `payment_basepoint`; * 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 `local_htlcpubkey` uses the local node's `htlc_basepoint`;
* the `remote_htlcpubkey` uses the remote 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`; * 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 * ### `remotepubkey` Derivation
* *
* If `option_static_remotekey` is negotiated the `remotepubkey` * If `option_static_remotekey` or `option_anchor_outputs` is
* is simply the remote node's `payment_basepoint`, otherwise it is * negotiated, the `remotepubkey` is simply the remote node's
* calculated as above using the remote node's `payment_basepoint`. * `payment_basepoint`, otherwise it is calculated as above using the
* remote node's `payment_basepoint`.
*/ */
if (option_static_remotekey) if (option_static_remotekey)
keyset->other_payment_key = other->payment; keyset->other_payment_key = other->payment;

7
hsmd/hsmd.c

@ -1513,9 +1513,10 @@ static void hsm_unilateral_close_privkey(struct privkey *dst,
/* BOLT #3: /* BOLT #3:
* *
* If `option_static_remotekey` is negotiated the `remotepubkey` * If `option_static_remotekey` or `option_anchor_outputs` is
* is simply the remote node's `payment_basepoint`, otherwise it is * negotiated, the `remotepubkey` is simply the remote node's
* calculated as above using the remote node's `payment_basepoint`. * `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 /* In our UTXO representation, this is indicated by a NULL
* commitment_point. */ * commitment_point. */

12
onchaind/onchaind.c

@ -415,13 +415,15 @@ static bool grind_htlc_tx_fee(struct amount_sat *fee,
* *
* The fee for an HTLC-timeout transaction: * The fee for an HTLC-timeout transaction:
* - MUST BE calculated to match: * - MUST BE calculated to match:
* 1. Multiply `feerate_per_kw` by 663 and divide by 1000 * 1. Multiply `feerate_per_kw` by 663
* (rounding down). * (666 if `option_anchor_outputs` applies)
* and divide by 1000 (rounding down).
* *
* The fee for an HTLC-success transaction: * The fee for an HTLC-success transaction:
* - MUST BE calculated to match: * - MUST BE calculated to match:
* 1. Multiply `feerate_per_kw` by 703 and divide by 1000 * 1. Multiply `feerate_per_kw` by 703
* (rounding down). * (706 if `option_anchor_outputs` applies)
* and divide by 1000 (rounding down).
*/ */
struct amount_sat out; struct amount_sat out;
@ -2335,7 +2337,7 @@ static void handle_our_unilateral(const struct tx_parts *tx,
NULL, NULL, NULL); NULL, NULL, NULL);
/* BOLT #3: /* 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 * `nSequence` field set to `to_self_delay` (which can
* only be valid after that duration has passed) and * only be valid after that duration has passed) and
* witness: * witness:

Loading…
Cancel
Save