Skip to content

Commit 4a3139d

Browse files
authored
Merge pull request #1161 from TheBlueMatt/2021-11-fix-chan-type-ser
Correct Channel type serialization logic
2 parents 4d6c262 + a44587d commit 4a3139d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5257,6 +5257,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
52575257
htlc.write(writer)?;
52585258
}
52595259

5260+
// If the channel type is something other than only-static-remote-key, then we need to have
5261+
// older clients fail to deserialize this channel at all. If the type is
5262+
// only-static-remote-key, we simply consider it "default" and don't write the channel type
5263+
// out at all.
5264+
let chan_type = if self.channel_type != ChannelTypeFeatures::only_static_remote_key() {
5265+
Some(&self.channel_type) } else { None };
5266+
52605267
write_tlv_fields!(writer, {
52615268
(0, self.announcement_sigs, option),
52625269
// minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
@@ -5266,12 +5273,12 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
52665273
// and new versions map the default values to None and allow the TLV entries here to
52675274
// override that.
52685275
(1, self.minimum_depth, option),
5276+
(2, chan_type, option),
52695277
(3, self.counterparty_selected_channel_reserve_satoshis, option),
52705278
(5, self.config, required),
52715279
(7, self.shutdown_scriptpubkey, option),
52725280
(9, self.target_closing_feerate_sats_per_kw, option),
52735281
(11, self.monitor_pending_finalized_fulfills, vec_type),
5274-
(13, self.channel_type, required),
52755282
});
52765283

52775284
Ok(())
@@ -5512,12 +5519,12 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
55125519
read_tlv_fields!(reader, {
55135520
(0, announcement_sigs, option),
55145521
(1, minimum_depth, option),
5522+
(2, channel_type, option),
55155523
(3, counterparty_selected_channel_reserve_satoshis, option),
55165524
(5, config, option), // Note that if none is provided we will *not* overwrite the existing one.
55175525
(7, shutdown_scriptpubkey, option),
55185526
(9, target_closing_feerate_sats_per_kw, option),
55195527
(11, monitor_pending_finalized_fulfills, vec_type),
5520-
(13, channel_type, option),
55215528
});
55225529

55235530
let chan_features = channel_type.as_ref().unwrap();

0 commit comments

Comments
 (0)