@@ -425,6 +425,7 @@ pub(super) struct Channel<Signer: Sign> {
425425 pub ( crate ) config : ChannelConfig ,
426426 #[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
427427 config : ChannelConfig ,
428+ commit_upfront_shutdown_pubkey : bool ,
428429
429430 user_id : u64 ,
430431
@@ -751,7 +752,7 @@ impl<Signer: Sign> Channel<Signer> {
751752 let mut secp_ctx = Secp256k1 :: new ( ) ;
752753 secp_ctx. seeded_randomize ( & keys_provider. get_secure_random_bytes ( ) ) ;
753754
754- let shutdown_scriptpubkey = if config. channel_options . commit_upfront_shutdown_pubkey {
755+ let shutdown_scriptpubkey = if config. own_channel_config . commit_upfront_shutdown_pubkey {
755756 Some ( keys_provider. get_shutdown_scriptpubkey ( ) )
756757 } else { None } ;
757758
@@ -764,6 +765,7 @@ impl<Signer: Sign> Channel<Signer> {
764765 Ok ( Channel {
765766 user_id,
766767 config : config. channel_options . clone ( ) ,
768+ commit_upfront_shutdown_pubkey : config. own_channel_config . commit_upfront_shutdown_pubkey . clone ( ) ,
767769
768770 channel_id : keys_provider. get_secure_random_bytes ( ) ,
769771 channel_state : ChannelState :: OurInitSent as u32 ,
@@ -1046,7 +1048,7 @@ impl<Signer: Sign> Channel<Signer> {
10461048 }
10471049 } else { None } ;
10481050
1049- let shutdown_scriptpubkey = if config. channel_options . commit_upfront_shutdown_pubkey {
1051+ let shutdown_scriptpubkey = if config. own_channel_config . commit_upfront_shutdown_pubkey {
10501052 Some ( keys_provider. get_shutdown_scriptpubkey ( ) )
10511053 } else { None } ;
10521054
@@ -1062,7 +1064,7 @@ impl<Signer: Sign> Channel<Signer> {
10621064 let chan = Channel {
10631065 user_id,
10641066 config : local_config,
1065-
1067+ commit_upfront_shutdown_pubkey : config . own_channel_config . commit_upfront_shutdown_pubkey ,
10661068 channel_id : msg. temporary_channel_id ,
10671069 channel_state : ( ChannelState :: OurInitSent as u32 ) | ( ChannelState :: TheirInitSent as u32 ) ,
10681070 secp_ctx,
@@ -5191,7 +5193,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
51915193 self . config . forwarding_fee_proportional_millionths . write ( writer) ?;
51925194 self . config . cltv_expiry_delta . write ( writer) ?;
51935195 self . config . announced_channel . write ( writer) ?;
5194- self . config . commit_upfront_shutdown_pubkey . write ( writer) ?;
5196+ self . commit_upfront_shutdown_pubkey . write ( writer) ?;
51955197
51965198 self . channel_id . write ( writer) ?;
51975199 ( self . channel_state | ChannelState :: PeerDisconnected as u32 ) . write ( writer) ?;
@@ -5434,6 +5436,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
54345436 ( 9 , self . target_closing_feerate_sats_per_kw, option) ,
54355437 ( 11 , self . monitor_pending_finalized_fulfills, vec_type) ,
54365438 ( 13 , self . channel_creation_height, required) ,
5439+ ( 15 , self . commit_upfront_shutdown_pubkey, required) ,
54375440 } ) ;
54385441
54395442 Ok ( ( ) )
@@ -5675,6 +5678,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
56755678 // only, so we default to that if none was written.
56765679 let mut channel_type = Some ( ChannelTypeFeatures :: only_static_remote_key ( ) ) ;
56775680 let mut channel_creation_height = Some ( serialized_height) ;
5681+ let mut commit_upfront_shutdown_pubkey = None ;
56785682 read_tlv_fields ! ( reader, {
56795683 ( 0 , announcement_sigs, option) ,
56805684 ( 1 , minimum_depth, option) ,
@@ -5687,6 +5691,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
56875691 ( 9 , target_closing_feerate_sats_per_kw, option) ,
56885692 ( 11 , monitor_pending_finalized_fulfills, vec_type) ,
56895693 ( 13 , channel_creation_height, option) ,
5694+ ( 15 , commit_upfront_shutdown_pubkey, option) ,
56905695 } ) ;
56915696
56925697 let chan_features = channel_type. as_ref ( ) . unwrap ( ) ;
@@ -5701,13 +5706,29 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
57015706 return Err ( DecodeError :: InvalidValue ) ;
57025707 }
57035708
5709+ if commit_upfront_shutdown_pubkey. is_none ( ) {
5710+ // commit_upfront_shutdown_pubkey has moved around a good bit, in version 1
5711+ // serialization, it was written out as a part of the explicit field list of the
5712+ // `ChannelConfig`. Then, it was written out as a field in the `ChannelConfig` itself.
5713+ // Now, it is written out explicitly as its own TLV (as the field has moved to
5714+ // `ChannelHandshakeConfig`).
5715+ // Thus, if its not in a TLV, we here pull it from the `ChannelConfig`, and if we can't
5716+ // find it at all, fail.
5717+ let legacy_commit_upfront_shutdown_pubkey = config. as_ref ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey ;
5718+ if let Some ( val) = legacy_commit_upfront_shutdown_pubkey {
5719+ commit_upfront_shutdown_pubkey = Some ( val) ;
5720+ } else {
5721+ return Err ( DecodeError :: InvalidValue ) ;
5722+ }
5723+ }
5724+
57045725 let mut secp_ctx = Secp256k1 :: new ( ) ;
57055726 secp_ctx. seeded_randomize ( & keys_source. get_secure_random_bytes ( ) ) ;
57065727
57075728 Ok ( Channel {
57085729 user_id,
5709-
57105730 config : config. unwrap ( ) ,
5731+ commit_upfront_shutdown_pubkey : commit_upfront_shutdown_pubkey. unwrap ( ) , config : config. unwrap ( ) ,
57115732 channel_id,
57125733 channel_state,
57135734 secp_ctx,
0 commit comments