Skip to content
Merged
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
24 changes: 21 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Node, BuildError> {
Expand Down Expand Up @@ -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<Arc<Node>, BuildError> {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use lightning::util::config::{
};

use crate::logger::LogLevel;
use crate::scoring::ProbabilisticScoringParameters;

// Config defaults
const DEFAULT_NETWORK: Network = Network::Bitcoin;
Expand Down Expand Up @@ -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<RouteParametersConfig>,
/// The parameters used to configure the [`lightning::routing::scoring::ProbabilisticScorer`]
/// used by the node.
pub scoring_parameters: ProbabilisticScoringParameters,
}

impl Default for Config {
Expand All @@ -198,6 +202,7 @@ impl Default for Config {
anchor_channels_config: Some(AnchorChannelsConfig::default()),
route_parameters: None,
node_alias: None,
scoring_parameters: ProbabilisticScoringParameters::default(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
14 changes: 13 additions & 1 deletion src/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
Loading