@@ -4439,7 +4439,7 @@ fn is_unsupported_shutdown_script(their_features: &InitFeatures, script: &Script
44394439 return !script. is_p2pkh ( ) && !script. is_p2sh ( ) && !script. is_v0_p2wpkh ( ) && !script. is_v0_p2wsh ( )
44404440}
44414441
4442- const SERIALIZATION_VERSION : u8 = 1 ;
4442+ const SERIALIZATION_VERSION : u8 = 2 ;
44434443const MIN_SERIALIZATION_VERSION : u8 = 1 ;
44444444
44454445impl_writeable_tlv_based_enum ! ( InboundHTLCRemovalReason , ;
@@ -4481,7 +4481,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
44814481 write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
44824482
44834483 self . user_id . write ( writer) ?;
4484- self . config . write ( writer) ?;
4484+
4485+ // Write out the old serialization for the config object. This is read by version-1
4486+ // deserializers, but we will read the version in the TLV at the end instead.
4487+ self . config . fee_proportional_millionths . write ( writer) ?;
4488+ self . config . cltv_expiry_delta . write ( writer) ?;
4489+ self . config . announced_channel . write ( writer) ?;
4490+ self . config . commit_upfront_shutdown_pubkey . write ( writer) ?;
44854491
44864492 self . channel_id . write ( writer) ?;
44874493 ( self . channel_state | ChannelState :: PeerDisconnected as u32 ) . write ( writer) ?;
@@ -4669,7 +4675,10 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
46694675
46704676 self . channel_update_status . write ( writer) ?;
46714677
4672- write_tlv_fields ! ( writer, { ( 0 , self . announcement_sigs, option) } ) ;
4678+ write_tlv_fields ! ( writer, {
4679+ ( 0 , self . announcement_sigs, option) ,
4680+ ( 1 , self . config, required) ,
4681+ } ) ;
46734682
46744683 Ok ( ( ) )
46754684 }
@@ -4679,10 +4688,21 @@ const MAX_ALLOC_SIZE: usize = 64*1024;
46794688impl < ' a , Signer : Sign , K : Deref > ReadableArgs < & ' a K > for Channel < Signer >
46804689 where K :: Target : KeysInterface < Signer = Signer > {
46814690 fn read < R : :: std:: io:: Read > ( reader : & mut R , keys_source : & ' a K ) -> Result < Self , DecodeError > {
4682- let _ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
4691+ let ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
46834692
46844693 let user_id = Readable :: read ( reader) ?;
4685- let config: ChannelConfig = Readable :: read ( reader) ?;
4694+
4695+ let mut config = Some ( ChannelConfig :: default ( ) ) ;
4696+ if ver == 1 {
4697+ // Read the old serialization of the ChannelConfig from version 0.0.98.
4698+ config. as_mut ( ) . unwrap ( ) . fee_proportional_millionths = Readable :: read ( reader) ?;
4699+ config. as_mut ( ) . unwrap ( ) . cltv_expiry_delta = Readable :: read ( reader) ?;
4700+ config. as_mut ( ) . unwrap ( ) . announced_channel = Readable :: read ( reader) ?;
4701+ config. as_mut ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey = Readable :: read ( reader) ?;
4702+ } else {
4703+ // Read the 8 bytes of backwards-compatibility ChannelConfig data.
4704+ let mut _val: u64 = Readable :: read ( reader) ?;
4705+ }
46864706
46874707 let channel_id = Readable :: read ( reader) ?;
46884708 let channel_state = Readable :: read ( reader) ?;
@@ -4842,15 +4862,18 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
48424862 let channel_update_status = Readable :: read ( reader) ?;
48434863
48444864 let mut announcement_sigs = None ;
4845- read_tlv_fields ! ( reader, { ( 0 , announcement_sigs, option) } ) ;
4865+ read_tlv_fields ! ( reader, {
4866+ ( 0 , announcement_sigs, option) ,
4867+ ( 1 , config, option) , // Note that if none is provided we will *not* overwrite the existing one.
4868+ } ) ;
48464869
48474870 let mut secp_ctx = Secp256k1 :: new ( ) ;
48484871 secp_ctx. seeded_randomize ( & keys_source. get_secure_random_bytes ( ) ) ;
48494872
48504873 Ok ( Channel {
48514874 user_id,
48524875
4853- config,
4876+ config : config . unwrap ( ) ,
48544877 channel_id,
48554878 channel_state,
48564879 secp_ctx,
0 commit comments