@@ -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 ;
29
+ use util:: configurations:: { UserConfigurations , ChannelLimits , ChannelOptions } ;
30
30
31
31
use std;
32
32
use std:: default:: Default ;
@@ -266,15 +266,14 @@ 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 ,
269
270
270
- config : UserConfigurations ,
271
271
user_id : u64 ,
272
272
273
273
channel_id : [ u8 ; 32 ] ,
274
274
channel_state : u32 ,
275
275
channel_outbound : bool ,
276
276
secp_ctx : Secp256k1 < secp256k1:: All > ,
277
- announce_publicly : bool ,
278
277
channel_value_satoshis : u64 ,
279
278
280
279
local_keys : ChannelKeys ,
@@ -407,7 +406,7 @@ impl Channel {
407
406
}
408
407
409
408
// Constructors:
410
- pub fn new_outbound ( fee_estimator : & FeeEstimator , chan_keys : ChannelKeys , their_node_id : PublicKey , channel_value_satoshis : u64 , push_msat : u64 , announce_publicly : bool , user_id : u64 , logger : Arc < Logger > , configurations : & UserConfigurations ) -> Result < Channel , APIError > {
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 > {
411
410
if channel_value_satoshis >= MAX_FUNDING_SATOSHIS {
412
411
return Err ( APIError :: APIMisuseError { err : "funding value > 2^24" } ) ;
413
412
}
@@ -434,12 +433,14 @@ impl Channel {
434
433
435
434
Ok ( Channel {
436
435
user_id : user_id,
437
- config : configurations. clone ( ) ,
436
+ config : UserConfigurations {
437
+ channel_options : configurations. channel_options . clone ( ) ,
438
+ channel_limits : Arc :: clone ( & configurations. channel_limits ) , } ,
439
+
438
440
channel_id : rng:: rand_u832 ( ) ,
439
441
channel_state : ChannelState :: OurInitSent as u32 ,
440
442
channel_outbound : true ,
441
443
secp_ctx : secp_ctx,
442
- announce_publicly : announce_publicly,
443
444
channel_value_satoshis : channel_value_satoshis,
444
445
445
446
local_keys : chan_keys,
@@ -504,12 +505,13 @@ impl Channel {
504
505
/// Assumes chain_hash has already been checked and corresponds with what we expect!
505
506
/// Generally prefers to take the DisconnectPeer action on failure, as a notice to the sender
506
507
/// that we're rejecting the new channel.
507
- pub fn new_from_req ( fee_estimator : & FeeEstimator , chan_keys : ChannelKeys , their_node_id : PublicKey , msg : & msgs:: OpenChannel , user_id : u64 , require_announce : bool , allow_announce : bool , logger : Arc < Logger > , configurations : & UserConfigurations ) -> Result < Channel , HandleError > {
508
+ pub fn new_from_req ( fee_estimator : & FeeEstimator , chan_keys : ChannelKeys , their_node_id : PublicKey , msg : & msgs:: OpenChannel , user_id : u64 , logger : Arc < Logger > , configurations : & UserConfigurations ) -> Result < Channel , HandleError > {
508
509
macro_rules! return_error_message {
509
510
( $msg: expr ) => {
510
511
return Err ( HandleError { err: $msg, action: Some ( msgs:: ErrorAction :: SendErrorMessage { msg: msgs:: ErrorMessage { channel_id: msg. temporary_channel_id, data: $msg. to_string( ) } } ) } ) ;
511
512
}
512
513
}
514
+ let mut local_config = ( * configurations) . channel_options . clone ( ) ;
513
515
514
516
// Check sanity of message fields:
515
517
if msg. funding_satoshis >= MAX_FUNDING_SATOSHIS {
@@ -543,7 +545,7 @@ impl Channel {
543
545
if msg. max_accepted_htlcs > 483 {
544
546
return_error_message ! ( "max_accpted_htlcs > 483" ) ;
545
547
}
546
- //optional parameter checking
548
+ //optional parameter checking
547
549
// MAY fail the channel if
548
550
if msg. funding_satoshis < configurations. channel_limits . funding_satoshis {
549
551
return_error_message ! ( "funding satoshis is less than the user specified limit" ) ;
@@ -567,12 +569,16 @@ impl Channel {
567
569
// Convert things into internal flags and prep our state:
568
570
569
571
let their_announce = if ( msg. channel_flags & 1 ) == 1 { true } else { false } ;
570
- if require_announce && !their_announce {
571
- return_error_message ! ( "Peer tried to open unannounced channel, but we require public ones" ) ;
572
- }
573
- if !allow_announce && their_announce {
574
- return_error_message ! ( "Peer tried to open announced channel, but we require private ones" ) ;
572
+ if local_config. force_announced_channel_preference {
573
+ if local_config. announced_channel && !their_announce {
574
+ return_error_message ! ( "Peer tried to open unannounced channel, but we require public ones" ) ;
575
+ }
576
+ if !local_config. announced_channel && their_announce {
577
+ return_error_message ! ( "Peer tried to open announced channel, but we require private ones" ) ;
578
+ }
575
579
}
580
+ //we either accept their preference or the preferences match
581
+ local_config. announced_channel = their_announce;
576
582
577
583
let background_feerate = fee_estimator. get_est_sat_per_1000_weight ( ConfirmationTarget :: Background ) ;
578
584
@@ -613,12 +619,14 @@ impl Channel {
613
619
614
620
let mut chan = Channel {
615
621
user_id : user_id,
616
- config : ( * configurations) . clone ( ) ,
622
+ config : UserConfigurations {
623
+ channel_options : local_config,
624
+ channel_limits : Arc :: clone ( & configurations. channel_limits ) , } ,
625
+
617
626
channel_id : msg. temporary_channel_id ,
618
627
channel_state : ( ChannelState :: OurInitSent as u32 ) | ( ChannelState :: TheirInitSent as u32 ) ,
619
628
channel_outbound : false ,
620
629
secp_ctx : secp_ctx,
621
- announce_publicly : their_announce,
622
630
623
631
local_keys : chan_keys,
624
632
cur_local_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
@@ -1268,7 +1276,10 @@ impl Channel {
1268
1276
if msg. max_accepted_htlcs > 483 {
1269
1277
return_error_message ! ( "max_accpted_htlcs > 483" ) ;
1270
1278
}
1271
-
1279
+ //Optional user definined limits
1280
+ if msg. minimum_depth > self . config . channel_limits . minimum_depth {
1281
+ return_error_message ! ( "We consider the minimum depth to be unreasonably large" ) ;
1282
+ }
1272
1283
self . channel_monitor . set_their_base_keys ( & msg. htlc_basepoint , & msg. delayed_payment_basepoint ) ;
1273
1284
1274
1285
self . their_dust_limit_satoshis = msg. dust_limit_satoshis ;
@@ -2257,7 +2268,7 @@ impl Channel {
2257
2268
}
2258
2269
2259
2270
pub fn should_announce ( & self ) -> bool {
2260
- self . announce_publicly
2271
+ self . config . channel_options . announced_channel
2261
2272
}
2262
2273
2263
2274
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
@@ -2443,7 +2454,7 @@ impl Channel {
2443
2454
delayed_payment_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . delayed_payment_base_key ) ,
2444
2455
htlc_basepoint : PublicKey :: from_secret_key ( & self . secp_ctx , & self . local_keys . htlc_base_key ) ,
2445
2456
first_per_commitment_point : PublicKey :: from_secret_key ( & self . secp_ctx , & local_commitment_secret) ,
2446
- channel_flags : if self . announce_publicly { 1 } else { 0 } ,
2457
+ channel_flags : if self . config . channel_options . announced_channel { 1 } else { 0 } ,
2447
2458
shutdown_scriptpubkey : None ,
2448
2459
}
2449
2460
}
@@ -2547,7 +2558,7 @@ impl Channel {
2547
2558
/// Note that the "channel must be funded" requirement is stricter than BOLT 7 requires - see
2548
2559
/// https://github.com/lightningnetwork/lightning-rfc/issues/468
2549
2560
pub fn get_channel_announcement ( & self , our_node_id : PublicKey , chain_hash : Sha256dHash ) -> Result < ( msgs:: UnsignedChannelAnnouncement , Signature ) , HandleError > {
2550
- if !self . announce_publicly {
2561
+ if !self . config . channel_options . announced_channel {
2551
2562
return Err ( HandleError { err : "Channel is not available for public announcements" , action : Some ( msgs:: ErrorAction :: IgnoreError ) } ) ;
2552
2563
}
2553
2564
if self . channel_state & ( ChannelState :: ChannelFunded as u32 ) == 0 {
@@ -2909,7 +2920,9 @@ mod tests {
2909
2920
hex:: decode( "023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb" ) . unwrap( ) [ ..] ) ;
2910
2921
2911
2922
let their_node_id = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & secp_ctx, & [ 42 ; 32 ] ) . unwrap ( ) ) ;
2912
- let mut chan = Channel :: new_outbound ( & feeest, chan_keys, their_node_id, 10000000 , 100000 , false , 42 , Arc :: clone ( & logger) , & UserConfigurations :: new ( ) ) . unwrap ( ) ; // Nothing uses their network key in this test
2923
+ let mut config = UserConfigurations :: new ( ) ;
2924
+ config. channel_options . announced_channel = false ;
2925
+ let mut chan = Channel :: new_outbound ( & feeest, chan_keys, their_node_id, 10000000 , 100000 , 42 , Arc :: clone ( & logger) , & config) . unwrap ( ) ; // Nothing uses their network key in this test
2913
2926
chan. their_to_self_delay = 144 ;
2914
2927
chan. our_dust_limit_satoshis = 546 ;
2915
2928
0 commit comments