@@ -39,7 +39,7 @@ use util::events::ClosureReason;
39
39
use util:: ser:: { Readable , ReadableArgs , Writeable , Writer , VecWriter } ;
40
40
use util:: logger:: Logger ;
41
41
use util:: errors:: APIError ;
42
- use util:: config:: { UserConfig , ChannelConfig , ChannelHandshakeConfig , ChannelHandshakeLimits } ;
42
+ use util:: config:: { UserConfig , LegacyChannelConfig , ChannelHandshakeConfig , ChannelHandshakeLimits } ;
43
43
use util:: scid_utils:: scid_from_parts;
44
44
45
45
use io;
@@ -491,9 +491,9 @@ pub(crate) const MIN_AFFORDABLE_HTLC_COUNT: usize = 4;
491
491
// Counterparty designates channel data owned by the another channel participant entity.
492
492
pub ( super ) struct Channel < Signer : Sign > {
493
493
#[ cfg( any( test, feature = "_test_utils" ) ) ]
494
- pub ( crate ) config : ChannelConfig ,
494
+ pub ( crate ) config : LegacyChannelConfig ,
495
495
#[ cfg( not( any( test, feature = "_test_utils" ) ) ) ]
496
- config : ChannelConfig ,
496
+ config : LegacyChannelConfig ,
497
497
498
498
inbound_handshake_limits_override : Option < ChannelHandshakeLimits > ,
499
499
@@ -855,7 +855,7 @@ impl<Signer: Sign> Channel<Signer> {
855
855
// available. If it's private, we first try `scid_privacy` as it provides better privacy
856
856
// with no other changes, and fall back to `only_static_remotekey`
857
857
let mut ret = ChannelTypeFeatures :: only_static_remote_key ( ) ;
858
- if !config. channel_options . announced_channel && config. own_channel_config . negotiate_scid_privacy {
858
+ if !config. own_channel_config . announced_channel && config. own_channel_config . negotiate_scid_privacy {
859
859
ret. set_scid_privacy_required ( ) ;
860
860
}
861
861
ret
@@ -918,7 +918,7 @@ impl<Signer: Sign> Channel<Signer> {
918
918
let mut secp_ctx = Secp256k1 :: new ( ) ;
919
919
secp_ctx. seeded_randomize ( & keys_provider. get_secure_random_bytes ( ) ) ;
920
920
921
- let shutdown_scriptpubkey = if config. channel_options . commit_upfront_shutdown_pubkey {
921
+ let shutdown_scriptpubkey = if config. own_channel_config . commit_upfront_shutdown_pubkey {
922
922
Some ( keys_provider. get_shutdown_scriptpubkey ( ) )
923
923
} else { None } ;
924
924
@@ -930,7 +930,13 @@ impl<Signer: Sign> Channel<Signer> {
930
930
931
931
Ok ( Channel {
932
932
user_id,
933
- config : config. channel_options . clone ( ) ,
933
+
934
+ config : LegacyChannelConfig {
935
+ mutable : config. channel_options . clone ( ) ,
936
+ announced_channel : config. own_channel_config . announced_channel ,
937
+ commit_upfront_shutdown_pubkey : config. own_channel_config . commit_upfront_shutdown_pubkey ,
938
+ } ,
939
+
934
940
inbound_handshake_limits_override : Some ( config. peer_channel_config_limits . clone ( ) ) ,
935
941
936
942
channel_id : keys_provider. get_secure_random_bytes ( ) ,
@@ -1117,7 +1123,6 @@ impl<Signer: Sign> Channel<Signer> {
1117
1123
delayed_payment_basepoint : msg. delayed_payment_basepoint ,
1118
1124
htlc_basepoint : msg. htlc_basepoint
1119
1125
} ;
1120
- let mut local_config = ( * config) . channel_options . clone ( ) ;
1121
1126
1122
1127
if config. own_channel_config . our_to_self_delay < BREAKDOWN_TIMEOUT {
1123
1128
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 ) ) ) ;
@@ -1182,12 +1187,10 @@ impl<Signer: Sign> Channel<Signer> {
1182
1187
// Convert things into internal flags and prep our state:
1183
1188
1184
1189
if config. peer_channel_config_limits . force_announced_channel_preference {
1185
- if local_config . announced_channel != announced_channel {
1190
+ if config . own_channel_config . announced_channel != announced_channel {
1186
1191
return Err ( ChannelError :: Close ( "Peer tried to open channel but their announcement preference is different from ours" . to_owned ( ) ) ) ;
1187
1192
}
1188
1193
}
1189
- // we either accept their preference or the preferences match
1190
- local_config. announced_channel = announced_channel;
1191
1194
1192
1195
let holder_selected_channel_reserve_satoshis = Channel :: < Signer > :: get_holder_selected_channel_reserve_satoshis ( msg. funding_satoshis ) ;
1193
1196
if holder_selected_channel_reserve_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS {
@@ -1239,7 +1242,7 @@ impl<Signer: Sign> Channel<Signer> {
1239
1242
}
1240
1243
} else { None } ;
1241
1244
1242
- let shutdown_scriptpubkey = if config. channel_options . commit_upfront_shutdown_pubkey {
1245
+ let shutdown_scriptpubkey = if config. own_channel_config . commit_upfront_shutdown_pubkey {
1243
1246
Some ( keys_provider. get_shutdown_scriptpubkey ( ) )
1244
1247
} else { None } ;
1245
1248
@@ -1254,7 +1257,13 @@ impl<Signer: Sign> Channel<Signer> {
1254
1257
1255
1258
let chan = Channel {
1256
1259
user_id,
1257
- config : local_config,
1260
+
1261
+ config : LegacyChannelConfig {
1262
+ mutable : config. channel_options . clone ( ) ,
1263
+ announced_channel,
1264
+ commit_upfront_shutdown_pubkey : config. own_channel_config . commit_upfront_shutdown_pubkey ,
1265
+ } ,
1266
+
1258
1267
inbound_handshake_limits_override : None ,
1259
1268
1260
1269
channel_id : msg. temporary_channel_id ,
@@ -4011,7 +4020,7 @@ impl<Signer: Sign> Channel<Signer> {
4011
4020
// We always add force_close_avoidance_max_fee_satoshis to our normal
4012
4021
// feerate-calculated fee, but allow the max to be overridden if we're using a
4013
4022
// target feerate-calculated fee.
4014
- cmp:: max ( normal_feerate as u64 * tx_weight / 1000 + self . config . force_close_avoidance_max_fee_satoshis ,
4023
+ cmp:: max ( normal_feerate as u64 * tx_weight / 1000 + self . config . mutable . force_close_avoidance_max_fee_satoshis ,
4015
4024
proposed_max_feerate as u64 * tx_weight / 1000 )
4016
4025
} else {
4017
4026
self . channel_value_satoshis - ( self . value_to_self_msat + 999 ) / 1000
@@ -4471,15 +4480,15 @@ impl<Signer: Sign> Channel<Signer> {
4471
4480
}
4472
4481
4473
4482
pub fn get_fee_proportional_millionths ( & self ) -> u32 {
4474
- self . config . forwarding_fee_proportional_millionths
4483
+ self . config . mutable . forwarding_fee_proportional_millionths
4475
4484
}
4476
4485
4477
4486
pub fn get_cltv_expiry_delta ( & self ) -> u16 {
4478
- cmp:: max ( self . config . cltv_expiry_delta , MIN_CLTV_EXPIRY_DELTA )
4487
+ cmp:: max ( self . config . mutable . cltv_expiry_delta , MIN_CLTV_EXPIRY_DELTA )
4479
4488
}
4480
4489
4481
4490
pub fn get_max_dust_htlc_exposure_msat ( & self ) -> u64 {
4482
- self . config . max_dust_htlc_exposure_msat
4491
+ self . config . mutable . max_dust_htlc_exposure_msat
4483
4492
}
4484
4493
4485
4494
pub fn get_feerate ( & self ) -> u32 {
@@ -4566,7 +4575,7 @@ impl<Signer: Sign> Channel<Signer> {
4566
4575
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
4567
4576
/// Allowed in any state (including after shutdown)
4568
4577
pub fn get_outbound_forwarding_fee_base_msat ( & self ) -> u32 {
4569
- self . config . forwarding_fee_base_msat
4578
+ self . config . mutable . forwarding_fee_base_msat
4570
4579
}
4571
4580
4572
4581
/// Returns true if we've ever received a message from the remote end for this Channel
@@ -6030,11 +6039,11 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6030
6039
6031
6040
let user_id = Readable :: read ( reader) ?;
6032
6041
6033
- let mut config = Some ( ChannelConfig :: default ( ) ) ;
6042
+ let mut config = Some ( LegacyChannelConfig :: default ( ) ) ;
6034
6043
if ver == 1 {
6035
6044
// Read the old serialization of the ChannelConfig from version 0.0.98.
6036
- config. as_mut ( ) . unwrap ( ) . forwarding_fee_proportional_millionths = Readable :: read ( reader) ?;
6037
- config. as_mut ( ) . unwrap ( ) . cltv_expiry_delta = Readable :: read ( reader) ?;
6045
+ config. as_mut ( ) . unwrap ( ) . mutable . forwarding_fee_proportional_millionths = Readable :: read ( reader) ?;
6046
+ config. as_mut ( ) . unwrap ( ) . mutable . cltv_expiry_delta = Readable :: read ( reader) ?;
6038
6047
config. as_mut ( ) . unwrap ( ) . announced_channel = Readable :: read ( reader) ?;
6039
6048
config. as_mut ( ) . unwrap ( ) . commit_upfront_shutdown_pubkey = Readable :: read ( reader) ?;
6040
6049
} else {
@@ -6926,7 +6935,7 @@ mod tests {
6926
6935
6927
6936
let counterparty_node_id = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
6928
6937
let mut config = UserConfig :: default ( ) ;
6929
- config. channel_options . announced_channel = false ;
6938
+ config. own_channel_config . announced_channel = false ;
6930
6939
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
6931
6940
chan. holder_dust_limit_satoshis = 546 ;
6932
6941
chan. counterparty_selected_channel_reserve_satoshis = Some ( 0 ) ; // Filled in in accept_channel
0 commit comments