@@ -425,6 +425,7 @@ pub(super) struct Channel<Signer: Sign> {
425
425
pub ( crate ) config : ChannelConfig ,
426
426
#[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
427
427
config : ChannelConfig ,
428
+ commit_upfront_shutdown_pubkey : bool ,
428
429
429
430
user_id : u64 ,
430
431
@@ -751,7 +752,7 @@ impl<Signer: Sign> Channel<Signer> {
751
752
let mut secp_ctx = Secp256k1 :: new ( ) ;
752
753
secp_ctx. seeded_randomize ( & keys_provider. get_secure_random_bytes ( ) ) ;
753
754
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 {
755
756
Some ( keys_provider. get_shutdown_scriptpubkey ( ) )
756
757
} else { None } ;
757
758
@@ -764,6 +765,7 @@ impl<Signer: Sign> Channel<Signer> {
764
765
Ok ( Channel {
765
766
user_id,
766
767
config : config. channel_options . clone ( ) ,
768
+ commit_upfront_shutdown_pubkey : config. own_channel_config . commit_upfront_shutdown_pubkey . clone ( ) ,
767
769
768
770
channel_id : keys_provider. get_secure_random_bytes ( ) ,
769
771
channel_state : ChannelState :: OurInitSent as u32 ,
@@ -1046,7 +1048,7 @@ impl<Signer: Sign> Channel<Signer> {
1046
1048
}
1047
1049
} else { None } ;
1048
1050
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 {
1050
1052
Some ( keys_provider. get_shutdown_scriptpubkey ( ) )
1051
1053
} else { None } ;
1052
1054
@@ -1062,7 +1064,7 @@ impl<Signer: Sign> Channel<Signer> {
1062
1064
let chan = Channel {
1063
1065
user_id,
1064
1066
config : local_config,
1065
-
1067
+ commit_upfront_shutdown_pubkey : config . own_channel_config . commit_upfront_shutdown_pubkey ,
1066
1068
channel_id : msg. temporary_channel_id ,
1067
1069
channel_state : ( ChannelState :: OurInitSent as u32 ) | ( ChannelState :: TheirInitSent as u32 ) ,
1068
1070
secp_ctx,
@@ -5191,7 +5193,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5191
5193
self . config . forwarding_fee_proportional_millionths . write ( writer) ?;
5192
5194
self . config . cltv_expiry_delta . write ( writer) ?;
5193
5195
self . config . announced_channel . write ( writer) ?;
5194
- self . config . commit_upfront_shutdown_pubkey . write ( writer) ?;
5196
+ self . commit_upfront_shutdown_pubkey . write ( writer) ?;
5195
5197
5196
5198
self . channel_id . write ( writer) ?;
5197
5199
( self . channel_state | ChannelState :: PeerDisconnected as u32 ) . write ( writer) ?;
@@ -5434,6 +5436,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5434
5436
( 9 , self . target_closing_feerate_sats_per_kw, option) ,
5435
5437
( 11 , self . monitor_pending_finalized_fulfills, vec_type) ,
5436
5438
( 13 , self . channel_creation_height, required) ,
5439
+ ( 15 , self . commit_upfront_shutdown_pubkey, required) ,
5437
5440
} ) ;
5438
5441
5439
5442
Ok ( ( ) )
@@ -5675,6 +5678,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
5675
5678
// only, so we default to that if none was written.
5676
5679
let mut channel_type = Some ( ChannelTypeFeatures :: only_static_remote_key ( ) ) ;
5677
5680
let mut channel_creation_height = Some ( serialized_height) ;
5681
+ let mut commit_upfront_shutdown_pubkey = None ;
5678
5682
read_tlv_fields ! ( reader, {
5679
5683
( 0 , announcement_sigs, option) ,
5680
5684
( 1 , minimum_depth, option) ,
@@ -5687,6 +5691,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
5687
5691
( 9 , target_closing_feerate_sats_per_kw, option) ,
5688
5692
( 11 , monitor_pending_finalized_fulfills, vec_type) ,
5689
5693
( 13 , channel_creation_height, option) ,
5694
+ ( 15 , commit_upfront_shutdown_pubkey, option) ,
5690
5695
} ) ;
5691
5696
5692
5697
let chan_features = channel_type. as_ref ( ) . unwrap ( ) ;
@@ -5701,13 +5706,28 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
5701
5706
return Err ( DecodeError :: InvalidValue ) ;
5702
5707
}
5703
5708
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
+
5704
5725
let mut secp_ctx = Secp256k1 :: new ( ) ;
5705
5726
secp_ctx. seeded_randomize ( & keys_source. get_secure_random_bytes ( ) ) ;
5706
5727
5707
5728
Ok ( Channel {
5708
5729
user_id,
5709
-
5710
- config : config. unwrap ( ) ,
5730
+ commit_upfront_shutdown_pubkey : commit_upfront_shutdown_pubkey. unwrap ( ) , config : config. unwrap ( ) ,
5711
5731
channel_id,
5712
5732
channel_state,
5713
5733
secp_ctx,
0 commit comments