@@ -26,7 +26,7 @@ use util::ser::Writeable;
26
26
use util:: sha2:: Sha256 ;
27
27
use util:: logger:: Logger ;
28
28
use util:: errors:: APIError ;
29
- use util:: configurations:: { UserConfigurations , ChannelLimits , ChannelOptions } ;
29
+ use util:: configurations:: UserConfigurations ;
30
30
31
31
use std;
32
32
use std:: default:: Default ;
@@ -266,14 +266,13 @@ const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1;
266
266
// calling channel_id() before we're set up or things like get_outbound_funding_signed on an
267
267
// inbound channel.
268
268
pub ( super ) struct Channel {
269
- config : UserConfigurations ,
270
-
271
269
user_id : u64 ,
272
270
273
271
channel_id : [ u8 ; 32 ] ,
274
272
channel_state : u32 ,
275
273
channel_outbound : bool ,
276
274
secp_ctx : Secp256k1 < secp256k1:: All > ,
275
+ announce_publicly : bool ,
277
276
channel_value_satoshis : u64 ,
278
277
279
278
local_keys : ChannelKeys ,
@@ -406,7 +405,7 @@ impl Channel {
406
405
}
407
406
408
407
// Constructors:
409
- pub fn new_outbound ( fee_estimator : & FeeEstimator , chan_keys : ChannelKeys , their_node_id : PublicKey , channel_value_satoshis : u64 , push_msat : u64 , user_id : u64 , logger : Arc < Logger > , configurations : & UserConfigurations ) -> Result < Channel , APIError > {
408
+ pub fn new_outbound ( fee_estimator : & FeeEstimator , chan_keys : ChannelKeys , their_node_id : PublicKey , channel_value_satoshis : u64 , push_msat : u64 , user_id : u64 , logger : Arc < Logger > , config : & UserConfigurations ) -> Result < Channel , APIError > {
410
409
if channel_value_satoshis >= MAX_FUNDING_SATOSHIS {
411
410
return Err ( APIError :: APIMisuseError { err : "funding value > 2^24" } ) ;
412
411
}
@@ -433,14 +432,12 @@ impl Channel {
433
432
434
433
Ok ( Channel {
435
434
user_id : user_id,
436
- config : UserConfigurations {
437
- channel_options : configurations. channel_options . clone ( ) ,
438
- channel_limits : Arc :: clone ( & configurations. channel_limits ) , } ,
439
435
440
436
channel_id : rng:: rand_u832 ( ) ,
441
437
channel_state : ChannelState :: OurInitSent as u32 ,
442
438
channel_outbound : true ,
443
439
secp_ctx : secp_ctx,
440
+ announce_publicly : config. channel_options . announced_channel ,
444
441
channel_value_satoshis : channel_value_satoshis,
445
442
446
443
local_keys : chan_keys,
@@ -511,7 +508,6 @@ impl Channel {
511
508
return Err ( HandleError { err: $msg, action: Some ( msgs:: ErrorAction :: SendErrorMessage { msg: msgs:: ErrorMessage { channel_id: msg. temporary_channel_id, data: $msg. to_string( ) } } ) } ) ;
512
509
}
513
510
}
514
- let mut local_config = ( * configurations) . channel_options . clone ( ) ;
515
511
516
512
// Check sanity of message fields:
517
513
if msg. funding_satoshis >= MAX_FUNDING_SATOSHIS {
@@ -569,16 +565,14 @@ impl Channel {
569
565
// Convert things into internal flags and prep our state:
570
566
571
567
let their_announce = if ( msg. channel_flags & 1 ) == 1 { true } else { false } ;
572
- if local_config . force_announced_channel_preference {
573
- if local_config . announced_channel && !their_announce {
568
+ if configurations . channel_options . force_announced_channel_preference {
569
+ if configurations . channel_options . announced_channel && !their_announce {
574
570
return_error_message ! ( "Peer tried to open unannounced channel, but we require public ones" ) ;
575
571
}
576
- if !local_config . announced_channel && their_announce {
572
+ if !configurations . channel_options . announced_channel && their_announce {
577
573
return_error_message ! ( "Peer tried to open announced channel, but we require private ones" ) ;
578
574
}
579
575
}
580
- //we either accept their preference or the preferences match
581
- local_config. announced_channel = their_announce;
582
576
583
577
let background_feerate = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
584
578
@@ -619,14 +613,12 @@ impl Channel {
619
613
620
614
let mut chan = Channel {
621
615
user_id : user_id,
622
- config : UserConfigurations {
623
- channel_options : local_config,
624
- channel_limits : Arc :: clone ( & configurations. channel_limits ) , } ,
625
616
626
617
channel_id : msg. temporary_channel_id ,
627
618
channel_state : ( ChannelState :: OurInitSent as u32 ) | ( ChannelState :: TheirInitSent as u32 ) ,
628
619
channel_outbound : false ,
629
620
secp_ctx : secp_ctx,
621
+ announce_publicly : their_announce,
630
622
631
623
local_keys : chan_keys,
632
624
cur_local_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
@@ -1233,7 +1225,7 @@ impl Channel {
1233
1225
1234
1226
// Message handlers:
1235
1227
1236
- pub fn accept_channel ( & mut self , msg : & msgs:: AcceptChannel ) -> Result < ( ) , HandleError > {
1228
+ pub fn accept_channel ( & mut self , msg : & msgs:: AcceptChannel , config : & UserConfigurations ) -> Result < ( ) , HandleError > {
1237
1229
macro_rules! return_error_message {
1238
1230
( $msg: expr ) => {
1239
1231
return Err ( HandleError { err: $msg, action: Some ( msgs:: ErrorAction :: SendErrorMessage { msg: msgs:: ErrorMessage { channel_id: msg. temporary_channel_id, data: $msg. to_string( ) } } ) } ) ;
@@ -1277,7 +1269,7 @@ impl Channel {
1277
1269
return_error_message ! ( "max_accpted_htlcs > 483" ) ;
1278
1270
}
1279
1271
//Optional user definined limits
1280
- if msg. minimum_depth > self . config . channel_limits . minimum_depth {
1272
+ if msg. minimum_depth > config. channel_limits . minimum_depth {
1281
1273
return_error_message ! ( "We consider the minimum depth to be unreasonably large" ) ;
1282
1274
}
1283
1275
self . channel_monitor . set_their_base_keys ( & msg. htlc_basepoint , & msg. delayed_payment_basepoint ) ;
@@ -2268,7 +2260,7 @@ impl Channel {
2268
2260
}
2269
2261
2270
2262
pub fn should_announce ( & self ) -> bool {
2271
- self . config . channel_options . announced_channel
2263
+ self . announce_publicly
2272
2264
}
2273
2265
2274
2266
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
@@ -2454,7 +2446,7 @@ impl Channel {
2454
2446
delayed_payment_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . delayed_payment_base_key ) ,
2455
2447
htlc_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . htlc_base_key ) ,
2456
2448
first_per_commitment_point : PublicKey :: from_secret_key ( & self . secp_ctx , & local_commitment_secret) ,
2457
- channel_flags : if self . config . channel_options . announced_channel { 1 } else { 0 } ,
2449
+ channel_flags : if self . announce_publicly { 1 } else { 0 } ,
2458
2450
shutdown_scriptpubkey : None ,
2459
2451
}
2460
2452
}
@@ -2558,7 +2550,7 @@ impl Channel {
2558
2550
/// Note that the "channel must be funded" requirement is stricter than BOLT 7 requires - see
2559
2551
/// https://github.com/lightningnetwork/lightning-rfc/issues/468
2560
2552
pub fn get_channel_announcement ( & self , our_node_id : PublicKey , chain_hash : Sha256dHash ) -> Result < ( msgs:: UnsignedChannelAnnouncement , Signature ) , HandleError > {
2561
- if !self . config . channel_options . announced_channel {
2553
+ if !self . announce_publicly {
2562
2554
return Err ( HandleError { err : "Channel is not available for public announcements" , action : Some ( msgs:: ErrorAction :: IgnoreError ) } ) ;
2563
2555
}
2564
2556
if self . channel_state & ( ChannelState :: ChannelFunded as u32 ) == 0 {
0 commit comments