Skip to content

Commit a6da78d

Browse files
rustyrussellcdecker
authored andcommitted
channel: import upgrade spec.
See lightning/bolts#868 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent fa640b8 commit a6da78d

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
@@ -1908,12 +1908,19 @@ static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg)
19081908
u64 next_revocation_number;
19091909
struct secret your_last_per_commitment_secret;
19101910
struct pubkey my_current_per_commitment_point;
1911+
#if EXPERIMENTAL_FEATURES
1912+
struct tlv_channel_reestablish_tlvs *tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
1913+
#endif
19111914

19121915
if (!fromwire_channel_reestablish(msg, &channel_id,
19131916
&next_commitment_number,
19141917
&next_revocation_number,
19151918
&your_last_per_commitment_secret,
1916-
&my_current_per_commitment_point))
1919+
&my_current_per_commitment_point
1920+
#if EXPERIMENTAL_FEATURES
1921+
, tlvs
1922+
#endif
1923+
))
19171924
peer_failed_warn(peer->pps, &peer->channel_id,
19181925
"Bad channel_reestablish %s", tal_hex(peer, msg));
19191926

@@ -2452,6 +2459,9 @@ static void peer_reconnect(struct peer *peer,
24522459
struct secret last_local_per_commitment_secret;
24532460
bool dataloss_protect, check_extra_fields;
24542461
const u8 **premature_msgs = tal_arr(peer, const u8 *, 0);
2462+
#if EXPERIMENTAL_FEATURES
2463+
struct tlv_channel_reestablish_tlvs *send_tlvs, *recv_tlvs;
2464+
#endif
24552465

24562466
dataloss_protect = feature_negotiated(peer->our_features,
24572467
peer->their_features,
@@ -2466,6 +2476,10 @@ static void peer_reconnect(struct peer *peer,
24662476
get_per_commitment_point(peer->next_index[LOCAL] - 1,
24672477
&my_current_per_commitment_point, NULL);
24682478

2479+
#if EXPERIMENTAL_FEATURES
2480+
send_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
2481+
#endif
2482+
24692483
/* BOLT #2:
24702484
*
24712485
* - upon reconnection:
@@ -2503,14 +2517,22 @@ static void peer_reconnect(struct peer *peer,
25032517
peer->revocations_received,
25042518
last_remote_per_commit_secret,
25052519
/* Can send any (valid) point here */
2506-
&peer->remote_per_commit);
2520+
&peer->remote_per_commit
2521+
#if EXPERIMENTAL_FEATURES
2522+
, send_tlvs
2523+
#endif
2524+
);
25072525
} else {
25082526
msg = towire_channel_reestablish
25092527
(NULL, &peer->channel_id,
25102528
peer->next_index[LOCAL],
25112529
peer->revocations_received,
25122530
last_remote_per_commit_secret,
2513-
&my_current_per_commitment_point);
2531+
&my_current_per_commitment_point
2532+
#if EXPERIMENTAL_FEATURES
2533+
, send_tlvs
2534+
#endif
2535+
);
25142536
}
25152537

25162538
sync_crypto_write(peer->pps, take(msg));
@@ -2530,12 +2552,20 @@ static void peer_reconnect(struct peer *peer,
25302552
msg) ||
25312553
capture_premature_msg(&premature_msgs, msg));
25322554

2555+
#if EXPERIMENTAL_FEATURES
2556+
recv_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
2557+
#endif
2558+
25332559
if (!fromwire_channel_reestablish(msg,
25342560
&channel_id,
25352561
&next_commitment_number,
25362562
&next_revocation_number,
25372563
&last_local_per_commitment_secret,
2538-
&remote_current_per_commitment_point)) {
2564+
&remote_current_per_commitment_point
2565+
#if EXPERIMENTAL_FEATURES
2566+
, recv_tlvs
2567+
#endif
2568+
)) {
25392569
peer_failed_warn(peer->pps,
25402570
&peer->channel_id,
25412571
"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)