@@ -39,7 +39,7 @@ use util::events::ClosureReason;
3939use util:: ser:: { Readable , ReadableArgs , Writeable , Writer , VecWriter } ;
4040use util:: logger:: Logger ;
4141use util:: errors:: APIError ;
42- use util:: config:: { UserConfig , ChannelConfig } ;
42+ use util:: config:: { UserConfig , ChannelConfig , ChannelHandshakeConfig } ;
4343use util:: scid_utils:: scid_from_parts;
4444
4545use io;
@@ -426,6 +426,13 @@ pub(super) struct Channel<Signer: Sign> {
426426 #[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
427427 config : ChannelConfig ,
428428
429+ #[ cfg( any( test, feature = "_test_utils" ) ) ]
430+ pub ( crate ) forwarding_fee_base_msat : u32 ,
431+ #[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
432+ forwarding_fee_base_msat : u32 ,
433+ forwarding_fee_proportional_millionths : u32 ,
434+ cltv_expiry_delta : u16 ,
435+
429436 user_id : u64 ,
430437
431438 channel_id : [ u8 ; 32 ] ,
@@ -760,11 +767,16 @@ impl<Signer: Sign> Channel<Signer> {
760767 return Err ( APIError :: IncompatibleShutdownScript { script : shutdown_scriptpubkey. clone ( ) } ) ;
761768 }
762769 }
770+ let handshake_config = config. own_channel_config . clone ( ) ;
763771
764772 Ok ( Channel {
765773 user_id,
766774 config : config. channel_options . clone ( ) ,
767775
776+ forwarding_fee_base_msat : handshake_config. forwarding_fee_base_msat ,
777+ forwarding_fee_proportional_millionths : handshake_config. forwarding_fee_proportional_millionths ,
778+ cltv_expiry_delta : config. channel_options . clone ( ) . cltv_expiry_delta ,
779+
768780 channel_id : keys_provider. get_secure_random_bytes ( ) ,
769781 channel_state : ChannelState :: OurInitSent as u32 ,
770782 secp_ctx,
@@ -929,6 +941,7 @@ impl<Signer: Sign> Channel<Signer> {
929941 htlc_basepoint : msg. htlc_basepoint
930942 } ;
931943 let mut local_config = ( * config) . channel_options . clone ( ) ;
944+ let handshake_config = ( * config) . own_channel_config . clone ( ) ;
932945
933946 if config. own_channel_config . our_to_self_delay < BREAKDOWN_TIMEOUT {
934947 return Err ( ChannelError :: Close ( format ! ( "Configured with an unreasonable our_to_self_delay ({}) putting user funds at risks. It must be greater than {}" , config. own_channel_config. our_to_self_delay, BREAKDOWN_TIMEOUT ) ) ) ;
@@ -1063,6 +1076,10 @@ impl<Signer: Sign> Channel<Signer> {
10631076 user_id,
10641077 config : local_config,
10651078
1079+ forwarding_fee_base_msat : handshake_config. forwarding_fee_base_msat ,
1080+ forwarding_fee_proportional_millionths : handshake_config. forwarding_fee_proportional_millionths ,
1081+ cltv_expiry_delta : local_config. cltv_expiry_delta ,
1082+
10661083 channel_id : msg. temporary_channel_id ,
10671084 channel_state : ( ChannelState :: OurInitSent as u32 ) | ( ChannelState :: TheirInitSent as u32 ) ,
10681085 secp_ctx,
@@ -4052,11 +4069,11 @@ impl<Signer: Sign> Channel<Signer> {
40524069 }
40534070
40544071 pub fn get_fee_proportional_millionths ( & self ) -> u32 {
4055- self . config . forwarding_fee_proportional_millionths
4072+ self . forwarding_fee_proportional_millionths
40564073 }
40574074
40584075 pub fn get_cltv_expiry_delta ( & self ) -> u16 {
4059- cmp:: max ( self . config . cltv_expiry_delta , MIN_CLTV_EXPIRY_DELTA )
4076+ cmp:: max ( self . cltv_expiry_delta , MIN_CLTV_EXPIRY_DELTA )
40604077 }
40614078
40624079 pub fn get_max_dust_htlc_exposure_msat ( & self ) -> u64 {
@@ -4147,7 +4164,7 @@ impl<Signer: Sign> Channel<Signer> {
41474164 /// Gets the fee we'd want to charge for adding an HTLC output to this Channel
41484165 /// Allowed in any state (including after shutdown)
41494166 pub fn get_outbound_forwarding_fee_base_msat ( & self ) -> u32 {
4150- self . config . forwarding_fee_base_msat
4167+ self . forwarding_fee_base_msat
41514168 }
41524169
41534170 /// Returns true if we've ever received a message from the remote end for this Channel
@@ -5188,7 +5205,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
51885205
51895206 // Write out the old serialization for the config object. This is read by version-1
51905207 // deserializers, but we will read the version in the TLV at the end instead.
5191- self . config . forwarding_fee_proportional_millionths . write ( writer) ?;
5208+ self . forwarding_fee_proportional_millionths . write ( writer) ?;
51925209 self . config . cltv_expiry_delta . write ( writer) ?;
51935210 self . config . announced_channel . write ( writer) ?;
51945211 self . config . commit_upfront_shutdown_pubkey . write ( writer) ?;
@@ -5450,9 +5467,10 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
54505467 let user_id = Readable :: read ( reader) ?;
54515468
54525469 let mut config = Some ( ChannelConfig :: default ( ) ) ;
5470+ let handshake_config = Some ( ChannelHandshakeConfig :: default ( ) ) ;
5471+
54535472 if ver == 1 {
5454- // Read the old serialization of the ChannelConfig from version 0.0.98.
5455- config. as_mut ( ) . unwrap ( ) . forwarding_fee_proportional_millionths = Readable :: read ( reader) ?;
5473+ // Read the old serialization of the ChannelConfig from version 0.0.98.handshake_config.as_mut().unwrap().forwarding_fee_proportional_millionths = Readable::read(reader)?;
54565474 config. as_mut ( ) . unwrap ( ) . cltv_expiry_delta = Readable :: read ( reader) ?;
54575475 config. as_mut ( ) . unwrap ( ) . announced_channel = Readable :: read ( reader) ?;
54585476 config. as_mut ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey = Readable :: read ( reader) ?;
@@ -5708,6 +5726,10 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
57085726 user_id,
57095727
57105728 config : config. unwrap ( ) ,
5729+ forwarding_fee_base_msat : handshake_config. unwrap ( ) . forwarding_fee_base_msat ,
5730+ forwarding_fee_proportional_millionths : handshake_config. unwrap ( ) . forwarding_fee_proportional_millionths ,
5731+ cltv_expiry_delta : config. unwrap ( ) . cltv_expiry_delta ,
5732+
57115733 channel_id,
57125734 channel_state,
57135735 secp_ctx,
0 commit comments