Skip to content

Commit 436197f

Browse files
committed
channel: import upgrade spec.
See lightning/bolts#868 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 0c45de1 commit 436197f

File tree

5 files changed

+89
-9
lines changed

5 files changed

+89
-9
lines changed

channeld/channeld.c

+34-4
Original file line numberDiff line numberDiff line change
@@ -1930,12 +1930,19 @@ static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg)
19301930
u64 next_revocation_number;
19311931
struct secret your_last_per_commitment_secret;
19321932
struct pubkey my_current_per_commitment_point;
1933+
#if EXPERIMENTAL_FEATURES
1934+
struct tlv_channel_reestablish_tlvs *tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
1935+
#endif
19331936

19341937
if (!fromwire_channel_reestablish(msg, &channel_id,
19351938
&next_commitment_number,
19361939
&next_revocation_number,
19371940
&your_last_per_commitment_secret,
1938-
&my_current_per_commitment_point))
1941+
&my_current_per_commitment_point
1942+
#if EXPERIMENTAL_FEATURES
1943+
, tlvs
1944+
#endif
1945+
))
19391946
peer_failed_warn(peer->pps, &peer->channel_id,
19401947
"Bad channel_reestablish %s", tal_hex(peer, msg));
19411948

@@ -2474,6 +2481,9 @@ static void peer_reconnect(struct peer *peer,
24742481
struct secret last_local_per_commitment_secret;
24752482
bool dataloss_protect, check_extra_fields;
24762483
const u8 **premature_msgs = tal_arr(peer, const u8 *, 0);
2484+
#if EXPERIMENTAL_FEATURES
2485+
struct tlv_channel_reestablish_tlvs *send_tlvs, *recv_tlvs;
2486+
#endif
24772487

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

2501+
#if EXPERIMENTAL_FEATURES
2502+
send_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
2503+
#endif
2504+
24912505
/* BOLT #2:
24922506
*
24932507
* - upon reconnection:
@@ -2525,14 +2539,22 @@ static void peer_reconnect(struct peer *peer,
25252539
peer->revocations_received,
25262540
last_remote_per_commit_secret,
25272541
/* Can send any (valid) point here */
2528-
&peer->remote_per_commit);
2542+
&peer->remote_per_commit
2543+
#if EXPERIMENTAL_FEATURES
2544+
, send_tlvs
2545+
#endif
2546+
);
25292547
} else {
25302548
msg = towire_channel_reestablish
25312549
(NULL, &peer->channel_id,
25322550
peer->next_index[LOCAL],
25332551
peer->revocations_received,
25342552
last_remote_per_commit_secret,
2535-
&my_current_per_commitment_point);
2553+
&my_current_per_commitment_point
2554+
#if EXPERIMENTAL_FEATURES
2555+
, send_tlvs
2556+
#endif
2557+
);
25362558
}
25372559

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

2577+
#if EXPERIMENTAL_FEATURES
2578+
recv_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
2579+
#endif
2580+
25552581
if (!fromwire_channel_reestablish(msg,
25562582
&channel_id,
25572583
&next_commitment_number,
25582584
&next_revocation_number,
25592585
&last_local_per_commitment_secret,
2560-
&remote_current_per_commitment_point)) {
2586+
&remote_current_per_commitment_point
2587+
#if EXPERIMENTAL_FEATURES
2588+
, recv_tlvs
2589+
#endif
2590+
)) {
25612591
peer_failed_warn(peer->pps,
25622592
&peer->channel_id,
25632593
"bad reestablish msg: %s %s",

closingd/closingd.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ static void do_reconnect(struct per_peer_state *pps,
176176
struct pubkey my_current_per_commitment_point, next_commitment_point;
177177
struct secret their_secret;
178178
struct tlv_shutdown_tlvs *tlvs;
179+
#if EXPERIMENTAL_FEATURES
180+
struct tlv_channel_reestablish_tlvs *reestablish_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
181+
#endif
179182

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

@@ -201,7 +204,11 @@ static void do_reconnect(struct per_peer_state *pps,
201204
next_index[LOCAL],
202205
revocations_received,
203206
last_remote_per_commit_secret,
204-
&my_current_per_commitment_point);
207+
&my_current_per_commitment_point
208+
#if EXPERIMENTAL_FEATURES
209+
, reestablish_tlvs
210+
#endif
211+
);
205212
sync_crypto_write(pps, take(msg));
206213

207214
/* They might have already sent reestablish, which triggered us */
@@ -221,7 +228,11 @@ static void do_reconnect(struct per_peer_state *pps,
221228
&next_local_commitment_number,
222229
&next_remote_revocation_number,
223230
&their_secret,
224-
&next_commitment_point)) {
231+
&next_commitment_point
232+
#if EXPERIMENTAL_FEATURES
233+
, reestablish_tlvs
234+
#endif
235+
)) {
225236
peer_failed_warn(pps, channel_id,
226237
"bad reestablish msg: %s %s",
227238
peer_wire_name(fromwire_peektype(channel_reestablish)),

openingd/dualopend.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -3164,6 +3164,9 @@ static void do_reconnect_dance(struct state *state)
31643164
last_remote_per_commit_secret;
31653165
struct pubkey remote_current_per_commit_point;
31663166
struct tx_state *tx_state = state->tx_state;
3167+
#if EXPERIMENTAL_FEATURES
3168+
struct tlv_channel_reestablish_tlvs *tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
3169+
#endif
31673170

31683171
/* BOLT #2:
31693172
* - if `next_revocation_number` equals 0:
@@ -3177,7 +3180,11 @@ static void do_reconnect_dance(struct state *state)
31773180
msg = towire_channel_reestablish
31783181
(NULL, &state->channel_id, 1, 0,
31793182
&last_remote_per_commit_secret,
3180-
&state->first_per_commitment_point[LOCAL]);
3183+
&state->first_per_commitment_point[LOCAL]
3184+
#if EXPERIMENTAL_FEATURES
3185+
, tlvs
3186+
#endif
3187+
);
31813188
sync_crypto_write(state->pps, take(msg));
31823189

31833190
peer_billboard(false, "Sent reestablish, waiting for theirs");
@@ -3200,7 +3207,11 @@ static void do_reconnect_dance(struct state *state)
32003207
&next_commitment_number,
32013208
&next_revocation_number,
32023209
&last_local_per_commit_secret,
3203-
&remote_current_per_commit_point))
3210+
&remote_current_per_commit_point
3211+
#if EXPERIMENTAL_FEATURES
3212+
, tlvs
3213+
#endif
3214+
))
32043215
open_err_fatal(state, "Bad reestablish msg: %s %s",
32053216
peer_wire_name(fromwire_peektype(msg)),
32063217
tal_hex(msg, msg));
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--- wire/peer_wire.csv 2021-05-09 15:44:59.166135652 +0930
2+
+++ wire/peer_wire.csv.raw 2021-05-11 09:59:31.695459756 +0930
3+
@@ -221,6 +131,18 @@
4+
msgdata,channel_reestablish,next_revocation_number,u64,
5+
msgdata,channel_reestablish,your_last_per_commitment_secret,byte,32
6+
msgdata,channel_reestablish,my_current_per_commitment_point,point,
7+
+msgdata,channel_reestablish,tlvs,channel_reestablish_tlvs,
8+
+tlvtype,channel_reestablish_tlvs,next_to_send,1
9+
+tlvdata,channel_reestablish_tlvs,next_to_send,commitment_number,tu64,
10+
+tlvtype,channel_reestablish_tlvs,desired_type,3
11+
+tlvdata,channel_reestablish_tlvs,desired_type,type,channel_type,
12+
+tlvtype,channel_reestablish_tlvs,current_type,5
13+
+tlvdata,channel_reestablish_tlvs,current_type,type,channel_type,
14+
+tlvtype,channel_reestablish_tlvs,upgradable,7
15+
+tlvdata,channel_reestablish_tlvs,upgradable,upgrades,channel_type,...
16+
+subtype,channel_type
17+
+subtypedata,channel_type,len,u16,
18+
+subtypedata,channel_type,features,byte,len
19+
msgtype,announcement_signatures,259
20+
msgdata,announcement_signatures,channel_id,channel_id,
21+
msgdata,announcement_signatures,short_channel_id,short_channel_id,

wire/peer_wire.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,17 @@ bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
124124
struct bitcoin_blkid ignored_chainhash;
125125
struct secret ignored_secret;
126126
struct tlv_open_channel_tlvs *tlvs = tlv_open_channel_tlvs_new(tmpctx);
127+
#if EXPERIMENTAL_FEATURES
128+
struct tlv_channel_reestablish_tlvs *reestab_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
129+
#endif
127130

128131
if (fromwire_channel_reestablish(in_pkt, channel_id,
129132
&ignored_u64, &ignored_u64,
130-
&ignored_secret, &ignored_pubkey))
133+
&ignored_secret, &ignored_pubkey
134+
#if EXPERIMENTAL_FEATURES
135+
, reestab_tlvs
136+
#endif
137+
))
131138
return true;
132139
if (fromwire_open_channel(in_pkt, &ignored_chainhash,
133140
channel_id, &ignored_sat,

0 commit comments

Comments
 (0)