@@ -10,10 +10,11 @@ use lightning::routing::gossip;
10
10
use lightning:: routing:: router:: DefaultRouter ;
11
11
use lightning:: routing:: scoring:: { ProbabilisticScorer , ProbabilisticScoringFeeParameters } ;
12
12
use lightning:: sign:: InMemorySigner ;
13
- use lightning:: util:: ser:: { Hostname , Readable , Writeable , Writer } ;
14
13
use lightning:: util:: config:: ChannelConfig as LdkChannelConfig ;
15
14
use lightning:: util:: config:: MaxDustHTLCExposure as LdkMaxDustHTLCExposure ;
16
- use lightning_net_tokio:: SocketDescriptor ; use lightning_transaction_sync:: EsploraSyncClient ;
15
+ use lightning:: util:: ser:: { Hostname , Readable , Writeable , Writer } ;
16
+ use lightning_net_tokio:: SocketDescriptor ;
17
+ use lightning_transaction_sync:: EsploraSyncClient ;
17
18
18
19
use bitcoin:: secp256k1:: PublicKey ;
19
20
use bitcoin:: OutPoint ;
@@ -22,7 +23,7 @@ use std::convert::TryFrom;
22
23
use std:: fmt:: Display ;
23
24
use std:: net:: { Ipv4Addr , Ipv6Addr , SocketAddr , SocketAddrV4 , SocketAddrV6 , ToSocketAddrs } ;
24
25
use std:: str:: FromStr ;
25
- use std:: sync:: { Arc , Mutex } ;
26
+ use std:: sync:: { Arc , Mutex , RwLock } ;
26
27
27
28
pub ( crate ) type ChainMonitor < K > = chainmonitor:: ChainMonitor <
28
29
InMemorySigner ,
@@ -396,44 +397,97 @@ impl Readable for NetAddress {
396
397
}
397
398
398
399
/// Options which apply on a per-channel basis.
400
+ ///
401
+ /// See documentation of [`LdkChannelConfig`] for details.
402
+ #[ derive( Debug ) ]
399
403
pub struct ChannelConfig {
400
- /// See documentation of [`LdkChannelConfig::forwarding_fee_proportional_millionths`].
401
- pub forwarding_fee_proportional_millionths : u32 ,
402
- /// See documentation of [`LdkChannelConfig::forwarding_fee_base_msat`].
403
- pub forwarding_fee_base_msat : u32 ,
404
- /// See documentation of [`LdkChannelConfig::cltv_expiry_delta`].
405
- pub cltv_expiry_delta : u16 ,
406
- /// See documentation of [`LdkChannelConfig::max_dust_htlc_exposure`].
407
- pub max_dust_htlc_exposure : Arc < MaxDustHTLCExposure > ,
408
- /// See documentation of [`LdkChannelConfig::force_close_avoidance_max_fee_satoshis`].
409
- pub force_close_avoidance_max_fee_satoshis : u64 ,
410
- /// See documentation of [`LdkChannelConfig::accept_underpaying_htlcs`].
411
- pub accept_underpaying_htlcs : bool ,
404
+ inner : RwLock < LdkChannelConfig > ,
405
+ }
406
+
407
+ impl Clone for ChannelConfig {
408
+ fn clone ( & self ) -> Self {
409
+ self . inner . read ( ) . unwrap ( ) . clone ( ) . into ( )
410
+ }
411
+ }
412
+
413
+ impl ChannelConfig {
414
+ /// Constructs a new `ChannelConfig`.
415
+ pub fn new ( ) -> Self {
416
+ Self :: default ( )
417
+ }
418
+
419
+ /// Returns the set `forwarding_fee_proportional_millionths`.
420
+ pub fn forwarding_fee_proportional_millionths ( & self ) -> u32 {
421
+ self . inner . read ( ) . unwrap ( ) . forwarding_fee_proportional_millionths
422
+ }
423
+
424
+ /// Sets the `forwarding_fee_proportional_millionths`.
425
+ pub fn set_forwarding_fee_proportional_millionths ( & self , value : u32 ) {
426
+ self . inner . write ( ) . unwrap ( ) . forwarding_fee_proportional_millionths = value;
427
+ }
428
+
429
+ /// Returns the set `forwarding_fee_base_msat`.
430
+ pub fn forwarding_fee_base_msat ( & self ) -> u32 {
431
+ self . inner . read ( ) . unwrap ( ) . forwarding_fee_base_msat
432
+ }
433
+
434
+ /// Sets the `forwarding_fee_base_msat`.
435
+ pub fn set_forwarding_fee_base_msat ( & self , fee_msat : u32 ) {
436
+ self . inner . write ( ) . unwrap ( ) . forwarding_fee_base_msat = fee_msat;
437
+ }
438
+
439
+ /// Returns the set `cltv_expiry_delta`.
440
+ pub fn cltv_expiry_delta ( & self ) -> u16 {
441
+ self . inner . read ( ) . unwrap ( ) . cltv_expiry_delta
442
+ }
443
+
444
+ /// Sets the `cltv_expiry_delta`.
445
+ pub fn set_cltv_expiry_delta ( & self , value : u16 ) {
446
+ self . inner . write ( ) . unwrap ( ) . cltv_expiry_delta = value;
447
+ }
448
+
449
+ /// Returns the set `force_close_avoidance_max_fee_satoshis`.
450
+ pub fn force_close_avoidance_max_fee_satoshis ( & self ) -> u64 {
451
+ self . inner . read ( ) . unwrap ( ) . force_close_avoidance_max_fee_satoshis
452
+ }
453
+
454
+ /// Sets the `force_close_avoidance_max_fee_satoshis`.
455
+ pub fn set_force_close_avoidance_max_fee_satoshis ( & self , value_sat : u64 ) {
456
+ self . inner . write ( ) . unwrap ( ) . force_close_avoidance_max_fee_satoshis = value_sat;
457
+ }
458
+
459
+ /// Returns the set `accept_underpaying_htlcs`.
460
+ pub fn accept_underpaying_htlcs ( & self ) -> bool {
461
+ self . inner . read ( ) . unwrap ( ) . accept_underpaying_htlcs
462
+ }
463
+
464
+ /// Sets the `accept_underpaying_htlcs`.
465
+ pub fn set_accept_underpaying_htlcs ( & self , value : bool ) {
466
+ self . inner . write ( ) . unwrap ( ) . accept_underpaying_htlcs = value;
467
+ }
468
+
469
+ /// Sets the `max_dust_htlc_exposure` from a fixed limit.
470
+ pub fn set_max_dust_htlc_exposure_from_fixed_limit ( & self , limit_msat : u64 ) {
471
+ self . inner . write ( ) . unwrap ( ) . max_dust_htlc_exposure =
472
+ LdkMaxDustHTLCExposure :: FixedLimitMsat ( limit_msat) ;
473
+ }
474
+
475
+ /// Sets the `max_dust_htlc_exposure` from a fee rate multiplier.
476
+ pub fn set_max_dust_htlc_exposure_from_fee_rate_multiplier ( & self , multiplier : u64 ) {
477
+ self . inner . write ( ) . unwrap ( ) . max_dust_htlc_exposure =
478
+ LdkMaxDustHTLCExposure :: FeeRateMultiplier ( multiplier) ;
479
+ }
412
480
}
413
481
414
482
impl From < LdkChannelConfig > for ChannelConfig {
415
483
fn from ( value : LdkChannelConfig ) -> Self {
416
- Self {
417
- forwarding_fee_proportional_millionths : value. forwarding_fee_proportional_millionths ,
418
- forwarding_fee_base_msat : value. forwarding_fee_base_msat ,
419
- cltv_expiry_delta : value. cltv_expiry_delta ,
420
- max_dust_htlc_exposure : Arc :: new ( MaxDustHTLCExposure ( value. max_dust_htlc_exposure ) ) ,
421
- force_close_avoidance_max_fee_satoshis : value. force_close_avoidance_max_fee_satoshis ,
422
- accept_underpaying_htlcs : value. accept_underpaying_htlcs ,
423
- }
484
+ Self { inner : RwLock :: new ( value) }
424
485
}
425
486
}
426
487
427
488
impl From < ChannelConfig > for LdkChannelConfig {
428
489
fn from ( value : ChannelConfig ) -> Self {
429
- Self {
430
- forwarding_fee_proportional_millionths : value. forwarding_fee_proportional_millionths ,
431
- forwarding_fee_base_msat : value. forwarding_fee_base_msat ,
432
- cltv_expiry_delta : value. cltv_expiry_delta ,
433
- max_dust_htlc_exposure : value. max_dust_htlc_exposure . 0 . clone ( ) ,
434
- force_close_avoidance_max_fee_satoshis : value. force_close_avoidance_max_fee_satoshis ,
435
- accept_underpaying_htlcs : value. accept_underpaying_htlcs ,
436
- }
490
+ * value. inner . read ( ) . unwrap ( )
437
491
}
438
492
}
439
493
@@ -442,20 +496,3 @@ impl Default for ChannelConfig {
442
496
LdkChannelConfig :: default ( ) . into ( )
443
497
}
444
498
}
445
-
446
- /// Options for how to set the max dust HTLC exposure allowed on a channel.
447
- ///
448
- /// See documentation of [`LdkMaxDustHTLCExposure`] for details.
449
- pub struct MaxDustHTLCExposure ( pub LdkMaxDustHTLCExposure ) ;
450
-
451
- impl MaxDustHTLCExposure {
452
- /// See documentation of [`LdkMaxDustHTLCExposure::FixedLimitMsat`] for details.
453
- pub fn from_fixed_limit ( limit_msat : u64 ) -> Self {
454
- Self ( LdkMaxDustHTLCExposure :: FixedLimitMsat ( limit_msat) )
455
- }
456
-
457
- /// See documentation of [`LdkMaxDustHTLCExposure::FeeRateMultiplier`] for details.
458
- pub fn from_fee_multiplier ( multiplier : u64 ) -> Self {
459
- Self ( LdkMaxDustHTLCExposure :: FeeRateMultiplier ( multiplier) )
460
- }
461
- }
0 commit comments