diff --git a/src/builder.rs b/src/builder.rs index ddb298add..727fb0c19 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -73,6 +73,7 @@ use crate::payment::asynchronous::om_mailbox::OnionMessageMailbox; use crate::peer_store::PeerStore; use crate::router::{LSPS4BlindedPathConfig, LSPS4Router}; use crate::runtime::Runtime; +use crate::scoring::ProbabilisticScoringParameters; use crate::tx_broadcaster::TransactionBroadcaster; use crate::types::{ ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeysManager, MessageRouter, @@ -620,6 +621,14 @@ impl NodeBuilder { Ok(self) } + /// Sets the parameters for the scoring algorithm. + pub fn set_scoring_params( + &mut self, scoring_params: ProbabilisticScoringParameters, + ) -> &mut Self { + self.config.scoring_parameters = scoring_params; + self + } + /// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options /// previously configured. pub fn build(&self) -> Result { @@ -1133,6 +1142,11 @@ impl ArcedNodeBuilder { self.inner.write().unwrap().set_async_payments_role(role).map(|_| ()) } + /// Sets the parameters for the scoring algorithm. + pub fn set_scoring_params(&self, scoring_params: ProbabilisticScoringParameters) { + self.inner.write().unwrap().set_scoring_params(scoring_params); + } + /// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options /// previously configured. pub fn build(&self) -> Result, BuildError> { @@ -1577,8 +1591,12 @@ fn build_with_store_internal( Ok(scorer) => scorer, Err(e) => { if e.kind() == std::io::ErrorKind::NotFound { - let params = ProbabilisticScoringDecayParameters::default(); - ProbabilisticScorer::new(params, Arc::clone(&network_graph), Arc::clone(&logger)) + let decay_params = config.scoring_parameters.decay_params; + ProbabilisticScorer::new( + decay_params, + Arc::clone(&network_graph), + Arc::clone(&logger), + ) } else { log_error!(logger, "Failed to read scoring data from store: {}", e); return Err(BuildError::ReadFailed); @@ -1606,7 +1624,7 @@ fn build_with_store_internal( }, } - let scoring_fee_params = ProbabilisticScoringFeeParameters::default(); + let scoring_fee_params = config.scoring_parameters.fee_params.clone(); let inner_router = DefaultRouter::new( Arc::clone(&network_graph), Arc::clone(&logger), diff --git a/src/config.rs b/src/config.rs index 510bcc875..e107538ae 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,6 +20,7 @@ use lightning::util::config::{ }; use crate::logger::LogLevel; +use crate::scoring::ProbabilisticScoringParameters; // Config defaults const DEFAULT_NETWORK: Network = Network::Bitcoin; @@ -184,6 +185,9 @@ pub struct Config { /// **Note:** If unset, default parameters will be used, and you will be able to override the /// parameters on a per-payment basis in the corresponding method calls. pub route_parameters: Option, + /// The parameters used to configure the [`lightning::routing::scoring::ProbabilisticScorer`] + /// used by the node. + pub scoring_parameters: ProbabilisticScoringParameters, } impl Default for Config { @@ -198,6 +202,7 @@ impl Default for Config { anchor_channels_config: Some(AnchorChannelsConfig::default()), route_parameters: None, node_alias: None, + scoring_parameters: ProbabilisticScoringParameters::default(), } } } diff --git a/src/lib.rs b/src/lib.rs index ef958563f..3dc8981db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,6 +103,8 @@ mod tx_broadcaster; mod types; mod wallet; +pub use scoring::ProbabilisticScoringParameters; + use std::default::Default; use std::net::ToSocketAddrs; use std::sync::{Arc, Mutex, RwLock}; diff --git a/src/scoring.rs b/src/scoring.rs index e85abade3..be8b274c8 100644 --- a/src/scoring.rs +++ b/src/scoring.rs @@ -2,10 +2,22 @@ use std::io::Cursor; use std::sync::{Arc, Mutex, RwLock}; use std::time::{Duration, SystemTime}; -use lightning::routing::scoring::ChannelLiquidities; +use lightning::routing::scoring::{ + ChannelLiquidities, ProbabilisticScoringDecayParameters, ProbabilisticScoringFeeParameters, +}; use lightning::util::ser::Readable; use lightning::{log_error, log_info, log_trace}; +/// The parameters used to configure the [`lightning::routing::scoring::ProbabilisticScorer`] +/// used by the node. +#[derive(Debug, Clone, Default)] +pub struct ProbabilisticScoringParameters { + /// The fee parameters used by the router to compute path penalties. + pub fee_params: ProbabilisticScoringFeeParameters, + /// The decay parameters used by the scorer to reduce certainty of liquidity information. + pub decay_params: ProbabilisticScoringDecayParameters, +} + use crate::config::{ EXTERNAL_PATHFINDING_SCORES_SYNC_INTERVAL, EXTERNAL_PATHFINDING_SCORES_SYNC_TIMEOUT_SECS, };