@@ -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
@@ -1061,8 +1063,9 @@ impl<Signer: Sign> Channel<Signer> {
1061
1063
1062
1064
let chan = Channel {
1063
1065
user_id,
1064
- config : local_config,
1065
1066
1067
+ config : local_config,
1068
+ commit_upfront_shutdown_pubkey : config. own_channel_config . commit_upfront_shutdown_pubkey ,
1066
1069
channel_id : msg. temporary_channel_id ,
1067
1070
channel_state : ( ChannelState :: OurInitSent as u32 ) | ( ChannelState :: TheirInitSent as u32 ) ,
1068
1071
secp_ctx,
@@ -5191,7 +5194,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5191
5194
self . config . forwarding_fee_proportional_millionths . write ( writer) ?;
5192
5195
self . config . cltv_expiry_delta . write ( writer) ?;
5193
5196
self . config . announced_channel . write ( writer) ?;
5194
- self . config . commit_upfront_shutdown_pubkey . write ( writer) ?;
5197
+ self . commit_upfront_shutdown_pubkey . write ( writer) ?;
5195
5198
5196
5199
self . channel_id . write ( writer) ?;
5197
5200
( self . channel_state | ChannelState :: PeerDisconnected as u32 ) . write ( writer) ?;
@@ -5434,6 +5437,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5434
5437
( 9 , self . target_closing_feerate_sats_per_kw, option) ,
5435
5438
( 11 , self . monitor_pending_finalized_fulfills, vec_type) ,
5436
5439
( 13 , self . channel_creation_height, required) ,
5440
+ ( 15 , self . commit_upfront_shutdown_pubkey, required) ,
5437
5441
} ) ;
5438
5442
5439
5443
Ok ( ( ) )
@@ -5455,7 +5459,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
5455
5459
config. as_mut ( ) . unwrap ( ) . forwarding_fee_proportional_millionths = Readable :: read ( reader) ?;
5456
5460
config. as_mut ( ) . unwrap ( ) . cltv_expiry_delta = Readable :: read ( reader) ?;
5457
5461
config. as_mut ( ) . unwrap ( ) . announced_channel = Readable :: read ( reader) ?;
5458
- config. as_mut ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey = Readable :: read ( reader) ?;
5462
+ config. as_mut ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey = Some ( Readable :: read ( reader) ?) ;
5459
5463
} else {
5460
5464
// Read the 8 bytes of backwards-compatibility ChannelConfig data.
5461
5465
let mut _val: u64 = Readable :: read ( reader) ?;
@@ -5675,6 +5679,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
5675
5679
// only, so we default to that if none was written.
5676
5680
let mut channel_type = Some ( ChannelTypeFeatures :: only_static_remote_key ( ) ) ;
5677
5681
let mut channel_creation_height = Some ( serialized_height) ;
5682
+ let mut commit_upfront_shutdown_pubkey = None ;
5678
5683
read_tlv_fields ! ( reader, {
5679
5684
( 0 , announcement_sigs, option) ,
5680
5685
( 1 , minimum_depth, option) ,
@@ -5687,6 +5692,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
5687
5692
( 9 , target_closing_feerate_sats_per_kw, option) ,
5688
5693
( 11 , monitor_pending_finalized_fulfills, vec_type) ,
5689
5694
( 13 , channel_creation_height, option) ,
5695
+ ( 15 , commit_upfront_shutdown_pubkey, option) ,
5690
5696
} ) ;
5691
5697
5692
5698
let chan_features = channel_type. as_ref ( ) . unwrap ( ) ;
@@ -5701,13 +5707,30 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
5701
5707
return Err ( DecodeError :: InvalidValue ) ;
5702
5708
}
5703
5709
5710
+ if commit_upfront_shutdown_pubkey. is_none ( ) {
5711
+ // commit_upfront_shutdown_pubkey has moved around a good bit, in version 1
5712
+ // serialization, it was written out as a part of the explicit field list of the
5713
+ // `ChannelConfig`. Then, it was written out as a field in the `ChannelConfig` itself.
5714
+ // Now, it is written out explicitly as its own TLV (as the field has moved to
5715
+ // `ChannelHandshakeConfig`).
5716
+ // Thus, if its not in a TLV, we here pull it from the `ChannelConfig`, and if we can't
5717
+ // find it at all, fail.
5718
+ let legacy_commit_upfront_shutdown_pubkey = config. as_ref ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey ;
5719
+ if let Some ( val) = legacy_commit_upfront_shutdown_pubkey {
5720
+ commit_upfront_shutdown_pubkey = Some ( val) ;
5721
+ } else {
5722
+ return Err ( DecodeError :: InvalidValue ) ;
5723
+ }
5724
+ }
5725
+
5704
5726
let mut secp_ctx = Secp256k1 :: new ( ) ;
5705
5727
secp_ctx. seeded_randomize ( & keys_source. get_secure_random_bytes ( ) ) ;
5706
5728
5707
5729
Ok ( Channel {
5708
5730
user_id,
5709
5731
5710
5732
config : config. unwrap ( ) ,
5733
+ commit_upfront_shutdown_pubkey : commit_upfront_shutdown_pubkey. unwrap ( ) ,
5711
5734
channel_id,
5712
5735
channel_state,
5713
5736
secp_ctx,
0 commit comments