Browse Source

wire: update to latest version of the spec.

The main change here is that the previously-optional open/accept
fields and reestablish fields are now compulsory (everyone was
including them anyway).  In fact, the open/accept is a TLV
because it was actually the same format.

For more details, see lightning-rfc/f068dd0d8dfa5ae75feedd99f269e23be4777381

Changelog-Removed: protocol: support for optioned form of reestablish messages now compulsory.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
paymod-01
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
93d04d08d0
  1. 2
      Makefile
  2. 2
      bitcoin/script.c
  3. 70
      channeld/channeld.c
  4. 9
      closingd/closingd.c
  5. 6
      common/bigsize.c
  6. 2
      common/decode_array.h
  7. 3
      common/features.c
  8. 2
      common/features.h
  9. 6
      common/test/run-bigsize.c
  10. 32
      gossipd/queries.c
  11. 2
      gossipd/queries.h
  12. 2
      onchaind/onchaind.c
  13. 92
      openingd/openingd.c
  14. 2
      wire/extracted_onion_wire_csv
  15. 28
      wire/extracted_peer_wire_csv
  16. 7
      wire/peer_wire.c
  17. 3
      wire/peer_wire.h
  18. 17
      wire/test/run-peer-wire.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 := 4107c69e315b4f33d5b00459bef919bcfaa64bf2 BOLTVERSION := 9e8e29af9b9a922eb114b2c716205d0772946e56
-include config.vars -include config.vars

2
bitcoin/script.c

@ -662,7 +662,7 @@ u8 *bitcoin_wscript_htlc_receive(const tal_t *ctx,
* ## HTLC-Timeout and HTLC-Success Transactions * ## HTLC-Timeout and HTLC-Success Transactions
* *
*... *...
* * `txin[0]` witness stack: `0 <remotehtlcsig> <localhtlcsig> <payment_preimage>` for HTLC-success, `0 <remotehtlcsig> <localhtlcsig> 0` for HTLC-timeout * * `txin[0]` witness stack: `0 <remotehtlcsig> <localhtlcsig> <payment_preimage>` for HTLC-success, `0 <remotehtlcsig> <localhtlcsig> <>` for HTLC-timeout
*/ */
u8 **bitcoin_witness_htlc_timeout_tx(const tal_t *ctx, u8 **bitcoin_witness_htlc_timeout_tx(const tal_t *ctx,
const struct bitcoin_signature *localhtlcsig, const struct bitcoin_signature *localhtlcsig,

70
channeld/channeld.c

@ -2204,8 +2204,7 @@ static void resend_commitment(struct peer *peer, const struct changed_htlc *last
* `your_last_per_commitment_secret` is correct for that * `your_last_per_commitment_secret` is correct for that
* `next_revocation_number` minus 1: * `next_revocation_number` minus 1:
*... *...
* - otherwise, if it supports `option_data_loss_protect`, AND the * - otherwise, if it supports `option_data_loss_protect`:
* `option_data_loss_protect` fields are present:
* - if `next_revocation_number` is greater than expected above, * - if `next_revocation_number` is greater than expected above,
* AND `your_last_per_commitment_secret` is correct for that * AND `your_last_per_commitment_secret` is correct for that
* `next_revocation_number` minus 1: * `next_revocation_number` minus 1:
@ -2266,8 +2265,7 @@ static void check_future_dataloss_fields(struct peer *peer,
* ... * ...
* - if `your_last_per_commitment_secret` does not match the expected values: * - if `your_last_per_commitment_secret` does not match the expected values:
* - SHOULD fail the channel. * - SHOULD fail the channel.
* - otherwise, if it supports `option_data_loss_protect`, AND the * - otherwise, if it supports `option_data_loss_protect`:
* `option_data_loss_protect` fields are present:
*... *...
* - otherwise (`your_last_per_commitment_secret` or * - otherwise (`your_last_per_commitment_secret` or
* `my_current_per_commitment_point` do not match the expected values): * `my_current_per_commitment_point` do not match the expected values):
@ -2440,41 +2438,33 @@ static void peer_reconnect(struct peer *peer,
* of the next `revoke_and_ack` message it expects to receive. * of the next `revoke_and_ack` message it expects to receive.
* - if `option_static_remotekey` applies to the commitment transaction: * - if `option_static_remotekey` applies to the commitment transaction:
* - MUST set `my_current_per_commitment_point` to a valid point. * - MUST set `my_current_per_commitment_point` to a valid point.
* - otherwise, if it supports `option_data_loss_protect`: * - otherwise:
* - MUST set `my_current_per_commitment_point` to its commitment * - MUST set `my_current_per_commitment_point` to its commitment
* point for the last signed commitment it received from its * point for the last signed commitment it received from its
* channel peer (i.e. the commitment_point corresponding to the * channel peer (i.e. the commitment_point corresponding to the
* commitment transaction the sender would use to unilaterally * commitment transaction the sender would use to unilaterally
* close). * close).
* - if `option_static_remotekey` applies to the commitment * - if `next_revocation_number` equals 0:
* transaction, or the sending node supports * - MUST set `your_last_per_commitment_secret` to all zeroes
* `option_data_loss_protect`: * - otherwise:
* - if `next_revocation_number` equals 0: * - MUST set `your_last_per_commitment_secret` to the last
* - MUST set `your_last_per_commitment_secret` to all zeroes * `per_commitment_secret` it received
* - otherwise:
* - MUST set `your_last_per_commitment_secret` to the last
* `per_commitment_secret` it received
*/ */
if (peer->channel->option_static_remotekey) { if (peer->channel->option_static_remotekey) {
msg = towire_channel_reestablish_option_static_remotekey msg = towire_channel_reestablish
(NULL, &peer->channel_id, (NULL, &peer->channel_id,
peer->next_index[LOCAL], peer->next_index[LOCAL],
peer->revocations_received, peer->revocations_received,
last_remote_per_commit_secret, last_remote_per_commit_secret,
/* Can send any (valid) point here */ /* Can send any (valid) point here */
&peer->remote_per_commit); &peer->remote_per_commit);
} else if (dataloss_protect) { } else {
msg = towire_channel_reestablish_option_data_loss_protect msg = towire_channel_reestablish
(NULL, &peer->channel_id, (NULL, &peer->channel_id,
peer->next_index[LOCAL], peer->next_index[LOCAL],
peer->revocations_received, peer->revocations_received,
last_remote_per_commit_secret, last_remote_per_commit_secret,
&my_current_per_commitment_point); &my_current_per_commitment_point);
} else {
msg = towire_channel_reestablish
(NULL, &peer->channel_id,
peer->next_index[LOCAL],
peer->revocations_received);
} }
sync_crypto_write(peer->pps, take(msg)); sync_crypto_write(peer->pps, take(msg));
@ -2494,43 +2484,17 @@ static void peer_reconnect(struct peer *peer,
msg) || msg) ||
capture_premature_msg(&premature_msgs, msg)); capture_premature_msg(&premature_msgs, msg));
if (peer->channel->option_static_remotekey) { if (!fromwire_channel_reestablish(msg,
struct pubkey ignore;
if (!fromwire_channel_reestablish_option_static_remotekey(msg,
&channel_id,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commitment_secret,
&ignore)) {
peer_failed(peer->pps,
&peer->channel_id,
"bad reestablish static_remotekey msg: %s %s",
wire_type_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
}
} else if (dataloss_protect) {
if (!fromwire_channel_reestablish_option_data_loss_protect(msg,
&channel_id, &channel_id,
&next_commitment_number, &next_commitment_number,
&next_revocation_number, &next_revocation_number,
&last_local_per_commitment_secret, &last_local_per_commitment_secret,
&remote_current_per_commitment_point)) { &remote_current_per_commitment_point)) {
peer_failed(peer->pps, peer_failed(peer->pps,
&peer->channel_id, &peer->channel_id,
"bad reestablish dataloss msg: %s %s", "bad reestablish msg: %s %s",
wire_type_name(fromwire_peektype(msg)), wire_type_name(fromwire_peektype(msg)),
tal_hex(msg, msg)); tal_hex(msg, msg));
}
} else {
if (!fromwire_channel_reestablish(msg, &channel_id,
&next_commitment_number,
&next_revocation_number)) {
peer_failed(peer->pps,
&peer->channel_id,
"bad reestablish msg: %s %s",
wire_type_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
}
} }
status_debug("Got reestablish commit=%"PRIu64" revoke=%"PRIu64, status_debug("Got reestablish commit=%"PRIu64" revoke=%"PRIu64,

9
closingd/closingd.c

@ -154,6 +154,7 @@ static void do_reconnect(struct per_peer_state *pps,
struct channel_id their_channel_id; struct channel_id their_channel_id;
u64 next_local_commitment_number, next_remote_revocation_number; u64 next_local_commitment_number, next_remote_revocation_number;
struct pubkey my_current_per_commitment_point, next_commitment_point; struct pubkey my_current_per_commitment_point, next_commitment_point;
struct secret their_secret;
my_current_per_commitment_point = get_per_commitment_point(next_index[LOCAL]-1); my_current_per_commitment_point = get_per_commitment_point(next_index[LOCAL]-1);
@ -175,9 +176,7 @@ static void do_reconnect(struct per_peer_state *pps,
* of the next `revoke_and_ack` message it expects to receive. * of the next `revoke_and_ack` message it expects to receive.
*/ */
/* We're always allowed to send extra fields, so we send dataloss_protect msg = towire_channel_reestablish(NULL, channel_id,
* even if we didn't negotiate it */
msg = towire_channel_reestablish_option_data_loss_protect(NULL, channel_id,
next_index[LOCAL], next_index[LOCAL],
revocations_received, revocations_received,
last_remote_per_commit_secret, last_remote_per_commit_secret,
@ -199,7 +198,9 @@ static void do_reconnect(struct per_peer_state *pps,
if (!fromwire_channel_reestablish(channel_reestablish, &their_channel_id, if (!fromwire_channel_reestablish(channel_reestablish, &their_channel_id,
&next_local_commitment_number, &next_local_commitment_number,
&next_remote_revocation_number)) { &next_remote_revocation_number,
&their_secret,
&next_commitment_point)) {
peer_failed(pps, channel_id, peer_failed(pps, channel_id,
"bad reestablish msg: %s %s", "bad reestablish msg: %s %s",
wire_type_name(fromwire_peektype(channel_reestablish)), wire_type_name(fromwire_peektype(channel_reestablish)),

6
common/bigsize.c

@ -64,7 +64,7 @@ size_t bigsize_get(const u8 *p, size_t max, bigsize_t *val)
} }
*val = ((u64)p[1] << 8) + p[2]; *val = ((u64)p[1] << 8) + p[2];
if (*val < 0xfd) { if (*val < 0xfd) {
SUPERVERBOSE("decoded varint is not canonical"); SUPERVERBOSE("decoded bigsize is not canonical");
return 0; return 0;
} }
return 3; return 3;
@ -76,7 +76,7 @@ size_t bigsize_get(const u8 *p, size_t max, bigsize_t *val)
*val = ((u64)p[1] << 24) + ((u64)p[2] << 16) *val = ((u64)p[1] << 24) + ((u64)p[2] << 16)
+ ((u64)p[3] << 8) + p[4]; + ((u64)p[3] << 8) + p[4];
if ((*val >> 16) == 0) { if ((*val >> 16) == 0) {
SUPERVERBOSE("decoded varint is not canonical"); SUPERVERBOSE("decoded bigsize is not canonical");
return 0; return 0;
} }
return 5; return 5;
@ -90,7 +90,7 @@ size_t bigsize_get(const u8 *p, size_t max, bigsize_t *val)
+ ((u64)p[5] << 24) + ((u64)p[6] << 16) + ((u64)p[5] << 24) + ((u64)p[6] << 16)
+ ((u64)p[7] << 8) + p[8]; + ((u64)p[7] << 8) + p[8];
if ((*val >> 32) == 0) { if ((*val >> 32) == 0) {
SUPERVERBOSE("decoded varint is not canonical"); SUPERVERBOSE("decoded bigsize is not canonical");
return 0; return 0;
} }
return 9; return 9;

2
common/decode_array.h

@ -23,7 +23,7 @@ struct short_channel_id *decode_short_ids(const tal_t *ctx, const u8 *encoded);
/* BOLT #7: /* BOLT #7:
* *
* `encoded_query_flags` is an array of bitfields, one varint per bitfield, * `encoded_query_flags` is an array of bitfields, one bigsize per bitfield,
* one bitfield for each `short_channel_id`. Bits have the following meaning: * one bitfield for each `short_channel_id`. Bits have the following meaning:
* *
* | Bit Position | Meaning | * | Bit Position | Meaning |

3
common/features.c

@ -61,9 +61,8 @@ static const struct feature_style feature_styles[] = {
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT, .copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT, [NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[BOLT11_FEATURE] = FEATURE_REPRESENT } }, [BOLT11_FEATURE] = FEATURE_REPRESENT } },
/* FIXME: Spec is wrong, and Eclair doesn't include in channel_announce! */
/* BOLT #9: /* BOLT #9:
* | 18/19 | `option_support_large_channel` |... INC+ ... * | 18/19 | `option_support_large_channel` |... IN ...
*/ */
{ OPT_LARGE_CHANNELS, { OPT_LARGE_CHANNELS,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT, .copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,

2
common/features.h

@ -95,7 +95,7 @@ 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` |... INC+ ... * | 18/19 | `option_support_large_channel` |... IN ...
*/ */
#define OPT_PAYMENT_SECRET 14 #define OPT_PAYMENT_SECRET 14
#define OPT_BASIC_MPP 16 #define OPT_BASIC_MPP 16

6
common/test/run-bigsize.c

@ -171,19 +171,19 @@ void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNE
* "name": "two byte not canonical", * "name": "two byte not canonical",
* "value": 0, * "value": 0,
* "bytes": "fd00fc", * "bytes": "fd00fc",
* "exp_error": "decoded varint is not canonical" * "exp_error": "decoded bigsize is not canonical"
* }, * },
* { * {
* "name": "four byte not canonical", * "name": "four byte not canonical",
* "value": 0, * "value": 0,
* "bytes": "fe0000ffff", * "bytes": "fe0000ffff",
* "exp_error": "decoded varint is not canonical" * "exp_error": "decoded bigsize is not canonical"
* }, * },
* { * {
* "name": "eight byte not canonical", * "name": "eight byte not canonical",
* "value": 0, * "value": 0,
* "bytes": "ff00000000ffffffff", * "bytes": "ff00000000ffffffff",
* "exp_error": "decoded varint is not canonical" * "exp_error": "decoded bigsize is not canonical"
* }, * },
* { * {
* "name": "two byte short read", * "name": "two byte short read",

32
gossipd/queries.c

@ -167,7 +167,7 @@ bool query_short_channel_ids(struct daemon *daemon,
/* BOLT #7: /* BOLT #7:
* - MAY include an optional `query_flags`. If so: * - MAY include an optional `query_flags`. If so:
* - MUST set `encoding_type`, as for `encoded_short_ids`. * - MUST set `encoding_type`, as for `encoded_short_ids`.
* - Each query flag is a minimally-encoded varint. * - Each query flag is a minimally-encoded bigsize.
* - MUST encode one query flag per `short_channel_id`. * - MUST encode one query flag per `short_channel_id`.
*/ */
if (query_flags) if (query_flags)
@ -353,18 +353,15 @@ static void reply_channel_range(struct peer *peer,
{ {
/* BOLT #7: /* BOLT #7:
* *
* - For each `reply_channel_range`: * - MUST respond with one or more `reply_channel_range`:
* - MUST set with `chain_hash` equal to that of `query_channel_range`, * - MUST set with `chain_hash` equal to that of `query_channel_range`,
* - MUST encode a `short_channel_id` for every open channel it
* knows in blocks `first_blocknum` to `first_blocknum` plus
* `number_of_blocks` minus one.
* - MUST limit `number_of_blocks` to the maximum number of blocks * - MUST limit `number_of_blocks` to the maximum number of blocks
* whose results could fit in `encoded_short_ids` * whose results could fit in `encoded_short_ids`
* - if does not maintain up-to-date channel information for * - if does not maintain up-to-date channel information for
* `chain_hash`: * `chain_hash`:
* - MUST set `complete` to 0. * - MUST set `full_information` to 0.
* - otherwise: * - otherwise:
* - SHOULD set `complete` to 1. * - SHOULD set `full_information` to 1.
*/ */
struct tlv_reply_channel_range_tlvs *tlvs struct tlv_reply_channel_range_tlvs *tlvs
= tlv_reply_channel_range_tlvs_new(tmpctx); = tlv_reply_channel_range_tlvs_new(tmpctx);
@ -449,7 +446,7 @@ static bool queue_channel_ranges(struct peer *peer,
* * [`chain_hash`:`chain_hash`] * * [`chain_hash`:`chain_hash`]
* * [`u32`:`first_blocknum`] * * [`u32`:`first_blocknum`]
* * [`u32`:`number_of_blocks`] * * [`u32`:`number_of_blocks`]
* * [`byte`:`complete`] * * [`byte`:`full_information`]
* * [`u16`:`len`] * * [`u16`:`len`]
* * [`len*byte`:`encoded_short_ids`] * * [`len*byte`:`encoded_short_ids`]
*/ */
@ -696,9 +693,18 @@ const u8 *handle_reply_channel_range(struct peer *peer, const u8 *msg)
* *
* The receiver of `query_channel_range`: * The receiver of `query_channel_range`:
*... *...
* - MUST respond with one or more `reply_channel_range` whose * - the first `reply_channel_range` message:
* combined range cover the requested `first_blocknum` to * - MUST set `first_blocknum` less than or equal to the
* `first_blocknum` plus `number_of_blocks` minus one. * `first_blocknum` in `query_channel_range`
* - MUST set `first_blocknum` plus `number_of_blocks` greater than
* `first_blocknum` in `query_channel_range`.
* - successive `reply_channel_range` message:
* - MUST set `first_blocknum` to the previous `first_blocknum`
* plus `number_of_blocks`.
* - the final `reply_channel_range` message:
* - MUST have `first_blocknum` plus `number_of_blocks` equal or
* greater than the `query_channel_range` `first_blocknum` plus
* `number_of_blocks`.
*/ */
/* ie. They can be outside range we asked, but they must overlap! */ /* ie. They can be outside range we asked, but they must overlap! */
if (first_blocknum + number_of_blocks <= peer->range_first_blocknum if (first_blocknum + number_of_blocks <= peer->range_first_blocknum
@ -988,9 +994,9 @@ void maybe_send_query_responses(struct peer *peer)
* `reply_short_channel_ids_end`. * `reply_short_channel_ids_end`.
* - if does not maintain up-to-date channel information for * - if does not maintain up-to-date channel information for
* `chain_hash`: * `chain_hash`:
* - MUST set `complete` to 0. * - MUST set `full_information` to 0.
* - otherwise: * - otherwise:
* - SHOULD set `complete` to 1. * - SHOULD set `full_information` to 1.
*/ */
/* FIXME: We consider ourselves to have complete knowledge. */ /* FIXME: We consider ourselves to have complete knowledge. */
u8 *end = towire_reply_short_channel_ids_end(peer, u8 *end = towire_reply_short_channel_ids_end(peer,

2
gossipd/queries.h

@ -21,7 +21,7 @@ void maybe_send_query_responses(struct peer *peer);
/* BOLT #7: /* BOLT #7:
* *
* `query_option_flags` is a bitfield represented as a minimally-encoded varint. * `query_option_flags` is a bitfield represented as a minimally-encoded bigsize.
* Bits have the following meaning: * Bits have the following meaning:
* *
* | Bit Position | Meaning | * | Bit Position | Meaning |

2
onchaind/onchaind.c

@ -2270,7 +2270,7 @@ static void handle_our_unilateral(const struct tx_parts *tx,
* only be valid after that duration has passed) and * only be valid after that duration has passed) and
* witness: * witness:
* *
* <local_delayedsig> 0 * <local_delayedsig> <>
*/ */
to_us = tx_to_us(out, delayed_payment_to_us, out, to_us = tx_to_us(out, delayed_payment_to_us, out,
to_self_delay[LOCAL], 0, NULL, 0, to_self_delay[LOCAL], 0, NULL, 0,

92
openingd/openingd.c

@ -516,6 +516,8 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
u8 *msg; u8 *msg;
u8 *funding_output_script; u8 *funding_output_script;
struct channel_id id_in; struct channel_id id_in;
struct tlv_open_channel_tlvs *open_tlvs;
struct tlv_accept_channel_tlvs *accept_tlvs;
if (!setup_channel_funder(state)) if (!setup_channel_funder(state))
return NULL; return NULL;
@ -524,16 +526,19 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
* *
* - if both nodes advertised the `option_upfront_shutdown_script` * - if both nodes advertised the `option_upfront_shutdown_script`
* feature: * feature:
* - MUST include either a valid `shutdown_scriptpubkey` as required * - MUST include `upfront_shutdown_script` with either a valid
* by `shutdown` `scriptpubkey`, or a zero-length * `shutdown_scriptpubkey` as required by `shutdown`
* `shutdown_scriptpubkey`. * `scriptpubkey`, or a zero-length `shutdown_scriptpubkey`
* - otherwise: * (ie. `0x0000`).
* - MAY include a`shutdown_scriptpubkey`.
*/ */
if (!state->upfront_shutdown_script[LOCAL]) if (!state->upfront_shutdown_script[LOCAL])
state->upfront_shutdown_script[LOCAL] = dev_upfront_shutdown_script(state); state->upfront_shutdown_script[LOCAL] = dev_upfront_shutdown_script(state);
msg = towire_open_channel_option_upfront_shutdown_script(NULL, open_tlvs = tlv_open_channel_tlvs_new(tmpctx);
open_tlvs->upfront_shutdown_script
= state->upfront_shutdown_script[LOCAL];
msg = towire_open_channel(NULL,
&chainparams->genesis_blockhash, &chainparams->genesis_blockhash,
&state->channel_id, &state->channel_id,
state->funding, state->funding,
@ -552,7 +557,7 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
&state->our_points.htlc, &state->our_points.htlc,
&state->first_per_commitment_point[LOCAL], &state->first_per_commitment_point[LOCAL],
channel_flags, channel_flags,
state->upfront_shutdown_script[LOCAL]); open_tlvs);
sync_crypto_write(state->pps, take(msg)); sync_crypto_write(state->pps, take(msg));
/* This is usually a very transient state... */ /* This is usually a very transient state... */
@ -572,10 +577,8 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
* `payment_basepoint`, or `delayed_payment_basepoint` are not * `payment_basepoint`, or `delayed_payment_basepoint` are not
* valid secp256k1 pubkeys in compressed format. * valid secp256k1 pubkeys in compressed format.
*/ */
if (feature_negotiated(state->our_features, state->their_features, accept_tlvs = tlv_accept_channel_tlvs_new(tmpctx);
OPT_UPFRONT_SHUTDOWN_SCRIPT)) { if (!fromwire_accept_channel(msg, &id_in,
if (!fromwire_accept_channel_option_upfront_shutdown_script(state,
msg, &id_in,
&state->remoteconf.dust_limit, &state->remoteconf.dust_limit,
&state->remoteconf.max_htlc_value_in_flight, &state->remoteconf.max_htlc_value_in_flight,
&state->remoteconf.channel_reserve, &state->remoteconf.channel_reserve,
@ -589,27 +592,13 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags)
&state->their_points.delayed_payment, &state->their_points.delayed_payment,
&state->their_points.htlc, &state->their_points.htlc,
&state->first_per_commitment_point[REMOTE], &state->first_per_commitment_point[REMOTE],
&state->upfront_shutdown_script[REMOTE])) accept_tlvs)) {
peer_failed(state->pps, peer_failed(state->pps,
&state->channel_id, &state->channel_id,
"Parsing accept_channel with option_upfront_shutdown_script %s", tal_hex(msg, msg)); "Parsing accept_channel %s", tal_hex(msg, msg));
} else if (!fromwire_accept_channel(msg, &id_in, }
&state->remoteconf.dust_limit, state->upfront_shutdown_script[REMOTE]
&state->remoteconf.max_htlc_value_in_flight, = tal_steal(state, accept_tlvs->upfront_shutdown_script);
&state->remoteconf.channel_reserve,
&state->remoteconf.htlc_minimum,
&state->minimum_depth,
&state->remoteconf.to_self_delay,
&state->remoteconf.max_accepted_htlcs,
&state->their_funding_pubkey,
&state->their_points.revocation,
&state->their_points.payment,
&state->their_points.delayed_payment,
&state->their_points.htlc,
&state->first_per_commitment_point[REMOTE]))
peer_failed(state->pps,
&state->channel_id,
"Parsing accept_channel %s", tal_hex(msg, msg));
/* BOLT #2: /* BOLT #2:
* *
@ -923,6 +912,9 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
char* err_reason; char* err_reason;
struct wally_tx_output *direct_outputs[NUM_SIDES]; struct wally_tx_output *direct_outputs[NUM_SIDES];
struct penalty_base *pbase; struct penalty_base *pbase;
struct tlv_accept_channel_tlvs *accept_tlvs;
struct tlv_open_channel_tlvs *open_tlvs
= tlv_open_channel_tlvs_new(tmpctx);
/* BOLT #2: /* BOLT #2:
* *
@ -932,10 +924,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
* `payment_basepoint`, or `delayed_payment_basepoint` are not valid * `payment_basepoint`, or `delayed_payment_basepoint` are not valid
* secp256k1 pubkeys in compressed format. * secp256k1 pubkeys in compressed format.
*/ */
if (feature_negotiated(state->our_features, state->their_features, if (!fromwire_open_channel(open_channel_msg, &chain_hash,
OPT_UPFRONT_SHUTDOWN_SCRIPT)) {
if (!fromwire_open_channel_option_upfront_shutdown_script(state,
open_channel_msg, &chain_hash,
&state->channel_id, &state->channel_id,
&state->funding, &state->funding,
&state->push_msat, &state->push_msat,
@ -953,31 +942,12 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
&theirs.htlc, &theirs.htlc,
&state->first_per_commitment_point[REMOTE], &state->first_per_commitment_point[REMOTE],
&channel_flags, &channel_flags,
&state->upfront_shutdown_script[REMOTE])) open_tlvs))
peer_failed(state->pps, peer_failed(state->pps,
&state->channel_id, &state->channel_id,
"Parsing open_channel with option_upfront_shutdown_script %s", tal_hex(tmpctx, open_channel_msg)); "Parsing open_channel %s", tal_hex(tmpctx, open_channel_msg));
} else if (!fromwire_open_channel(open_channel_msg, &chain_hash, state->upfront_shutdown_script[REMOTE]
&state->channel_id, = tal_steal(state, open_tlvs->upfront_shutdown_script);
&state->funding,
&state->push_msat,
&state->remoteconf.dust_limit,
&state->remoteconf.max_htlc_value_in_flight,
&state->remoteconf.channel_reserve,
&state->remoteconf.htlc_minimum,
&state->feerate_per_kw,
&state->remoteconf.to_self_delay,
&state->remoteconf.max_accepted_htlcs,
&their_funding_pubkey,
&theirs.revocation,
&theirs.payment,
&theirs.delayed_payment,
&theirs.htlc,
&state->first_per_commitment_point[REMOTE],
&channel_flags))
peer_failed(state->pps, NULL,
"Bad open_channel %s",
tal_hex(open_channel_msg, open_channel_msg));
/* BOLT #2: /* BOLT #2:
* *
@ -1125,7 +1095,11 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
state->upfront_shutdown_script[LOCAL] = dev_upfront_shutdown_script(state); state->upfront_shutdown_script[LOCAL] = dev_upfront_shutdown_script(state);
/* OK, we accept! */ /* OK, we accept! */
msg = towire_accept_channel_option_upfront_shutdown_script(NULL, &state->channel_id, accept_tlvs = tlv_accept_channel_tlvs_new(tmpctx);
accept_tlvs->upfront_shutdown_script
= state->upfront_shutdown_script[LOCAL];
msg = towire_accept_channel(NULL, &state->channel_id,
state->localconf.dust_limit, state->localconf.dust_limit,
state->localconf.max_htlc_value_in_flight, state->localconf.max_htlc_value_in_flight,
state->localconf.channel_reserve, state->localconf.channel_reserve,
@ -1139,7 +1113,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
&state->our_points.delayed_payment, &state->our_points.delayed_payment,
&state->our_points.htlc, &state->our_points.htlc,
&state->first_per_commitment_point[LOCAL], &state->first_per_commitment_point[LOCAL],
state->upfront_shutdown_script[LOCAL]); accept_tlvs);
sync_crypto_write(state->pps, take(msg)); sync_crypto_write(state->pps, take(msg));

2
wire/extracted_onion_wire_csv

@ -49,6 +49,6 @@ msgdata,final_incorrect_htlc_amount,incoming_htlc_amt,u64,
msgtype,channel_disabled,UPDATE|20 msgtype,channel_disabled,UPDATE|20
msgtype,expiry_too_far,21 msgtype,expiry_too_far,21
msgtype,invalid_onion_payload,PERM|22 msgtype,invalid_onion_payload,PERM|22
msgdata,invalid_onion_payload,type,varint, msgdata,invalid_onion_payload,type,bigsize,
msgdata,invalid_onion_payload,offset,u16, msgdata,invalid_onion_payload,offset,u16,
msgtype,mpp_timeout,23 msgtype,mpp_timeout,23

28
wire/extracted_peer_wire_csv

@ -1,8 +1,8 @@
msgtype,init,16 msgtype,init,16
msgdata,init,gflen,u16, msgdata,init,gflen,u16,
msgdata,init,globalfeatures,byte,gflen msgdata,init,globalfeatures,byte,gflen
msgdata,init,lflen,u16, msgdata,init,flen,u16,
msgdata,init,localfeatures,byte,lflen msgdata,init,features,byte,flen
msgdata,init,tlvs,init_tlvs, msgdata,init,tlvs,init_tlvs,
tlvtype,init_tlvs,networks,1 tlvtype,init_tlvs,networks,1
tlvdata,init_tlvs,networks,chains,chain_hash,... tlvdata,init_tlvs,networks,chains,chain_hash,...
@ -50,8 +50,9 @@ msgdata,open_channel,delayed_payment_basepoint,point,
msgdata,open_channel,htlc_basepoint,point, msgdata,open_channel,htlc_basepoint,point,
msgdata,open_channel,first_per_commitment_point,point, msgdata,open_channel,first_per_commitment_point,point,
msgdata,open_channel,channel_flags,byte, msgdata,open_channel,channel_flags,byte,
msgdata,open_channel,shutdown_len,u16,,option_upfront_shutdown_script msgdata,open_channel,tlvs,open_channel_tlvs,
msgdata,open_channel,shutdown_scriptpubkey,byte,shutdown_len,option_upfront_shutdown_script tlvtype,open_channel_tlvs,upfront_shutdown_script,0
tlvdata,open_channel_tlvs,upfront_shutdown_script,shutdown_scriptpubkey,byte,...
msgtype,accept_channel,33 msgtype,accept_channel,33
msgdata,accept_channel,temporary_channel_id,byte,32 msgdata,accept_channel,temporary_channel_id,byte,32
msgdata,accept_channel,dust_limit_satoshis,u64, msgdata,accept_channel,dust_limit_satoshis,u64,
@ -67,8 +68,9 @@ msgdata,accept_channel,payment_basepoint,point,
msgdata,accept_channel,delayed_payment_basepoint,point, msgdata,accept_channel,delayed_payment_basepoint,point,
msgdata,accept_channel,htlc_basepoint,point, msgdata,accept_channel,htlc_basepoint,point,
msgdata,accept_channel,first_per_commitment_point,point, msgdata,accept_channel,first_per_commitment_point,point,
msgdata,accept_channel,shutdown_len,u16,,option_upfront_shutdown_script msgdata,accept_channel,tlvs,accept_channel_tlvs,
msgdata,accept_channel,shutdown_scriptpubkey,byte,shutdown_len,option_upfront_shutdown_script tlvtype,accept_channel_tlvs,upfront_shutdown_script,0
tlvdata,accept_channel_tlvs,upfront_shutdown_script,shutdown_scriptpubkey,byte,...
msgtype,funding_created,34 msgtype,funding_created,34
msgdata,funding_created,temporary_channel_id,byte,32 msgdata,funding_created,temporary_channel_id,byte,32
msgdata,funding_created,funding_txid,sha256, msgdata,funding_created,funding_txid,sha256,
@ -125,8 +127,8 @@ msgtype,channel_reestablish,136
msgdata,channel_reestablish,channel_id,channel_id, msgdata,channel_reestablish,channel_id,channel_id,
msgdata,channel_reestablish,next_commitment_number,u64, msgdata,channel_reestablish,next_commitment_number,u64,
msgdata,channel_reestablish,next_revocation_number,u64, msgdata,channel_reestablish,next_revocation_number,u64,
msgdata,channel_reestablish,your_last_per_commitment_secret,byte,32,option_data_loss_protect,option_static_remotekey msgdata,channel_reestablish,your_last_per_commitment_secret,byte,32
msgdata,channel_reestablish,my_current_per_commitment_point,point,,option_data_loss_protect,option_static_remotekey msgdata,channel_reestablish,my_current_per_commitment_point,point,
msgtype,announcement_signatures,259 msgtype,announcement_signatures,259
msgdata,announcement_signatures,channel_id,channel_id, msgdata,announcement_signatures,channel_id,channel_id,
msgdata,announcement_signatures,short_channel_id,short_channel_id, msgdata,announcement_signatures,short_channel_id,short_channel_id,
@ -173,28 +175,28 @@ msgdata,query_short_channel_ids,len,u16,
msgdata,query_short_channel_ids,encoded_short_ids,byte,len msgdata,query_short_channel_ids,encoded_short_ids,byte,len
msgdata,query_short_channel_ids,tlvs,query_short_channel_ids_tlvs, msgdata,query_short_channel_ids,tlvs,query_short_channel_ids_tlvs,
tlvtype,query_short_channel_ids_tlvs,query_flags,1 tlvtype,query_short_channel_ids_tlvs,query_flags,1
tlvdata,query_short_channel_ids_tlvs,query_flags,encoding_type,u8, tlvdata,query_short_channel_ids_tlvs,query_flags,encoding_type,byte,
tlvdata,query_short_channel_ids_tlvs,query_flags,encoded_query_flags,byte,... tlvdata,query_short_channel_ids_tlvs,query_flags,encoded_query_flags,byte,...
msgtype,reply_short_channel_ids_end,262,gossip_queries msgtype,reply_short_channel_ids_end,262,gossip_queries
msgdata,reply_short_channel_ids_end,chain_hash,chain_hash, msgdata,reply_short_channel_ids_end,chain_hash,chain_hash,
msgdata,reply_short_channel_ids_end,complete,byte, msgdata,reply_short_channel_ids_end,full_information,byte,
msgtype,query_channel_range,263,gossip_queries msgtype,query_channel_range,263,gossip_queries
msgdata,query_channel_range,chain_hash,chain_hash, msgdata,query_channel_range,chain_hash,chain_hash,
msgdata,query_channel_range,first_blocknum,u32, msgdata,query_channel_range,first_blocknum,u32,
msgdata,query_channel_range,number_of_blocks,u32, msgdata,query_channel_range,number_of_blocks,u32,
msgdata,query_channel_range,tlvs,query_channel_range_tlvs, msgdata,query_channel_range,tlvs,query_channel_range_tlvs,
tlvtype,query_channel_range_tlvs,query_option,1 tlvtype,query_channel_range_tlvs,query_option,1
tlvdata,query_channel_range_tlvs,query_option,query_option_flags,varint, tlvdata,query_channel_range_tlvs,query_option,query_option_flags,bigsize,
msgtype,reply_channel_range,264,gossip_queries msgtype,reply_channel_range,264,gossip_queries
msgdata,reply_channel_range,chain_hash,chain_hash, msgdata,reply_channel_range,chain_hash,chain_hash,
msgdata,reply_channel_range,first_blocknum,u32, msgdata,reply_channel_range,first_blocknum,u32,
msgdata,reply_channel_range,number_of_blocks,u32, msgdata,reply_channel_range,number_of_blocks,u32,
msgdata,reply_channel_range,complete,byte, msgdata,reply_channel_range,full_information,byte,
msgdata,reply_channel_range,len,u16, msgdata,reply_channel_range,len,u16,
msgdata,reply_channel_range,encoded_short_ids,byte,len msgdata,reply_channel_range,encoded_short_ids,byte,len
msgdata,reply_channel_range,tlvs,reply_channel_range_tlvs, msgdata,reply_channel_range,tlvs,reply_channel_range_tlvs,
tlvtype,reply_channel_range_tlvs,timestamps_tlv,1 tlvtype,reply_channel_range_tlvs,timestamps_tlv,1
tlvdata,reply_channel_range_tlvs,timestamps_tlv,encoding_type,u8, tlvdata,reply_channel_range_tlvs,timestamps_tlv,encoding_type,byte,
tlvdata,reply_channel_range_tlvs,timestamps_tlv,encoded_timestamps,byte,... tlvdata,reply_channel_range_tlvs,timestamps_tlv,encoded_timestamps,byte,...
tlvtype,reply_channel_range_tlvs,checksums_tlv,3 tlvtype,reply_channel_range_tlvs,checksums_tlv,3
tlvdata,reply_channel_range_tlvs,checksums_tlv,checksums,channel_update_checksums,... tlvdata,reply_channel_range_tlvs,checksums_tlv,checksums,channel_update_checksums,...

7
wire/peer_wire.c

@ -98,9 +98,12 @@ bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
u8 ignored_u8; u8 ignored_u8;
struct pubkey ignored_pubkey; struct pubkey ignored_pubkey;
struct bitcoin_blkid ignored_chainhash; struct bitcoin_blkid ignored_chainhash;
struct secret ignored_secret;
struct tlv_open_channel_tlvs *tlvs = tlv_open_channel_tlvs_new(tmpctx);
if (fromwire_channel_reestablish(in_pkt, channel_id, if (fromwire_channel_reestablish(in_pkt, channel_id,
&ignored_u64, &ignored_u64)) &ignored_u64, &ignored_u64,
&ignored_secret, &ignored_pubkey))
return true; return true;
if (fromwire_open_channel(in_pkt, &ignored_chainhash, if (fromwire_open_channel(in_pkt, &ignored_chainhash,
channel_id, &ignored_sat, channel_id, &ignored_sat,
@ -111,7 +114,7 @@ bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
&ignored_pubkey, &ignored_pubkey, &ignored_pubkey, &ignored_pubkey,
&ignored_pubkey, &ignored_pubkey, &ignored_pubkey, &ignored_pubkey,
&ignored_pubkey, &ignored_pubkey, &ignored_pubkey, &ignored_pubkey,
&ignored_u8)) &ignored_u8, tlvs))
return true; return true;
return false; return false;
} }

3
wire/peer_wire.h

@ -10,7 +10,8 @@
* - upon receiving a message of _odd_, unknown type: * - upon receiving a message of _odd_, unknown type:
* - MUST ignore the received message. * - MUST ignore the received message.
* - upon receiving a message of _even_, unknown type: * - upon receiving a message of _even_, unknown type:
* - MUST fail the channels. * - MUST close the connection.
* - MAY fail the channels.
*/ */
/* Return true if it's an unknown ODD message. cursor is a tal ptr. */ /* Return true if it's an unknown ODD message. cursor is a tal ptr. */

17
wire/test/run-peer-wire.c

@ -97,6 +97,7 @@ struct msg_accept_channel {
struct pubkey delayed_payment_basepoint; struct pubkey delayed_payment_basepoint;
struct pubkey htlc_basepoint; struct pubkey htlc_basepoint;
struct pubkey first_per_commitment_point; struct pubkey first_per_commitment_point;
struct tlv_accept_channel_tlvs *tlvs;
}; };
struct msg_update_fulfill_htlc { struct msg_update_fulfill_htlc {
struct channel_id channel_id; struct channel_id channel_id;
@ -184,6 +185,7 @@ struct msg_open_channel {
struct pubkey htlc_basepoint; struct pubkey htlc_basepoint;
struct pubkey first_per_commitment_point; struct pubkey first_per_commitment_point;
u8 channel_flags; u8 channel_flags;
struct tlv_open_channel_tlvs *tlvs;
}; };
struct msg_update_fail_htlc { struct msg_update_fail_htlc {
struct channel_id channel_id; struct channel_id channel_id;
@ -278,12 +280,14 @@ static void *towire_struct_open_channel(const tal_t *ctx,
&s->delayed_payment_basepoint, &s->delayed_payment_basepoint,
&s->htlc_basepoint, &s->htlc_basepoint,
&s->first_per_commitment_point, &s->first_per_commitment_point,
s->channel_flags); s->channel_flags,
NULL);
} }
static struct msg_open_channel *fromwire_struct_open_channel(const tal_t *ctx, const void *p) static struct msg_open_channel *fromwire_struct_open_channel(const tal_t *ctx, const void *p)
{ {
struct msg_open_channel *s = tal(ctx, struct msg_open_channel); struct msg_open_channel *s = tal(ctx, struct msg_open_channel);
s->tlvs = tlv_open_channel_tlvs_new(s);
if (fromwire_open_channel(p, if (fromwire_open_channel(p,
&s->chain_hash, &s->chain_hash,
@ -303,7 +307,8 @@ static struct msg_open_channel *fromwire_struct_open_channel(const tal_t *ctx, c
&s->delayed_payment_basepoint, &s->delayed_payment_basepoint,
&s->htlc_basepoint, &s->htlc_basepoint,
&s->first_per_commitment_point, &s->first_per_commitment_point,
&s->channel_flags)) &s->channel_flags,
s->tlvs))
return s; return s;
return tal_free(s); return tal_free(s);
} }
@ -325,12 +330,14 @@ static void *towire_struct_accept_channel(const tal_t *ctx,
&s->payment_basepoint, &s->payment_basepoint,
&s->htlc_basepoint, &s->htlc_basepoint,
&s->delayed_payment_basepoint, &s->delayed_payment_basepoint,
&s->first_per_commitment_point); &s->first_per_commitment_point,
s->tlvs);
} }
static struct msg_accept_channel *fromwire_struct_accept_channel(const tal_t *ctx, const void *p) static struct msg_accept_channel *fromwire_struct_accept_channel(const tal_t *ctx, const void *p)
{ {
struct msg_accept_channel *s = tal(ctx, struct msg_accept_channel); struct msg_accept_channel *s = tal(ctx, struct msg_accept_channel);
s->tlvs = tlv_accept_channel_tlvs_new(s);
if (fromwire_accept_channel(p, if (fromwire_accept_channel(p,
&s->temporary_channel_id, &s->temporary_channel_id,
@ -346,7 +353,8 @@ static struct msg_accept_channel *fromwire_struct_accept_channel(const tal_t *ct
&s->payment_basepoint, &s->payment_basepoint,
&s->htlc_basepoint, &s->htlc_basepoint,
&s->delayed_payment_basepoint, &s->delayed_payment_basepoint,
&s->first_per_commitment_point)) &s->first_per_commitment_point,
s->tlvs))
return s; return s;
return tal_free(s); return tal_free(s);
} }
@ -1136,6 +1144,7 @@ int main(void)
set_pubkey(&ac.delayed_payment_basepoint); set_pubkey(&ac.delayed_payment_basepoint);
set_pubkey(&ac.htlc_basepoint); set_pubkey(&ac.htlc_basepoint);
set_pubkey(&ac.first_per_commitment_point); set_pubkey(&ac.first_per_commitment_point);
ac.tlvs = NULL;
msg = towire_struct_accept_channel(ctx, &ac); msg = towire_struct_accept_channel(ctx, &ac);
ac2 = fromwire_struct_accept_channel(ctx, msg); ac2 = fromwire_struct_accept_channel(ctx, msg);

Loading…
Cancel
Save