Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOLT updates to latest #3959

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CCANDIR := ccan

# Where we keep the BOLT RFCs
BOLTDIR := ../lightning-rfc/
BOLTVERSION := 9e8e29af9b9a922eb114b2c716205d0772946e56
BOLTVERSION := 7e8c478aef0d23a445845b7d297b0e804583697c

-include config.vars

Expand Down
6 changes: 3 additions & 3 deletions bitcoin/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,17 +552,17 @@ 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
* block csv lock.
*
* <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>
*/
Expand Down
16 changes: 8 additions & 8 deletions bitcoin/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version,
return script;
}

/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3:
/* BOLT #3:
*
* #### `to_remote` Output
*
Expand Down Expand Up @@ -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 <RIPEMD160(SHA256(revocationpubkey))> OP_EQUAL
Expand All @@ -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
Expand Down Expand Up @@ -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 <RIPEMD160(SHA256(revocationpubkey))> OP_EQUAL
Expand All @@ -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
Expand Down Expand Up @@ -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)
*...
* <local_funding_pubkey/remote_funding_pubkey> OP_CHECKSIG OP_IFDUP
Expand Down
2 changes: 1 addition & 1 deletion channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions channeld/commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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++) {
Expand All @@ -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++) {
Expand All @@ -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).
*/
Expand All @@ -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).
*/
Expand All @@ -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
*
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion channeld/test/run-commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions common/bolt11.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -651,7 +654,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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion common/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 1 addition & 5 deletions common/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion common/gossip_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion common/htlc_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions common/htlc_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Loading