Skip to content

Commit

Permalink
channel: import upgrade spec.
Browse files Browse the repository at this point in the history
See lightning/bolts#868

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Jun 3, 2021
1 parent 60dc78d commit 3d8c4a1
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 9 deletions.
38 changes: 34 additions & 4 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -1930,12 +1930,19 @@ static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg)
u64 next_revocation_number;
struct secret your_last_per_commitment_secret;
struct pubkey my_current_per_commitment_point;
#if EXPERIMENTAL_FEATURES
struct tlv_channel_reestablish_tlvs *tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
#endif

if (!fromwire_channel_reestablish(msg, &channel_id,
&next_commitment_number,
&next_revocation_number,
&your_last_per_commitment_secret,
&my_current_per_commitment_point))
&my_current_per_commitment_point
#if EXPERIMENTAL_FEATURES
, tlvs
#endif
))
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad channel_reestablish %s", tal_hex(peer, msg));

Expand Down Expand Up @@ -2474,6 +2481,9 @@ static void peer_reconnect(struct peer *peer,
struct secret last_local_per_commitment_secret;
bool dataloss_protect, check_extra_fields;
const u8 **premature_msgs = tal_arr(peer, const u8 *, 0);
#if EXPERIMENTAL_FEATURES
struct tlv_channel_reestablish_tlvs *send_tlvs, *recv_tlvs;
#endif

dataloss_protect = feature_negotiated(peer->our_features,
peer->their_features,
Expand All @@ -2488,6 +2498,10 @@ static void peer_reconnect(struct peer *peer,
get_per_commitment_point(peer->next_index[LOCAL] - 1,
&my_current_per_commitment_point, NULL);

#if EXPERIMENTAL_FEATURES
send_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
#endif

/* BOLT #2:
*
* - upon reconnection:
Expand Down Expand Up @@ -2525,14 +2539,22 @@ static void peer_reconnect(struct peer *peer,
peer->revocations_received,
last_remote_per_commit_secret,
/* Can send any (valid) point here */
&peer->remote_per_commit);
&peer->remote_per_commit
#if EXPERIMENTAL_FEATURES
, send_tlvs
#endif
);
} else {
msg = towire_channel_reestablish
(NULL, &peer->channel_id,
peer->next_index[LOCAL],
peer->revocations_received,
last_remote_per_commit_secret,
&my_current_per_commitment_point);
&my_current_per_commitment_point
#if EXPERIMENTAL_FEATURES
, send_tlvs
#endif
);
}

sync_crypto_write(peer->pps, take(msg));
Expand All @@ -2552,12 +2574,20 @@ static void peer_reconnect(struct peer *peer,
msg) ||
capture_premature_msg(&premature_msgs, msg));

#if EXPERIMENTAL_FEATURES
recv_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
#endif

if (!fromwire_channel_reestablish(msg,
&channel_id,
&next_commitment_number,
&next_revocation_number,
&last_local_per_commitment_secret,
&remote_current_per_commitment_point)) {
&remote_current_per_commitment_point
#if EXPERIMENTAL_FEATURES
, recv_tlvs
#endif
)) {
peer_failed_warn(peer->pps,
&peer->channel_id,
"bad reestablish msg: %s %s",
Expand Down
15 changes: 13 additions & 2 deletions closingd/closingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ static void do_reconnect(struct per_peer_state *pps,
struct pubkey my_current_per_commitment_point, next_commitment_point;
struct secret their_secret;
struct tlv_shutdown_tlvs *tlvs;
#if EXPERIMENTAL_FEATURES
struct tlv_channel_reestablish_tlvs *reestablish_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
#endif

my_current_per_commitment_point = get_per_commitment_point(next_index[LOCAL]-1);

Expand All @@ -201,7 +204,11 @@ static void do_reconnect(struct per_peer_state *pps,
next_index[LOCAL],
revocations_received,
last_remote_per_commit_secret,
&my_current_per_commitment_point);
&my_current_per_commitment_point
#if EXPERIMENTAL_FEATURES
, reestablish_tlvs
#endif
);
sync_crypto_write(pps, take(msg));

/* They might have already sent reestablish, which triggered us */
Expand All @@ -221,7 +228,11 @@ static void do_reconnect(struct per_peer_state *pps,
&next_local_commitment_number,
&next_remote_revocation_number,
&their_secret,
&next_commitment_point)) {
&next_commitment_point
#if EXPERIMENTAL_FEATURES
, reestablish_tlvs
#endif
)) {
peer_failed_warn(pps, channel_id,
"bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(channel_reestablish)),
Expand Down
15 changes: 13 additions & 2 deletions openingd/dualopend.c
Original file line number Diff line number Diff line change
Expand Up @@ -3164,6 +3164,9 @@ static void do_reconnect_dance(struct state *state)
last_remote_per_commit_secret;
struct pubkey remote_current_per_commit_point;
struct tx_state *tx_state = state->tx_state;
#if EXPERIMENTAL_FEATURES
struct tlv_channel_reestablish_tlvs *tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
#endif

/* BOLT #2:
* - if `next_revocation_number` equals 0:
Expand All @@ -3177,7 +3180,11 @@ static void do_reconnect_dance(struct state *state)
msg = towire_channel_reestablish
(NULL, &state->channel_id, 1, 0,
&last_remote_per_commit_secret,
&state->first_per_commitment_point[LOCAL]);
&state->first_per_commitment_point[LOCAL]
#if EXPERIMENTAL_FEATURES
, tlvs
#endif
);
sync_crypto_write(state->pps, take(msg));

peer_billboard(false, "Sent reestablish, waiting for theirs");
Expand All @@ -3200,7 +3207,11 @@ static void do_reconnect_dance(struct state *state)
&next_commitment_number,
&next_revocation_number,
&last_local_per_commit_secret,
&remote_current_per_commit_point))
&remote_current_per_commit_point
#if EXPERIMENTAL_FEATURES
, tlvs
#endif
))
open_err_fatal(state, "Bad reestablish msg: %s %s",
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
Expand Down
21 changes: 21 additions & 0 deletions wire/extracted_peer_exp_upgradable.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--- wire/peer_wire.csv 2021-05-09 15:44:59.166135652 +0930
+++ wire/peer_wire.csv.raw 2021-05-11 09:59:31.695459756 +0930
@@ -221,6 +131,18 @@
msgdata,channel_reestablish,next_revocation_number,u64,
msgdata,channel_reestablish,your_last_per_commitment_secret,byte,32
msgdata,channel_reestablish,my_current_per_commitment_point,point,
+msgdata,channel_reestablish,tlvs,channel_reestablish_tlvs,
+tlvtype,channel_reestablish_tlvs,next_to_send,1
+tlvdata,channel_reestablish_tlvs,next_to_send,commitment_number,tu64,
+tlvtype,channel_reestablish_tlvs,desired_type,3
+tlvdata,channel_reestablish_tlvs,desired_type,type,channel_type,
+tlvtype,channel_reestablish_tlvs,current_type,5
+tlvdata,channel_reestablish_tlvs,current_type,type,channel_type,
+tlvtype,channel_reestablish_tlvs,upgradable,7
+tlvdata,channel_reestablish_tlvs,upgradable,upgrades,channel_type,...
+subtype,channel_type
+subtypedata,channel_type,len,u16,
+subtypedata,channel_type,features,byte,len
msgtype,announcement_signatures,259
msgdata,announcement_signatures,channel_id,channel_id,
msgdata,announcement_signatures,short_channel_id,short_channel_id,
9 changes: 8 additions & 1 deletion wire/peer_wire.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,17 @@ bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
struct bitcoin_blkid ignored_chainhash;
struct secret ignored_secret;
struct tlv_open_channel_tlvs *tlvs = tlv_open_channel_tlvs_new(tmpctx);
#if EXPERIMENTAL_FEATURES
struct tlv_channel_reestablish_tlvs *reestab_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
#endif

if (fromwire_channel_reestablish(in_pkt, channel_id,
&ignored_u64, &ignored_u64,
&ignored_secret, &ignored_pubkey))
&ignored_secret, &ignored_pubkey
#if EXPERIMENTAL_FEATURES
, reestab_tlvs
#endif
))
return true;
if (fromwire_open_channel(in_pkt, &ignored_chainhash,
channel_id, &ignored_sat,
Expand Down

0 comments on commit 3d8c4a1

Please sign in to comment.