Skip to content

Commit 3f06e26

Browse files
committed
f Make ChannelConfig a UniFFI interface
1 parent bdad3bc commit 3f06e26

File tree

3 files changed

+100
-63
lines changed

3 files changed

+100
-63
lines changed

bindings/ldk_node.udl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,20 @@ dictionary PeerDetails {
199199
boolean is_connected;
200200
};
201201

202-
dictionary ChannelConfig {
203-
u32 forwarding_fee_proportional_millionths = 0;
204-
u32 forwarding_fee_base_msat = 1000;
205-
u16 cltv_expiry_delta = 72;
206-
MaxDustHTLCExposure max_dust_htlc_exposure;
207-
u64 force_close_avoidance_max_fee_satoshis = 1000;
208-
boolean accept_underpaying_htlcs = false;
209-
};
210-
211-
interface MaxDustHTLCExposure {
212-
[Name=from_fixed_limit]
213-
constructor(u64 limit);
214-
[Name=from_fee_multiplier]
215-
constructor(u64 multiplier);
202+
interface ChannelConfig {
203+
constructor();
204+
u32 forwarding_fee_proportional_millionths();
205+
void set_forwarding_fee_proportional_millionths(u32 value);
206+
u32 forwarding_fee_base_msat();
207+
void set_forwarding_fee_base_msat(u32 fee_msat);
208+
u16 cltv_expiry_delta();
209+
void set_cltv_expiry_delta(u16 value);
210+
u64 force_close_avoidance_max_fee_satoshis();
211+
void set_force_close_avoidance_max_fee_satoshis(u64 value_sat);
212+
boolean accept_underpaying_htlcs();
213+
void set_accept_underpaying_htlcs(boolean value);
214+
void set_max_dust_htlc_exposure_from_fixed_limit(u64 limit_msat);
215+
void set_max_dust_htlc_exposure_from_fee_rate_multiplier(u64 multiplier);
216216
};
217217

218218
enum LogLevel {

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ use payment_store::PaymentStore;
120120
pub use payment_store::{PaymentDetails, PaymentDirection, PaymentStatus};
121121
use peer_store::{PeerInfo, PeerStore};
122122
use types::{ChainMonitor, ChannelManager, KeysManager, NetworkGraph, PeerManager, Scorer};
123-
pub use types::{ChannelDetails, ChannelId, PeerDetails, UserChannelId, MaxDustHTLCExposure};
123+
pub use types::{ChannelDetails, ChannelId, PeerDetails, UserChannelId};
124124
use wallet::Wallet;
125125

126126
use logger::{log_error, log_info, log_trace, FilesystemLogger, Logger};
@@ -889,7 +889,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
889889
/// Returns a temporary channel id.
890890
pub fn connect_open_channel(
891891
&self, node_id: PublicKey, address: NetAddress, channel_amount_sats: u64,
892-
push_to_counterparty_msat: Option<u64>, channel_config: Option<ChannelConfig>,
892+
push_to_counterparty_msat: Option<u64>, channel_config: Option<Arc<ChannelConfig>>,
893893
announce_channel: bool,
894894
) -> Result<(), Error> {
895895
let rt_lock = self.runtime.read().unwrap();
@@ -919,13 +919,14 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
919919
})
920920
})?;
921921

922+
let channel_config = (*(channel_config.unwrap_or_default())).clone().into();
922923
let user_config = UserConfig {
923924
channel_handshake_limits: Default::default(),
924925
channel_handshake_config: ChannelHandshakeConfig {
925926
announced_channel: announce_channel,
926927
..Default::default()
927928
},
928-
channel_config: channel_config.unwrap_or_default().into(),
929+
channel_config,
929930
..Default::default()
930931
};
931932

@@ -1029,10 +1030,10 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
10291030
/// Update the config for a previously opened channel.
10301031
pub fn update_channel_config(
10311032
&self, channel_id: &ChannelId, counterparty_node_id: PublicKey,
1032-
channel_config: ChannelConfig,
1033+
channel_config: Arc<ChannelConfig>,
10331034
) -> Result<(), Error> {
10341035
self.channel_manager
1035-
.update_channel_config(&counterparty_node_id, &[channel_id.0], &channel_config.into())
1036+
.update_channel_config(&counterparty_node_id, &[channel_id.0], &(*channel_config).clone().into())
10361037
.map_err(|_| Error::ChannelConfigUpdateFailed)
10371038
}
10381039

src/types.rs

Lines changed: 80 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::convert::TryFrom;
2222
use std::fmt::Display;
2323
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
2424
use std::str::FromStr;
25-
use std::sync::{Arc, Mutex};
25+
use std::sync::{Arc, Mutex, RwLock};
2626

2727
pub(crate) type ChainMonitor<K> = chainmonitor::ChainMonitor<
2828
InMemorySigner,
@@ -396,44 +396,97 @@ impl Readable for NetAddress {
396396
}
397397

398398
/// Options which apply on a per-channel basis.
399+
///
400+
/// See documentation of [`LdkChannelConfig`] for details.
401+
#[derive(Debug)]
399402
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,
403+
inner: RwLock<LdkChannelConfig>,
404+
}
405+
406+
impl Clone for ChannelConfig {
407+
fn clone(&self) -> Self {
408+
self.inner.read().unwrap().clone().into()
409+
}
410+
}
411+
412+
impl ChannelConfig {
413+
/// Constructs a new `ChannelConfig`.
414+
pub fn new() -> Self {
415+
Self::default()
416+
}
417+
418+
/// Returns the set `forwarding_fee_proportional_millionths`.
419+
pub fn forwarding_fee_proportional_millionths(&self) -> u32 {
420+
self.inner.read().unwrap().forwarding_fee_proportional_millionths
421+
}
422+
423+
/// Sets the `forwarding_fee_proportional_millionths`.
424+
pub fn set_forwarding_fee_proportional_millionths(&self, value: u32) {
425+
self.inner.write().unwrap().forwarding_fee_proportional_millionths = value;
426+
}
427+
428+
/// Returns the set `forwarding_fee_base_msat`.
429+
pub fn forwarding_fee_base_msat(&self) -> u32 {
430+
self.inner.read().unwrap().forwarding_fee_base_msat
431+
}
432+
433+
/// Sets the `forwarding_fee_base_msat`.
434+
pub fn set_forwarding_fee_base_msat(&self, fee_msat: u32) {
435+
self.inner.write().unwrap().forwarding_fee_base_msat = fee_msat;
436+
}
437+
438+
/// Returns the set `cltv_expiry_delta`.
439+
pub fn cltv_expiry_delta(&self) -> u16 {
440+
self.inner.read().unwrap().cltv_expiry_delta
441+
}
442+
443+
/// Sets the `cltv_expiry_delta`.
444+
pub fn set_cltv_expiry_delta(&self, value: u16) {
445+
self.inner.write().unwrap().cltv_expiry_delta = value;
446+
}
447+
448+
/// Returns the set `force_close_avoidance_max_fee_satoshis`.
449+
pub fn force_close_avoidance_max_fee_satoshis(&self) -> u64 {
450+
self.inner.read().unwrap().force_close_avoidance_max_fee_satoshis
451+
}
452+
453+
/// Sets the `force_close_avoidance_max_fee_satoshis`.
454+
pub fn set_force_close_avoidance_max_fee_satoshis(&self, value_sat: u64) {
455+
self.inner.write().unwrap().force_close_avoidance_max_fee_satoshis = value_sat;
456+
}
457+
458+
/// Returns the set `accept_underpaying_htlcs`.
459+
pub fn accept_underpaying_htlcs(&self) -> bool {
460+
self.inner.read().unwrap().accept_underpaying_htlcs
461+
}
462+
463+
/// Sets the `accept_underpaying_htlcs`.
464+
pub fn set_accept_underpaying_htlcs(&self, value: bool) {
465+
self.inner.write().unwrap().accept_underpaying_htlcs = value;
466+
}
467+
468+
/// Sets the `max_dust_htlc_exposure` from a fixed limit.
469+
pub fn set_max_dust_htlc_exposure_from_fixed_limit(&self, limit_msat: u64) {
470+
self.inner.write().unwrap().max_dust_htlc_exposure = LdkMaxDustHTLCExposure::FixedLimitMsat(limit_msat);
471+
}
472+
473+
/// Sets the `max_dust_htlc_exposure` from a fee rate multiplier.
474+
pub fn set_max_dust_htlc_exposure_from_fee_rate_multiplier(&self, multiplier: u64) {
475+
self.inner.write().unwrap().max_dust_htlc_exposure = LdkMaxDustHTLCExposure::FeeRateMultiplier(multiplier);
476+
}
412477
}
413478

414479
impl From<LdkChannelConfig> for ChannelConfig {
415480
fn from(value: LdkChannelConfig) -> Self {
416481
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,
482+
inner: RwLock::new(value)
423483
}
424484
}
425485
}
426486

427487
impl From<ChannelConfig> for LdkChannelConfig {
428488
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-
}
489+
*value.inner.read().unwrap()
437490
}
438491
}
439492

@@ -442,20 +495,3 @@ impl Default for ChannelConfig {
442495
LdkChannelConfig::default().into()
443496
}
444497
}
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

Comments
 (0)