Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ interface ProbingConfigBuilder {
void set_max_locked_msat(u64 max_msat);
void set_diversity_penalty_msat(u64 penalty_msat);
void set_cooldown(u64 secs);
[Throws=BuildError]
void set_amount_range_msat(u64 min_msat, u64 max_msat);
ProbingConfig build();
};

Expand Down
14 changes: 8 additions & 6 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ use crate::config::BitcoindRestClientConfig;
use crate::config::{
default_user_config, may_announce_channel, AnnounceError, AsyncPaymentsRole, Config,
ElectrumSyncConfig, EsploraSyncConfig, HRNResolverConfig, TorConfig,
DEFAULT_ESPLORA_SERVER_URL, DEFAULT_LOG_FILENAME, DEFAULT_LOG_LEVEL,
DEFAULT_MAX_PROBE_AMOUNT_MSAT, DEFAULT_MIN_PROBE_AMOUNT_MSAT, PAYMENT_CACHE_CAPACITY,
DEFAULT_ESPLORA_SERVER_URL, DEFAULT_LOG_FILENAME, DEFAULT_LOG_LEVEL, PAYMENT_CACHE_CAPACITY,
PAYMENT_CACHE_WARMUP_COUNT,
};
use crate::connection::ConnectionManager;
Expand Down Expand Up @@ -193,6 +192,8 @@ pub enum BuildError {
InvalidTorProxyAddress,
/// The provided alias is invalid.
InvalidNodeAlias,
/// The given probe amount range is invalid, i.e., its minimum exceeds its maximum.
InvalidProbeAmountRange,
/// An attempt to setup a runtime has failed.
RuntimeSetupFailed,
/// We failed to read data from the [`KVStore`].
Expand Down Expand Up @@ -255,6 +256,7 @@ impl fmt::Display for BuildError {
Self::LoggerSetupFailed => write!(f, "Failed to setup the logger."),
Self::ChainSourceSetupFailed => write!(f, "Failed to setup the chain source."),
Self::InvalidNodeAlias => write!(f, "Given node alias is invalid."),
Self::InvalidProbeAmountRange => write!(f, "Given probe amount range is invalid."),
Self::NetworkMismatch => {
write!(f, "Given network does not match the node's previously configured network.")
},
Expand Down Expand Up @@ -2429,8 +2431,8 @@ fn build_with_store_internal(
Arc::clone(&channel_manager),
probing_router,
*top_node_count,
DEFAULT_MIN_PROBE_AMOUNT_MSAT,
DEFAULT_MAX_PROBE_AMOUNT_MSAT,
probing_cfg.min_amount_msat,
probing_cfg.max_amount_msat,
probing_cfg.cooldown,
config.probing_liquidity_limit_multiplier,
))
Expand All @@ -2439,8 +2441,8 @@ fn build_with_store_internal(
Arc::clone(&network_graph),
Arc::clone(&channel_manager),
*max_hops,
DEFAULT_MIN_PROBE_AMOUNT_MSAT,
DEFAULT_MAX_PROBE_AMOUNT_MSAT,
probing_cfg.min_amount_msat,
probing_cfg.max_amount_msat,
)),
ProbingStrategyKind::Custom(s) => Arc::clone(s),
};
Expand Down
47 changes: 45 additions & 2 deletions src/probing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ use lightning::routing::router::{
use lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA;
use lightning_types::features::{ChannelFeatures, NodeFeatures};

use crate::builder::BuildError;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think this should import and use BuildError here. Let's introduce a dedicated error type.

use crate::config::{
DEFAULT_MAX_PROBE_LOCKED_MSAT, DEFAULT_PROBED_NODE_COOLDOWN_SECS,
DEFAULT_PROBING_INTERVAL_SECS, MIN_PROBING_INTERVAL,
DEFAULT_MAX_PROBE_AMOUNT_MSAT, DEFAULT_MAX_PROBE_LOCKED_MSAT, DEFAULT_MIN_PROBE_AMOUNT_MSAT,
DEFAULT_PROBED_NODE_COOLDOWN_SECS, DEFAULT_PROBING_INTERVAL_SECS, MIN_PROBING_INTERVAL,
};
use crate::logger::{log_debug, LdkLogger, Logger};
use crate::types::{ChannelManager, Graph, Router};
Expand Down Expand Up @@ -165,6 +166,8 @@ pub struct ProbingConfig {
pub(crate) max_locked_msat: u64,
pub(crate) diversity_penalty_msat: Option<u64>,
pub(crate) cooldown: Duration,
pub(crate) min_amount_msat: u64,
pub(crate) max_amount_msat: u64,
}

/// Builder for [`ProbingConfig`].
Expand All @@ -183,6 +186,8 @@ pub struct ProbingConfigBuilder {
max_locked_msat: u64,
diversity_penalty_msat: Option<u64>,
cooldown: Duration,
min_amount_msat: u64,
max_amount_msat: u64,
}

impl ProbingConfigBuilder {
Expand All @@ -193,6 +198,8 @@ impl ProbingConfigBuilder {
max_locked_msat: DEFAULT_MAX_PROBE_LOCKED_MSAT,
diversity_penalty_msat: None,
cooldown: Duration::from_secs(DEFAULT_PROBED_NODE_COOLDOWN_SECS),
min_amount_msat: DEFAULT_MIN_PROBE_AMOUNT_MSAT,
max_amount_msat: DEFAULT_MAX_PROBE_AMOUNT_MSAT,
}
}

Expand Down Expand Up @@ -256,6 +263,28 @@ impl ProbingConfigBuilder {
self
}

/// Overrides the bounds each probe's amount is uniformly drawn from.
///
/// Only applies to the built-in strategies; custom strategies choose their
/// own probe amounts when building paths. Larger amounts teach the scorer
/// about liquidity in the range of larger payments, at the cost of locking
/// more liquidity per in-flight probe — size `max_locked_msat` accordingly.
///
/// Defaults to 1 000 000 - 10 000 000 msat (1k - 10k sats).
///
/// Returns [`BuildError::InvalidProbeAmountRange`] if `min_msat` exceeds `max_msat`.
pub fn amount_range_msat(
&mut self, min_msat: u64, max_msat: u64,
) -> Result<&mut Self, BuildError> {
if min_msat > max_msat {
return Err(BuildError::InvalidProbeAmountRange);
}

self.min_amount_msat = min_msat;
self.max_amount_msat = max_msat;
Ok(self)
}

/// Builds the [`ProbingConfig`].
pub fn build(&self) -> ProbingConfig {
ProbingConfig {
Expand All @@ -264,6 +293,8 @@ impl ProbingConfigBuilder {
max_locked_msat: self.max_locked_msat,
diversity_penalty_msat: self.diversity_penalty_msat,
cooldown: self.cooldown,
min_amount_msat: self.min_amount_msat,
max_amount_msat: self.max_amount_msat,
}
}
}
Expand Down Expand Up @@ -335,6 +366,18 @@ impl ArcedProbingConfigBuilder {
self.inner.write().expect("lock").cooldown(Duration::from_secs(secs));
}

/// Overrides the bounds each probe's amount is uniformly drawn from.
///
/// Only applies to the built-in strategies; custom strategies choose their
/// own probe amounts when building paths.
///
/// Defaults to 1 000 000 - 10 000 000 msat (1k - 10k sats).
///
/// Returns [`BuildError::InvalidProbeAmountRange`] if `min_msat` exceeds `max_msat`.
pub fn set_amount_range_msat(&self, min_msat: u64, max_msat: u64) -> Result<(), BuildError> {
self.inner.write().expect("lock").amount_range_msat(min_msat, max_msat).map(|_| ())
}

/// Builds the [`ProbingConfig`].
pub fn build(&self) -> Arc<ProbingConfig> {
Arc::new(self.inner.read().expect("lock").build())
Expand Down
Loading