Skip to content

Commit a44587d

Browse files
committed
Correct Channel type serialization logic
Currently, we write out the Channel's `ChannelTypeFeatures` as an odd type, implying clients which don't understand the `ChannelTypeFeatures` field can simply ignore it. This is obviously nonsense if the channel type is some future version - the client needs to fail to deserialize as it doesn't understand the channel's type. We adapt the serialization logic here to only write out the `ChannelTypeFeatures` field if it is something other than only-static-remote-key, and simply consider that "default" (as it is the only supported type today). Then, we write out the channel type as an even TLV, implying clients which do not understand it must fail to read the `Channel`. Note that we do not need to bother reserving the TLV type no longer written as it never appeared in a release (merged post-0.0.103).
1 parent 6f053e4 commit a44587d

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
@@ -5254,6 +5254,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
52545254
htlc.write(writer)?;
52555255
}
52565256

5257+
// If the channel type is something other than only-static-remote-key, then we need to have
5258+
// older clients fail to deserialize this channel at all. If the type is
5259+
// only-static-remote-key, we simply consider it "default" and don't write the channel type
5260+
// out at all.
5261+
let chan_type = if self.channel_type != ChannelTypeFeatures::only_static_remote_key() {
5262+
Some(&self.channel_type) } else { None };
5263+
52575264
write_tlv_fields!(writer, {
52585265
(0, self.announcement_sigs, option),
52595266
// minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
@@ -5263,12 +5270,12 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
52635270
// and new versions map the default values to None and allow the TLV entries here to
52645271
// override that.
52655272
(1, self.minimum_depth, option),
5273+
(2, chan_type, option),
52665274
(3, self.counterparty_selected_channel_reserve_satoshis, option),
52675275
(5, self.config, required),
52685276
(7, self.shutdown_scriptpubkey, option),
52695277
(9, self.target_closing_feerate_sats_per_kw, option),
52705278
(11, self.monitor_pending_finalized_fulfills, vec_type),
5271-
(13, self.channel_type, required),
52725279
});
52735280

52745281
Ok(())
@@ -5509,12 +5516,12 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
55095516
read_tlv_fields!(reader, {
55105517
(0, announcement_sigs, option),
55115518
(1, minimum_depth, option),
5519+
(2, channel_type, option),
55125520
(3, counterparty_selected_channel_reserve_satoshis, option),
55135521
(5, config, option), // Note that if none is provided we will *not* overwrite the existing one.
55145522
(7, shutdown_scriptpubkey, option),
55155523
(9, target_closing_feerate_sats_per_kw, option),
55165524
(11, monitor_pending_finalized_fulfills, vec_type),
5517-
(13, channel_type, option),
55185525
});
55195526

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

0 commit comments

Comments
 (0)