@@ -4431,7 +4431,7 @@ fn is_unsupported_shutdown_script(their_features: &InitFeatures, script: &Script
44314431 return !script. is_p2pkh ( ) && !script. is_p2sh ( ) && !script. is_v0_p2wpkh ( ) && !script. is_v0_p2wsh ( )
44324432}
44334433
4434- const SERIALIZATION_VERSION : u8 = 1 ;
4434+ const SERIALIZATION_VERSION : u8 = 2 ;
44354435const MIN_SERIALIZATION_VERSION : u8 = 1 ;
44364436
44374437impl_writeable_tlv_based_enum ! ( InboundHTLCRemovalReason , ;
@@ -4473,7 +4473,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
44734473 write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
44744474
44754475 self . user_id . write ( writer) ?;
4476- self . config . write ( writer) ?;
4476+
4477+ // Write out the old serialization for the config object. This is read by version-1
4478+ // deserializers, but we will read the version in the TLV at the end instead.
4479+ self . config . fee_proportional_millionths . write ( writer) ?;
4480+ self . config . cltv_expiry_delta . write ( writer) ?;
4481+ self . config . announced_channel . write ( writer) ?;
4482+ self . config . commit_upfront_shutdown_pubkey . write ( writer) ?;
44774483
44784484 self . channel_id . write ( writer) ?;
44794485 ( self . channel_state | ChannelState :: PeerDisconnected as u32 ) . write ( writer) ?;
@@ -4661,7 +4667,10 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
46614667
46624668 self . channel_update_status . write ( writer) ?;
46634669
4664- write_tlv_fields ! ( writer, { ( 0 , self . announcement_sigs, option) } ) ;
4670+ write_tlv_fields ! ( writer, {
4671+ ( 0 , self . announcement_sigs, option) ,
4672+ ( 1 , self . config, required) ,
4673+ } ) ;
46654674
46664675 Ok ( ( ) )
46674676 }
@@ -4671,10 +4680,21 @@ const MAX_ALLOC_SIZE: usize = 64*1024;
46714680impl < ' a , Signer : Sign , K : Deref > ReadableArgs < & ' a K > for Channel < Signer >
46724681 where K :: Target : KeysInterface < Signer = Signer > {
46734682 fn read < R : :: std:: io:: Read > ( reader : & mut R , keys_source : & ' a K ) -> Result < Self , DecodeError > {
4674- let _ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
4683+ let ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
46754684
46764685 let user_id = Readable :: read ( reader) ?;
4677- let config: ChannelConfig = Readable :: read ( reader) ?;
4686+
4687+ let mut config = Some ( ChannelConfig :: default ( ) ) ;
4688+ if ver == 1 {
4689+ // Read the old serialization of the ChannelConfig from version 0.0.98.
4690+ config. as_mut ( ) . unwrap ( ) . fee_proportional_millionths = Readable :: read ( reader) ?;
4691+ config. as_mut ( ) . unwrap ( ) . cltv_expiry_delta = Readable :: read ( reader) ?;
4692+ config. as_mut ( ) . unwrap ( ) . announced_channel = Readable :: read ( reader) ?;
4693+ config. as_mut ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey = Readable :: read ( reader) ?;
4694+ } else {
4695+ // Read the 8 bytes of backwards-compatibility ChannelConfig data.
4696+ let mut _val: u64 = Readable :: read ( reader) ?;
4697+ }
46784698
46794699 let channel_id = Readable :: read ( reader) ?;
46804700 let channel_state = Readable :: read ( reader) ?;
@@ -4834,15 +4854,18 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
48344854 let channel_update_status = Readable :: read ( reader) ?;
48354855
48364856 let mut announcement_sigs = None ;
4837- read_tlv_fields ! ( reader, { ( 0 , announcement_sigs, option) } ) ;
4857+ read_tlv_fields ! ( reader, {
4858+ ( 0 , announcement_sigs, option) ,
4859+ ( 1 , config, option) , // Note that if none is provided we will *not* overwrite the existing one.
4860+ } ) ;
48384861
48394862 let mut secp_ctx = Secp256k1 :: new ( ) ;
48404863 secp_ctx. seeded_randomize ( & keys_source. get_secure_random_bytes ( ) ) ;
48414864
48424865 Ok ( Channel {
48434866 user_id,
48444867
4845- config,
4868+ config : config . unwrap ( ) ,
48464869 channel_id,
48474870 channel_state,
48484871 secp_ctx,
0 commit comments