77
88//! Objects for configuring the node.
99
10+ use std:: collections:: HashMap ;
1011use std:: fmt;
1112use std:: str:: FromStr ;
1213use std:: time:: Duration ;
1314
1415use bitcoin:: secp256k1:: PublicKey ;
1516use bitcoin:: Network ;
1617use lightning:: ln:: msgs:: SocketAddress ;
17- use lightning:: routing:: gossip:: NodeAlias ;
18+ use lightning:: routing:: gossip:: { NodeAlias , NodeId } ;
1819use lightning:: routing:: router:: RouteParametersConfig ;
20+ use lightning:: routing:: scoring:: ProbabilisticScoringFeeParameters as LdkProbabilisticScoringFeeParameters ;
1921use lightning:: util:: config:: {
2022 ChannelConfig as LdkChannelConfig , MaxDustHTLCExposure as LdkMaxDustHTLCExposure , UserConfig ,
2123} ;
@@ -128,11 +130,13 @@ pub(crate) const LNURL_AUTH_TIMEOUT_SECS: u64 = 15;
128130/// | `probing_liquidity_limit_multiplier` | 3 |
129131/// | `anchor_channels_config` | Some(..) |
130132/// | `route_parameters` | None |
133+ /// | `scoring_fee_parameters` | ProbabilisticScoringFeeParameters::default() |
131134/// | `tor_config` | None |
132135/// | `hrn_config` | HumanReadableNamesConfig::default() |
133136///
134- /// See [`AnchorChannelsConfig`] and [`RouteParametersConfig`] for more information regarding their
135- /// respective default values.
137+ /// See [`AnchorChannelsConfig`], [`RouteParametersConfig`], and
138+ /// [`ProbabilisticScoringFeeParameters`] for more information regarding their respective default
139+ /// values.
136140///
137141/// [`Node`]: crate::Node
138142pub struct Config {
@@ -194,6 +198,11 @@ pub struct Config {
194198 /// **Note:** If unset, default parameters will be used, and you will be able to override the
195199 /// parameters on a per-payment basis in the corresponding method calls.
196200 pub route_parameters : Option < RouteParametersConfig > ,
201+ /// Configuration options for scoring candidate routes during pathfinding.
202+ ///
203+ /// These parameters configure the channel penalties applied by LDK's probabilistic scorer,
204+ /// influencing which routes are preferred when sending payments.
205+ pub scoring_fee_parameters : ProbabilisticScoringFeeParameters ,
197206 /// Configuration options for enabling peer connections via the Tor network.
198207 ///
199208 /// Setting [`TorConfig`] enables connecting to peers with OnionV3 addresses. No other connections
@@ -219,12 +228,95 @@ impl Default for Config {
219228 anchor_channels_config : Some ( AnchorChannelsConfig :: default ( ) ) ,
220229 tor_config : None ,
221230 route_parameters : None ,
231+ scoring_fee_parameters : ProbabilisticScoringFeeParameters :: default ( ) ,
222232 node_alias : None ,
223233 hrn_config : HumanReadableNamesConfig :: default ( ) ,
224234 }
225235 }
226236}
227237
238+ /// Parameters for configuring channel penalties applied during payment pathfinding.
239+ ///
240+ /// See [`LdkProbabilisticScoringFeeParameters`] for more information on how these values affect
241+ /// route selection.
242+ #[ derive( Clone , Debug ) ]
243+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Record ) ) ]
244+ pub struct ProbabilisticScoringFeeParameters {
245+ /// A fixed penalty in msats to apply to each channel.
246+ pub base_penalty_msat : u64 ,
247+ /// A multiplier used with the payment amount to calculate an additional fixed penalty.
248+ pub base_penalty_amount_multiplier_msat : u64 ,
249+ /// A multiplier used with the estimated success probability to determine the liquidity penalty.
250+ pub liquidity_penalty_multiplier_msat : u64 ,
251+ /// A multiplier used with payment amount and estimated success probability to determine the
252+ /// liquidity amount penalty.
253+ pub liquidity_penalty_amount_multiplier_msat : u64 ,
254+ /// A multiplier used with historical liquidity estimates to determine a penalty.
255+ pub historical_liquidity_penalty_multiplier_msat : u64 ,
256+ /// A multiplier used with payment amount and historical liquidity estimates to determine a
257+ /// penalty.
258+ pub historical_liquidity_penalty_amount_multiplier_msat : u64 ,
259+ /// Manual penalties used for the given nodes.
260+ pub manual_node_penalties : HashMap < NodeId , u64 > ,
261+ /// Penalty applied when a channel's `htlc_maximum_msat` is at least half of its capacity.
262+ pub anti_probing_penalty_msat : u64 ,
263+ /// Penalty applied when the total amount flowing over a channel exceeds our current estimate of
264+ /// the channel's available liquidity.
265+ pub considered_impossible_penalty_msat : u64 ,
266+ /// If set, a linear probability density function is used for channel liquidity.
267+ pub linear_success_probability : bool ,
268+ /// Maximum penalty applied when choosing probing paths based on recent liquidity updates.
269+ pub probing_diversity_penalty_msat : u64 ,
270+ }
271+
272+ impl Default for ProbabilisticScoringFeeParameters {
273+ fn default ( ) -> Self {
274+ LdkProbabilisticScoringFeeParameters :: default ( ) . into ( )
275+ }
276+ }
277+
278+ impl From < LdkProbabilisticScoringFeeParameters > for ProbabilisticScoringFeeParameters {
279+ fn from ( value : LdkProbabilisticScoringFeeParameters ) -> Self {
280+ Self {
281+ base_penalty_msat : value. base_penalty_msat ,
282+ base_penalty_amount_multiplier_msat : value. base_penalty_amount_multiplier_msat ,
283+ liquidity_penalty_multiplier_msat : value. liquidity_penalty_multiplier_msat ,
284+ liquidity_penalty_amount_multiplier_msat : value
285+ . liquidity_penalty_amount_multiplier_msat ,
286+ historical_liquidity_penalty_multiplier_msat : value
287+ . historical_liquidity_penalty_multiplier_msat ,
288+ historical_liquidity_penalty_amount_multiplier_msat : value
289+ . historical_liquidity_penalty_amount_multiplier_msat ,
290+ manual_node_penalties : value. manual_node_penalties . into_iter ( ) . collect ( ) ,
291+ anti_probing_penalty_msat : value. anti_probing_penalty_msat ,
292+ considered_impossible_penalty_msat : value. considered_impossible_penalty_msat ,
293+ linear_success_probability : value. linear_success_probability ,
294+ probing_diversity_penalty_msat : value. probing_diversity_penalty_msat ,
295+ }
296+ }
297+ }
298+
299+ impl From < ProbabilisticScoringFeeParameters > for LdkProbabilisticScoringFeeParameters {
300+ fn from ( value : ProbabilisticScoringFeeParameters ) -> Self {
301+ Self {
302+ base_penalty_msat : value. base_penalty_msat ,
303+ base_penalty_amount_multiplier_msat : value. base_penalty_amount_multiplier_msat ,
304+ liquidity_penalty_multiplier_msat : value. liquidity_penalty_multiplier_msat ,
305+ liquidity_penalty_amount_multiplier_msat : value
306+ . liquidity_penalty_amount_multiplier_msat ,
307+ historical_liquidity_penalty_multiplier_msat : value
308+ . historical_liquidity_penalty_multiplier_msat ,
309+ historical_liquidity_penalty_amount_multiplier_msat : value
310+ . historical_liquidity_penalty_amount_multiplier_msat ,
311+ manual_node_penalties : value. manual_node_penalties . into_iter ( ) . collect ( ) ,
312+ anti_probing_penalty_msat : value. anti_probing_penalty_msat ,
313+ considered_impossible_penalty_msat : value. considered_impossible_penalty_msat ,
314+ linear_success_probability : value. linear_success_probability ,
315+ probing_diversity_penalty_msat : value. probing_diversity_penalty_msat ,
316+ }
317+ }
318+ }
319+
228320/// Configuration options for how our node resolves Human-Readable Names (BIP 353).
229321///
230322/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
0 commit comments