Skip to content

Commit b628dc2

Browse files
committed
Prefactor: Move ChannelConfig to config
.. to also expose it via the `config` module rather than at the top-level docs.
1 parent 7bf1417 commit b628dc2

File tree

4 files changed

+121
-121
lines changed

4 files changed

+121
-121
lines changed

src/config.rs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use crate::payment::SendingParameters;
1111

1212
use lightning::ln::msgs::SocketAddress;
1313
use lightning::routing::gossip::NodeAlias;
14+
use lightning::util::config::ChannelConfig as LdkChannelConfig;
15+
use lightning::util::config::MaxDustHTLCExposure as LdkMaxDustHTLCExposure;
1416
use lightning::util::config::UserConfig;
1517
use lightning::util::logger::Level as LogLevel;
1618

@@ -300,6 +302,122 @@ pub(crate) fn default_user_config(config: &Config) -> UserConfig {
300302
user_config
301303
}
302304

305+
/// Options which apply on a per-channel basis and may change at runtime or based on negotiation
306+
/// with our counterparty.
307+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
308+
pub struct ChannelConfig {
309+
/// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
310+
/// over the channel.
311+
/// This may be allowed to change at runtime in a later update, however doing so must result in
312+
/// update messages sent to notify all nodes of our updated relay fee.
313+
///
314+
/// Please refer to [`LdkChannelConfig`] for further details.
315+
pub forwarding_fee_proportional_millionths: u32,
316+
/// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
317+
/// excess of [`ChannelConfig::forwarding_fee_proportional_millionths`].
318+
/// This may be allowed to change at runtime in a later update, however doing so must result in
319+
/// update messages sent to notify all nodes of our updated relay fee.
320+
///
321+
/// Please refer to [`LdkChannelConfig`] for further details.
322+
pub forwarding_fee_base_msat: u32,
323+
/// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
324+
/// the channel this config applies to.
325+
///
326+
/// Please refer to [`LdkChannelConfig`] for further details.
327+
pub cltv_expiry_delta: u16,
328+
/// Limit our total exposure to potential loss to on-chain fees on close, including in-flight
329+
/// HTLCs which are burned to fees as they are too small to claim on-chain and fees on
330+
/// commitment transaction(s) broadcasted by our counterparty in excess of our own fee estimate.
331+
///
332+
/// Please refer to [`LdkChannelConfig`] for further details.
333+
pub max_dust_htlc_exposure: MaxDustHTLCExposure,
334+
/// The additional fee we're willing to pay to avoid waiting for the counterparty's
335+
/// `to_self_delay` to reclaim funds.
336+
///
337+
/// Please refer to [`LdkChannelConfig`] for further details.
338+
pub force_close_avoidance_max_fee_satoshis: u64,
339+
/// If set, allows this channel's counterparty to skim an additional fee off this node's inbound
340+
/// HTLCs. Useful for liquidity providers to offload on-chain channel costs to end users.
341+
///
342+
/// Please refer to [`LdkChannelConfig`] for further details.
343+
pub accept_underpaying_htlcs: bool,
344+
}
345+
346+
impl From<LdkChannelConfig> for ChannelConfig {
347+
fn from(value: LdkChannelConfig) -> Self {
348+
Self {
349+
forwarding_fee_proportional_millionths: value.forwarding_fee_proportional_millionths,
350+
forwarding_fee_base_msat: value.forwarding_fee_base_msat,
351+
cltv_expiry_delta: value.cltv_expiry_delta,
352+
max_dust_htlc_exposure: value.max_dust_htlc_exposure.into(),
353+
force_close_avoidance_max_fee_satoshis: value.force_close_avoidance_max_fee_satoshis,
354+
accept_underpaying_htlcs: value.accept_underpaying_htlcs,
355+
}
356+
}
357+
}
358+
359+
impl From<ChannelConfig> for LdkChannelConfig {
360+
fn from(value: ChannelConfig) -> Self {
361+
Self {
362+
forwarding_fee_proportional_millionths: value.forwarding_fee_proportional_millionths,
363+
forwarding_fee_base_msat: value.forwarding_fee_base_msat,
364+
cltv_expiry_delta: value.cltv_expiry_delta,
365+
max_dust_htlc_exposure: value.max_dust_htlc_exposure.into(),
366+
force_close_avoidance_max_fee_satoshis: value.force_close_avoidance_max_fee_satoshis,
367+
accept_underpaying_htlcs: value.accept_underpaying_htlcs,
368+
}
369+
}
370+
}
371+
372+
impl Default for ChannelConfig {
373+
fn default() -> Self {
374+
LdkChannelConfig::default().into()
375+
}
376+
}
377+
378+
/// Options for how to set the max dust exposure allowed on a channel.
379+
///
380+
/// See [`LdkChannelConfig::max_dust_htlc_exposure`] for details.
381+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
382+
pub enum MaxDustHTLCExposure {
383+
/// This sets a fixed limit on the total dust exposure in millisatoshis.
384+
///
385+
/// Please refer to [`LdkMaxDustHTLCExposure`] for further details.
386+
FixedLimit {
387+
/// The fixed limit, in millisatoshis.
388+
limit_msat: u64,
389+
},
390+
/// This sets a multiplier on the feerate to determine the maximum allowed dust exposure.
391+
///
392+
/// Please refer to [`LdkMaxDustHTLCExposure`] for further details.
393+
FeeRateMultiplier {
394+
/// The applied fee rate multiplier.
395+
multiplier: u64,
396+
},
397+
}
398+
399+
impl From<LdkMaxDustHTLCExposure> for MaxDustHTLCExposure {
400+
fn from(value: LdkMaxDustHTLCExposure) -> Self {
401+
match value {
402+
LdkMaxDustHTLCExposure::FixedLimitMsat(limit_msat) => Self::FixedLimit { limit_msat },
403+
LdkMaxDustHTLCExposure::FeeRateMultiplier(multiplier) => {
404+
Self::FeeRateMultiplier { multiplier }
405+
},
406+
}
407+
}
408+
}
409+
410+
impl From<MaxDustHTLCExposure> for LdkMaxDustHTLCExposure {
411+
fn from(value: MaxDustHTLCExposure) -> Self {
412+
match value {
413+
MaxDustHTLCExposure::FixedLimit { limit_msat } => Self::FixedLimitMsat(limit_msat),
414+
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } => {
415+
Self::FeeRateMultiplier(multiplier)
416+
},
417+
}
418+
}
419+
}
420+
303421
#[cfg(test)]
304422
mod tests {
305423
use std::str::FromStr;

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ pub use error::Error as NodeError;
106106
use error::Error;
107107

108108
pub use event::Event;
109-
pub use types::{ChannelConfig, MaxDustHTLCExposure};
110109

111110
pub use io::utils::generate_entropy_mnemonic;
112111

@@ -121,7 +120,7 @@ pub use builder::NodeBuilder as Builder;
121120

122121
use chain::ChainSource;
123122
use config::{
124-
default_user_config, may_announce_channel, Config, NODE_ANN_BCAST_INTERVAL,
123+
default_user_config, may_announce_channel, ChannelConfig, Config, NODE_ANN_BCAST_INTERVAL,
125124
PEER_RECONNECTION_INTERVAL, RGS_SYNC_INTERVAL,
126125
};
127126
use connection::ConnectionManager;

src/types.rs

Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// accordance with one or both of these licenses.
77

88
use crate::chain::ChainSource;
9+
use crate::config::ChannelConfig;
910
use crate::fee_estimator::OnchainFeeEstimator;
1011
use crate::logger::FilesystemLogger;
1112
use crate::message_handler::NodeCustomMessageHandler;
@@ -20,8 +21,6 @@ use lightning::routing::gossip;
2021
use lightning::routing::router::DefaultRouter;
2122
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
2223
use lightning::sign::InMemorySigner;
23-
use lightning::util::config::ChannelConfig as LdkChannelConfig;
24-
use lightning::util::config::MaxDustHTLCExposure as LdkMaxDustHTLCExposure;
2524
use lightning::util::persist::KVStore;
2625
use lightning::util::ser::{Readable, Writeable, Writer};
2726
use lightning::util::sweep::OutputSweeper;
@@ -349,119 +348,3 @@ pub struct PeerDetails {
349348
/// Indicates whether we currently have an active connection with the peer.
350349
pub is_connected: bool,
351350
}
352-
353-
/// Options which apply on a per-channel basis and may change at runtime or based on negotiation
354-
/// with our counterparty.
355-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
356-
pub struct ChannelConfig {
357-
/// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
358-
/// over the channel.
359-
/// This may be allowed to change at runtime in a later update, however doing so must result in
360-
/// update messages sent to notify all nodes of our updated relay fee.
361-
///
362-
/// Please refer to [`LdkChannelConfig`] for further details.
363-
pub forwarding_fee_proportional_millionths: u32,
364-
/// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
365-
/// excess of [`ChannelConfig::forwarding_fee_proportional_millionths`].
366-
/// This may be allowed to change at runtime in a later update, however doing so must result in
367-
/// update messages sent to notify all nodes of our updated relay fee.
368-
///
369-
/// Please refer to [`LdkChannelConfig`] for further details.
370-
pub forwarding_fee_base_msat: u32,
371-
/// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
372-
/// the channel this config applies to.
373-
///
374-
/// Please refer to [`LdkChannelConfig`] for further details.
375-
pub cltv_expiry_delta: u16,
376-
/// Limit our total exposure to potential loss to on-chain fees on close, including in-flight
377-
/// HTLCs which are burned to fees as they are too small to claim on-chain and fees on
378-
/// commitment transaction(s) broadcasted by our counterparty in excess of our own fee estimate.
379-
///
380-
/// Please refer to [`LdkChannelConfig`] for further details.
381-
pub max_dust_htlc_exposure: MaxDustHTLCExposure,
382-
/// The additional fee we're willing to pay to avoid waiting for the counterparty's
383-
/// `to_self_delay` to reclaim funds.
384-
///
385-
/// Please refer to [`LdkChannelConfig`] for further details.
386-
pub force_close_avoidance_max_fee_satoshis: u64,
387-
/// If set, allows this channel's counterparty to skim an additional fee off this node's inbound
388-
/// HTLCs. Useful for liquidity providers to offload on-chain channel costs to end users.
389-
///
390-
/// Please refer to [`LdkChannelConfig`] for further details.
391-
pub accept_underpaying_htlcs: bool,
392-
}
393-
394-
impl From<LdkChannelConfig> for ChannelConfig {
395-
fn from(value: LdkChannelConfig) -> Self {
396-
Self {
397-
forwarding_fee_proportional_millionths: value.forwarding_fee_proportional_millionths,
398-
forwarding_fee_base_msat: value.forwarding_fee_base_msat,
399-
cltv_expiry_delta: value.cltv_expiry_delta,
400-
max_dust_htlc_exposure: value.max_dust_htlc_exposure.into(),
401-
force_close_avoidance_max_fee_satoshis: value.force_close_avoidance_max_fee_satoshis,
402-
accept_underpaying_htlcs: value.accept_underpaying_htlcs,
403-
}
404-
}
405-
}
406-
407-
impl From<ChannelConfig> for LdkChannelConfig {
408-
fn from(value: ChannelConfig) -> Self {
409-
Self {
410-
forwarding_fee_proportional_millionths: value.forwarding_fee_proportional_millionths,
411-
forwarding_fee_base_msat: value.forwarding_fee_base_msat,
412-
cltv_expiry_delta: value.cltv_expiry_delta,
413-
max_dust_htlc_exposure: value.max_dust_htlc_exposure.into(),
414-
force_close_avoidance_max_fee_satoshis: value.force_close_avoidance_max_fee_satoshis,
415-
accept_underpaying_htlcs: value.accept_underpaying_htlcs,
416-
}
417-
}
418-
}
419-
420-
impl Default for ChannelConfig {
421-
fn default() -> Self {
422-
LdkChannelConfig::default().into()
423-
}
424-
}
425-
426-
/// Options for how to set the max dust exposure allowed on a channel.
427-
///
428-
/// See [`LdkChannelConfig::max_dust_htlc_exposure`] for details.
429-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
430-
pub enum MaxDustHTLCExposure {
431-
/// This sets a fixed limit on the total dust exposure in millisatoshis.
432-
///
433-
/// Please refer to [`LdkMaxDustHTLCExposure`] for further details.
434-
FixedLimit {
435-
/// The fixed limit, in millisatoshis.
436-
limit_msat: u64,
437-
},
438-
/// This sets a multiplier on the feerate to determine the maximum allowed dust exposure.
439-
///
440-
/// Please refer to [`LdkMaxDustHTLCExposure`] for further details.
441-
FeeRateMultiplier {
442-
/// The applied fee rate multiplier.
443-
multiplier: u64,
444-
},
445-
}
446-
447-
impl From<LdkMaxDustHTLCExposure> for MaxDustHTLCExposure {
448-
fn from(value: LdkMaxDustHTLCExposure) -> Self {
449-
match value {
450-
LdkMaxDustHTLCExposure::FixedLimitMsat(limit_msat) => Self::FixedLimit { limit_msat },
451-
LdkMaxDustHTLCExposure::FeeRateMultiplier(multiplier) => {
452-
Self::FeeRateMultiplier { multiplier }
453-
},
454-
}
455-
}
456-
}
457-
458-
impl From<MaxDustHTLCExposure> for LdkMaxDustHTLCExposure {
459-
fn from(value: MaxDustHTLCExposure) -> Self {
460-
match value {
461-
MaxDustHTLCExposure::FixedLimit { limit_msat } => Self::FixedLimitMsat(limit_msat),
462-
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } => {
463-
Self::FeeRateMultiplier(multiplier)
464-
},
465-
}
466-
}
467-
}

src/uniffi_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
// Make sure to add any re-exported items that need to be used in uniffi below.
1212

13-
pub use crate::config::{default_config, AnchorChannelsConfig};
13+
pub use crate::config::{default_config, AnchorChannelsConfig, MaxDustHTLCExposure};
1414
pub use crate::graph::{ChannelInfo, ChannelUpdateInfo, NodeAnnouncementInfo, NodeInfo};
1515
pub use crate::payment::store::{LSPFeeLimits, PaymentDirection, PaymentKind, PaymentStatus};
1616
pub use crate::payment::{MaxTotalRoutingFeeLimit, QrPaymentResult, SendingParameters};

0 commit comments

Comments
 (0)