@@ -4460,7 +4460,7 @@ fn is_unsupported_shutdown_script(their_features: &InitFeatures, script: &Script
44604460 return !script. is_p2pkh ( ) && !script. is_p2sh ( ) && !script. is_v0_p2wpkh ( ) && !script. is_v0_p2wsh ( )
44614461}
44624462
4463- const SERIALIZATION_VERSION : u8 = 1 ;
4463+ const SERIALIZATION_VERSION : u8 = 2 ;
44644464const MIN_SERIALIZATION_VERSION : u8 = 1 ;
44654465
44664466impl_writeable_tlv_based_enum ! ( InboundHTLCRemovalReason , ;
@@ -4502,7 +4502,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
45024502 write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
45034503
45044504 self . user_id . write ( writer) ?;
4505- self . config . write ( writer) ?;
4505+
4506+ // Write out the old serialization for the config object. This is read by version-1
4507+ // deserializers, but we will read the version in the TLV at the end instead.
4508+ self . config . fee_proportional_millionths . write ( writer) ?;
4509+ self . config . cltv_expiry_delta . write ( writer) ?;
4510+ self . config . announced_channel . write ( writer) ?;
4511+ self . config . commit_upfront_shutdown_pubkey . write ( writer) ?;
45064512
45074513 self . channel_id . write ( writer) ?;
45084514 ( self . channel_state | ChannelState :: PeerDisconnected as u32 ) . write ( writer) ?;
@@ -4700,6 +4706,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
47004706 // override that.
47014707 ( 1 , self . minimum_depth, option) ,
47024708 ( 3 , self . counterparty_selected_channel_reserve_satoshis, option) ,
4709+ ( 5 , self . config, required) ,
47034710 } ) ;
47044711
47054712 Ok ( ( ) )
@@ -4710,10 +4717,21 @@ const MAX_ALLOC_SIZE: usize = 64*1024;
47104717impl < ' a , Signer : Sign , K : Deref > ReadableArgs < & ' a K > for Channel < Signer >
47114718 where K :: Target : KeysInterface < Signer = Signer > {
47124719 fn read < R : :: std:: io:: Read > ( reader : & mut R , keys_source : & ' a K ) -> Result < Self , DecodeError > {
4713- let _ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
4720+ let ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
47144721
47154722 let user_id = Readable :: read ( reader) ?;
4716- let config: ChannelConfig = Readable :: read ( reader) ?;
4723+
4724+ let mut config = Some ( ChannelConfig :: default ( ) ) ;
4725+ if ver == 1 {
4726+ // Read the old serialization of the ChannelConfig from version 0.0.98.
4727+ config. as_mut ( ) . unwrap ( ) . fee_proportional_millionths = Readable :: read ( reader) ?;
4728+ config. as_mut ( ) . unwrap ( ) . cltv_expiry_delta = Readable :: read ( reader) ?;
4729+ config. as_mut ( ) . unwrap ( ) . announced_channel = Readable :: read ( reader) ?;
4730+ config. as_mut ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey = Readable :: read ( reader) ?;
4731+ } else {
4732+ // Read the 8 bytes of backwards-compatibility ChannelConfig data.
4733+ let mut _val: u64 = Readable :: read ( reader) ?;
4734+ }
47174735
47184736 let channel_id = Readable :: read ( reader) ?;
47194737 let channel_state = Readable :: read ( reader) ?;
@@ -4887,6 +4905,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
48874905 ( 0 , announcement_sigs, option) ,
48884906 ( 1 , minimum_depth, option) ,
48894907 ( 3 , counterparty_selected_channel_reserve_satoshis, option) ,
4908+ ( 5 , config, option) , // Note that if none is provided we will *not* overwrite the existing one.
48904909 } ) ;
48914910
48924911 let mut secp_ctx = Secp256k1 :: new ( ) ;
@@ -4895,7 +4914,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
48954914 Ok ( Channel {
48964915 user_id,
48974916
4898- config,
4917+ config : config . unwrap ( ) ,
48994918 channel_id,
49004919 channel_state,
49014920 secp_ctx,
0 commit comments