+ #[cfg(any(test, feature = "fuzztarget"))]
+ (self.historical_inbound_htlc_fulfills.len() as u64).write(writer)?;
+ #[cfg(any(test, feature = "fuzztarget"))]
+ for htlc in self.historical_inbound_htlc_fulfills.iter() {
+ htlc.write(writer)?;
+ }
+
+ // If the channel type is something other than only-static-remote-key, then we need to have
+ // older clients fail to deserialize this channel at all. If the type is
+ // only-static-remote-key, we simply consider it "default" and don't write the channel type
+ // out at all.
+ let chan_type = if self.channel_type != ChannelTypeFeatures::only_static_remote_key() {
+ Some(&self.channel_type) } else { None };
+
+ // The same logic applies for `holder_selected_channel_reserve_satoshis` and
+ // `holder_max_htlc_value_in_flight_msat` values other than the defaults.
+ let serialized_holder_selected_reserve =
+ if self.holder_selected_channel_reserve_satoshis != Self::get_holder_selected_channel_reserve_satoshis(self.channel_value_satoshis)
+ { Some(self.holder_selected_channel_reserve_satoshis) } else { None };
+ let serialized_holder_htlc_max_in_flight =
+ if self.holder_max_htlc_value_in_flight_msat != Self::get_holder_max_htlc_value_in_flight_msat(self.channel_value_satoshis)
+ { Some(self.holder_max_htlc_value_in_flight_msat) } else { None };
+
+ write_tlv_fields!(writer, {
+ (0, self.announcement_sigs, option),
+ // minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
+ // default value instead of being Option<>al. Thus, to maintain compatibility we write
+ // them twice, once with their original default values above, and once as an option
+ // here. On the read side, old versions will simply ignore the odd-type entries here,
+ // and new versions map the default values to None and allow the TLV entries here to
+ // override that.
+ (1, self.minimum_depth, option),
+ (2, chan_type, option),
+ (3, self.counterparty_selected_channel_reserve_satoshis, option),
+ (4, serialized_holder_selected_reserve, option),
+ (5, self.config, required),
+ (6, serialized_holder_htlc_max_in_flight, option),
+ (7, self.shutdown_scriptpubkey, option),
+ (9, self.target_closing_feerate_sats_per_kw, option),
+ (11, self.monitor_pending_finalized_fulfills, vec_type),
+ (13, self.channel_creation_height, required),
+ });