@@ -4460,7 +4460,7 @@ fn is_unsupported_shutdown_script(their_features: &InitFeatures, script: &Script
4460
4460
return !script. is_p2pkh ( ) && !script. is_p2sh ( ) && !script. is_v0_p2wpkh ( ) && !script. is_v0_p2wsh ( )
4461
4461
}
4462
4462
4463
- const SERIALIZATION_VERSION : u8 = 1 ;
4463
+ const SERIALIZATION_VERSION : u8 = 2 ;
4464
4464
const MIN_SERIALIZATION_VERSION : u8 = 1 ;
4465
4465
4466
4466
impl_writeable_tlv_based_enum ! ( InboundHTLCRemovalReason , ;
@@ -4502,7 +4502,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
4502
4502
write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
4503
4503
4504
4504
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) ?;
4506
4512
4507
4513
self . channel_id . write ( writer) ?;
4508
4514
( self . channel_state | ChannelState :: PeerDisconnected as u32 ) . write ( writer) ?;
@@ -4700,6 +4706,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
4700
4706
// override that.
4701
4707
( 1 , self . minimum_depth, option) ,
4702
4708
( 3 , self . counterparty_selected_channel_reserve_satoshis, option) ,
4709
+ ( 5 , self . config, required) ,
4703
4710
} ) ;
4704
4711
4705
4712
Ok ( ( ) )
@@ -4710,10 +4717,21 @@ const MAX_ALLOC_SIZE: usize = 64*1024;
4710
4717
impl < ' a , Signer : Sign , K : Deref > ReadableArgs < & ' a K > for Channel < Signer >
4711
4718
where K :: Target : KeysInterface < Signer = Signer > {
4712
4719
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 ) ;
4714
4721
4715
4722
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
+ }
4717
4735
4718
4736
let channel_id = Readable :: read ( reader) ?;
4719
4737
let channel_state = Readable :: read ( reader) ?;
@@ -4887,6 +4905,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4887
4905
( 0 , announcement_sigs, option) ,
4888
4906
( 1 , minimum_depth, option) ,
4889
4907
( 3 , counterparty_selected_channel_reserve_satoshis, option) ,
4908
+ ( 5 , config, option) , // Note that if none is provided we will *not* overwrite the existing one.
4890
4909
} ) ;
4891
4910
4892
4911
let mut secp_ctx = Secp256k1 :: new ( ) ;
@@ -4895,7 +4914,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4895
4914
Ok ( Channel {
4896
4915
user_id,
4897
4916
4898
- config,
4917
+ config : config . unwrap ( ) ,
4899
4918
channel_id,
4900
4919
channel_state,
4901
4920
secp_ctx,
0 commit comments