@@ -495,6 +495,7 @@ pub(super) struct Channel<Signer: Sign> {
495
495
#[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
496
496
config : ChannelConfig ,
497
497
498
+ announced : bool ,
498
499
inbound_handshake_limits_override : Option < ChannelHandshakeLimits > ,
499
500
500
501
user_id : u64 ,
@@ -855,7 +856,7 @@ impl<Signer: Sign> Channel<Signer> {
855
856
// available. If it's private, we first try `scid_privacy` as it provides better privacy
856
857
// with no other changes, and fall back to `only_static_remotekey`
857
858
let mut ret = ChannelTypeFeatures :: only_static_remote_key ( ) ;
858
- if !config. channel_options . announced_channel && config. own_channel_config . negotiate_scid_privacy {
859
+ if !config. own_channel_config . announced_channel && config. own_channel_config . negotiate_scid_privacy {
859
860
ret. set_scid_privacy_required ( ) ;
860
861
}
861
862
ret
@@ -928,9 +929,17 @@ impl<Signer: Sign> Channel<Signer> {
928
929
}
929
930
}
930
931
932
+ // Also update `ChannelConfig::announced_channel` to make sure we still allow users to
933
+ // downgrade versions after the fact.
934
+ //
935
+ // TODO: This can be removed once we prevent downgrades to v0.0.107.
936
+ let mut channel_options = config. channel_options . clone ( ) ;
937
+ channel_options. announced_channel = config. own_channel_config . announced_channel ;
938
+
931
939
Ok ( Channel {
932
940
user_id,
933
- config : config. channel_options . clone ( ) ,
941
+ config : channel_options,
942
+ announced : config. own_channel_config . announced_channel ,
934
943
inbound_handshake_limits_override : Some ( config. peer_channel_config_limits . clone ( ) ) ,
935
944
936
945
channel_id : keys_provider. get_secure_random_bytes ( ) ,
@@ -1117,7 +1126,6 @@ impl<Signer: Sign> Channel<Signer> {
1117
1126
delayed_payment_basepoint : msg. delayed_payment_basepoint ,
1118
1127
htlc_basepoint : msg. htlc_basepoint
1119
1128
} ;
1120
- let mut local_config = ( * config) . channel_options . clone ( ) ;
1121
1129
1122
1130
if config. own_channel_config . our_to_self_delay < BREAKDOWN_TIMEOUT {
1123
1131
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 ) ) ) ;
@@ -1181,13 +1189,18 @@ impl<Signer: Sign> Channel<Signer> {
1181
1189
1182
1190
// Convert things into internal flags and prep our state:
1183
1191
1192
+ // We either accept their preference or the preferences match.
1184
1193
if config. peer_channel_config_limits . force_announced_channel_preference {
1185
- if local_config . announced_channel != announced_channel {
1194
+ if config . own_channel_config . announced_channel != announced_channel {
1186
1195
return Err ( ChannelError :: Close ( "Peer tried to open channel but their announcement preference is different from ours" . to_owned ( ) ) ) ;
1187
1196
}
1188
1197
}
1189
- // we either accept their preference or the preferences match
1190
- local_config. announced_channel = announced_channel;
1198
+ // Also update `ChannelConfig::announced_channel` to make sure we still allow users to
1199
+ // downgrade versions after the fact.
1200
+ //
1201
+ // TODO: This can be removed once we prevent downgrades to v0.0.107.
1202
+ let mut channel_options = config. channel_options . clone ( ) ;
1203
+ channel_options. announced_channel = announced_channel;
1191
1204
1192
1205
let holder_selected_channel_reserve_satoshis = Channel :: < Signer > :: get_holder_selected_channel_reserve_satoshis ( msg. funding_satoshis ) ;
1193
1206
if holder_selected_channel_reserve_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS {
@@ -1254,7 +1267,8 @@ impl<Signer: Sign> Channel<Signer> {
1254
1267
1255
1268
let chan = Channel {
1256
1269
user_id,
1257
- config : local_config,
1270
+ config : channel_options,
1271
+ announced : announced_channel,
1258
1272
inbound_handshake_limits_override : None ,
1259
1273
1260
1274
channel_id : msg. temporary_channel_id ,
@@ -4556,7 +4570,7 @@ impl<Signer: Sign> Channel<Signer> {
4556
4570
}
4557
4571
4558
4572
pub fn should_announce ( & self ) -> bool {
4559
- self . config . announced_channel
4573
+ self . announced
4560
4574
}
4561
4575
4562
4576
pub fn is_outbound ( & self ) -> bool {
@@ -4896,7 +4910,7 @@ impl<Signer: Sign> Channel<Signer> {
4896
4910
delayed_payment_basepoint : keys. delayed_payment_basepoint ,
4897
4911
htlc_basepoint : keys. htlc_basepoint ,
4898
4912
first_per_commitment_point,
4899
- channel_flags : if self . config . announced_channel { 1 } else { 0 } ,
4913
+ channel_flags : if self . announced { 1 } else { 0 } ,
4900
4914
shutdown_scriptpubkey : OptionalField :: Present ( match & self . shutdown_scriptpubkey {
4901
4915
Some ( script) => script. clone ( ) . into_inner ( ) ,
4902
4916
None => Builder :: new ( ) . into_script ( ) ,
@@ -5046,7 +5060,7 @@ impl<Signer: Sign> Channel<Signer> {
5046
5060
///
5047
5061
/// This will only return ChannelError::Ignore upon failure.
5048
5062
fn get_channel_announcement ( & self , node_id : PublicKey , chain_hash : BlockHash ) -> Result < msgs:: UnsignedChannelAnnouncement , ChannelError > {
5049
- if !self . config . announced_channel {
5063
+ if !self . announced {
5050
5064
return Err ( ChannelError :: Ignore ( "Channel is not available for public announcements" . to_owned ( ) ) ) ;
5051
5065
}
5052
5066
if !self . is_usable ( ) {
@@ -6007,6 +6021,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
6007
6021
( 17 , self . announcement_sigs_state, required) ,
6008
6022
( 19 , self . latest_inbound_scid_alias, option) ,
6009
6023
( 21 , self . outbound_scid_alias, required) ,
6024
+ ( 23 , self . announced, required) ,
6010
6025
} ) ;
6011
6026
6012
6027
Ok ( ( ) )
@@ -6264,6 +6279,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6264
6279
let mut announcement_sigs_state = Some ( AnnouncementSigsState :: NotSent ) ;
6265
6280
let mut latest_inbound_scid_alias = None ;
6266
6281
let mut outbound_scid_alias = None ;
6282
+ let mut announced = None ;
6267
6283
6268
6284
read_tlv_fields ! ( reader, {
6269
6285
( 0 , announcement_sigs, option) ,
@@ -6281,6 +6297,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6281
6297
( 17 , announcement_sigs_state, option) ,
6282
6298
( 19 , latest_inbound_scid_alias, option) ,
6283
6299
( 21 , outbound_scid_alias, option) ,
6300
+ ( 23 , announced, option) ,
6284
6301
} ) ;
6285
6302
6286
6303
if let Some ( preimages) = preimages_opt {
@@ -6321,6 +6338,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6321
6338
user_id,
6322
6339
6323
6340
config : config. unwrap ( ) ,
6341
+ announced : announced. unwrap_or ( config. unwrap ( ) . announced_channel ) ,
6324
6342
6325
6343
// Note that we don't care about serializing handshake limits as we only ever serialize
6326
6344
// channel data after the handshake has completed.
@@ -6918,7 +6936,7 @@ mod tests {
6918
6936
6919
6937
let counterparty_node_id = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
6920
6938
let mut config = UserConfig :: default ( ) ;
6921
- config. channel_options . announced_channel = false ;
6939
+ config. own_channel_config . announced_channel = false ;
6922
6940
let mut chan = Channel :: < InMemorySigner > :: new_outbound ( & & feeest, & & keys_provider, counterparty_node_id, & InitFeatures :: known ( ) , 10_000_000 , 100000 , 42 , & config, 0 , 42 ) . unwrap ( ) ; // Nothing uses their network key in this test
6923
6941
chan. holder_dust_limit_satoshis = 546 ;
6924
6942
chan. counterparty_selected_channel_reserve_satoshis = Some ( 0 ) ; // Filled in in accept_channel
0 commit comments