Skip to content

Commit 2a77d9a

Browse files
committed
Hard-code scorer parameters to ProbabilisticScoringFeeParameters
The scorer currently relies on an associated type for the fee parameters. This isn't supportable at all in bindings, and for lack of a better option we simply hard-code the parameter for all scorers to `ProbabilisticScoringFeeParameters`.
1 parent f959254 commit 2a77d9a

File tree

5 files changed

+37
-41
lines changed

5 files changed

+37
-41
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,6 @@ type DynRouter = lightning::routing::router::DefaultRouter<
348348
&'static (dyn Logger + Send + Sync),
349349
>,
350350
>,
351-
lightning::routing::scoring::ProbabilisticScoringFeeParameters,
352-
lightning::routing::scoring::ProbabilisticScorer<
353-
&'static NetworkGraph<&'static (dyn Logger + Send + Sync)>,
354-
&'static (dyn Logger + Send + Sync),
355-
>,
356351
>;
357352

358353
#[cfg(not(c_bindings))]
@@ -1899,8 +1894,6 @@ mod tests {
18991894
Arc<test_utils::TestLogger>,
19001895
Arc<KeysManager>,
19011896
Arc<LockingWrapper<TestScorer>>,
1902-
(),
1903-
TestScorer,
19041897
>,
19051898
>,
19061899
Arc<
@@ -2187,10 +2180,11 @@ mod tests {
21872180
}
21882181

21892182
impl ScoreLookUp for TestScorer {
2183+
#[cfg(not(c_bindings))]
21902184
type ScoreParams = ();
21912185
fn channel_penalty_msat(
21922186
&self, _candidate: &CandidateRouteHop, _usage: ChannelUsage,
2193-
_score_params: &Self::ScoreParams,
2187+
_score_params: &lightning::routing::scoring::ProbabilisticScoringFeeParameters,
21942188
) -> u64 {
21952189
unimplemented!();
21962190
}

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,8 +1743,6 @@ pub type SimpleArcChannelManager<M, T, F, L> = ChannelManager<
17431743
Arc<L>,
17441744
Arc<KeysManager>,
17451745
Arc<RwLock<ProbabilisticScorer<Arc<NetworkGraph<Arc<L>>>, Arc<L>>>>,
1746-
ProbabilisticScoringFeeParameters,
1747-
ProbabilisticScorer<Arc<NetworkGraph<Arc<L>>>, Arc<L>>,
17481746
>,
17491747
>,
17501748
Arc<DefaultMessageRouter<Arc<NetworkGraph<Arc<L>>>, Arc<L>, Arc<KeysManager>>>,
@@ -1775,8 +1773,6 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, M, T, F, L>
17751773
&'g L,
17761774
&'c KeysManager,
17771775
&'h RwLock<ProbabilisticScorer<&'f NetworkGraph<&'g L>, &'g L>>,
1778-
ProbabilisticScoringFeeParameters,
1779-
ProbabilisticScorer<&'f NetworkGraph<&'g L>, &'g L>,
17801776
>,
17811777
&'i DefaultMessageRouter<&'f NetworkGraph<&'g L>, &'g L, &'c KeysManager>,
17821778
&'g L,
@@ -1961,7 +1957,7 @@ where
19611957
/// # fee_estimator: &dyn lightning::chain::chaininterface::FeeEstimator,
19621958
/// # chain_monitor: &dyn lightning::chain::Watch<lightning::sign::InMemorySigner>,
19631959
/// # tx_broadcaster: &dyn lightning::chain::chaininterface::BroadcasterInterface,
1964-
/// # router: &lightning::routing::router::DefaultRouter<&NetworkGraph<&'a L>, &'a L, &ES, &S, SP, SL>,
1960+
/// # router: &lightning::routing::router::DefaultRouter<&NetworkGraph<&'a L>, &'a L, &ES, &S>,
19651961
/// # message_router: &lightning::onion_message::messenger::DefaultMessageRouter<&NetworkGraph<&'a L>, &'a L, &ES>,
19661962
/// # logger: &L,
19671963
/// # entropy_source: &ES,

lightning/src/routing/router.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,36 +60,32 @@ pub struct DefaultRouter<
6060
L: Deref,
6161
ES: Deref,
6262
S: Deref,
63-
SP: Sized,
64-
Sc: ScoreLookUp<ScoreParams = SP>,
6563
> where
6664
L::Target: Logger,
67-
S::Target: for<'a> LockableScore<'a, ScoreLookUp = Sc>,
65+
S::Target: for<'a> LockableScore<'a>,
6866
ES::Target: EntropySource,
6967
{
7068
network_graph: G,
7169
logger: L,
7270
entropy_source: ES,
7371
scorer: S,
74-
score_params: SP,
72+
score_params: crate::routing::scoring::ProbabilisticScoringFeeParameters,
7573
}
7674

7775
impl<
7876
G: Deref<Target = NetworkGraph<L>>,
7977
L: Deref,
8078
ES: Deref,
8179
S: Deref,
82-
SP: Sized,
83-
Sc: ScoreLookUp<ScoreParams = SP>,
84-
> DefaultRouter<G, L, ES, S, SP, Sc>
80+
> DefaultRouter<G, L, ES, S>
8581
where
8682
L::Target: Logger,
87-
S::Target: for<'a> LockableScore<'a, ScoreLookUp = Sc>,
83+
S::Target: for<'a> LockableScore<'a>,
8884
ES::Target: EntropySource,
8985
{
9086
/// Creates a new router.
9187
pub fn new(
92-
network_graph: G, logger: L, entropy_source: ES, scorer: S, score_params: SP,
88+
network_graph: G, logger: L, entropy_source: ES, scorer: S, score_params: crate::routing::scoring::ProbabilisticScoringFeeParameters,
9389
) -> Self {
9490
Self { network_graph, logger, entropy_source, scorer, score_params }
9591
}
@@ -100,12 +96,10 @@ impl<
10096
L: Deref,
10197
ES: Deref,
10298
S: Deref,
103-
SP: Sized,
104-
Sc: ScoreLookUp<ScoreParams = SP>,
105-
> Router for DefaultRouter<G, L, ES, S, SP, Sc>
99+
> Router for DefaultRouter<G, L, ES, S>
106100
where
107101
L::Target: Logger,
108-
S::Target: for<'a> LockableScore<'a, ScoreLookUp = Sc>,
102+
S::Target: for<'a> LockableScore<'a>,
109103
ES::Target: EntropySource,
110104
{
111105
#[rustfmt::skip]
@@ -320,9 +314,10 @@ impl<'a, S: Deref> ScoreLookUp for ScorerAccountingForInFlightHtlcs<'a, S>
320314
where
321315
S::Target: ScoreLookUp,
322316
{
317+
#[cfg(not(c_bindings))]
323318
type ScoreParams = <S::Target as ScoreLookUp>::ScoreParams;
324319
#[rustfmt::skip]
325-
fn channel_penalty_msat(&self, candidate: &CandidateRouteHop, usage: ChannelUsage, score_params: &Self::ScoreParams) -> u64 {
320+
fn channel_penalty_msat(&self, candidate: &CandidateRouteHop, usage: ChannelUsage, score_params: &crate::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
326321
let target = match candidate.target() {
327322
Some(target) => target,
328323
None => return self.scorer.channel_penalty_msat(candidate, usage, score_params),
@@ -2420,7 +2415,7 @@ fn sort_first_hop_channels(
24202415
pub fn find_route<L: Deref, GL: Deref, S: ScoreLookUp>(
24212416
our_node_pubkey: &PublicKey, route_params: &RouteParameters,
24222417
network_graph: &NetworkGraph<GL>, first_hops: Option<&[&ChannelDetails]>, logger: L,
2423-
scorer: &S, score_params: &S::ScoreParams, random_seed_bytes: &[u8; 32]
2418+
scorer: &S, score_params: &crate::routing::scoring::ProbabilisticScoringFeeParameters, random_seed_bytes: &[u8; 32]
24242419
) -> Result<Route, &'static str>
24252420
where L::Target: Logger, GL::Target: Logger {
24262421
let graph_lock = network_graph.read_only();
@@ -2433,7 +2428,7 @@ where L::Target: Logger, GL::Target: Logger {
24332428
#[rustfmt::skip]
24342429
pub(crate) fn get_route<L: Deref, S: ScoreLookUp>(
24352430
our_node_pubkey: &PublicKey, route_params: &RouteParameters, network_graph: &ReadOnlyNetworkGraph,
2436-
first_hops: Option<&[&ChannelDetails]>, logger: L, scorer: &S, score_params: &S::ScoreParams,
2431+
first_hops: Option<&[&ChannelDetails]>, logger: L, scorer: &S, score_params: &crate::routing::scoring::ProbabilisticScoringFeeParameters,
24372432
_random_seed_bytes: &[u8; 32]
24382433
) -> Result<Route, &'static str>
24392434
where L::Target: Logger {
@@ -3845,9 +3840,10 @@ fn build_route_from_hops_internal<L: Deref>(
38453840
}
38463841

38473842
impl ScoreLookUp for HopScorer {
3843+
#[cfg(not(c_bindings))]
38483844
type ScoreParams = ();
38493845
fn channel_penalty_msat(&self, candidate: &CandidateRouteHop,
3850-
_usage: ChannelUsage, _score_params: &Self::ScoreParams) -> u64
3846+
_usage: ChannelUsage, _score_params: &crate::routing::scoring::ProbabilisticScoringFeeParameters) -> u64
38513847
{
38523848
let mut cur_id = self.our_node_id;
38533849
for i in 0..self.hop_ids.len() {
@@ -7222,9 +7218,10 @@ mod tests {
72227218
fn write<W: Writer>(&self, _w: &mut W) -> Result<(), crate::io::Error> { unimplemented!() }
72237219
}
72247220
impl ScoreLookUp for BadChannelScorer {
7221+
#[cfg(not(c_bindings))]
72257222
type ScoreParams = ();
72267223
#[rustfmt::skip]
7227-
fn channel_penalty_msat(&self, candidate: &CandidateRouteHop, _: ChannelUsage, _score_params:&Self::ScoreParams) -> u64 {
7224+
fn channel_penalty_msat(&self, candidate: &CandidateRouteHop, _: ChannelUsage, _score_params:&crate::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
72287225
if candidate.short_channel_id() == Some(self.short_channel_id) { u64::max_value() } else { 0 }
72297226
}
72307227
}
@@ -7240,9 +7237,10 @@ mod tests {
72407237
}
72417238

72427239
impl ScoreLookUp for BadNodeScorer {
7240+
#[cfg(not(c_bindings))]
72437241
type ScoreParams = ();
72447242
#[rustfmt::skip]
7245-
fn channel_penalty_msat(&self, candidate: &CandidateRouteHop, _: ChannelUsage, _score_params:&Self::ScoreParams) -> u64 {
7243+
fn channel_penalty_msat(&self, candidate: &CandidateRouteHop, _: ChannelUsage, _score_params:&crate::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
72467244
if candidate.target() == Some(self.node_id) { u64::max_value() } else { 0 }
72477245
}
72487246
}
@@ -9385,7 +9383,7 @@ pub(crate) mod bench_utils {
93859383

93869384
#[rustfmt::skip]
93879385
pub(crate) fn generate_test_routes<S: ScoreLookUp + ScoreUpdate>(graph: &NetworkGraph<&TestLogger>, scorer: &mut S,
9388-
score_params: &S::ScoreParams, features: Bolt11InvoiceFeatures, mut seed: u64,
9386+
score_params: &crate::routing::scoring::ProbabilisticScoringFeeParameters, features: Bolt11InvoiceFeatures, mut seed: u64,
93899387
starting_amount: u64, route_count: usize,
93909388
) -> Vec<(ChannelDetails, PaymentParameters, u64)> {
93919389
let payer = payer_pubkey();
@@ -9528,7 +9526,7 @@ pub mod benches {
95289526
#[rustfmt::skip]
95299527
fn generate_routes<S: ScoreLookUp + ScoreUpdate>(
95309528
bench: &mut Criterion, graph: &NetworkGraph<&TestLogger>, mut scorer: S,
9531-
score_params: &S::ScoreParams, features: Bolt11InvoiceFeatures, starting_amount: u64,
9529+
score_params: &crate::routing::scoring::ProbabilisticScoringFeeParameters, features: Bolt11InvoiceFeatures, starting_amount: u64,
95329530
bench_name: &'static str,
95339531
) {
95349532
// First, get 100 (source, destination) pairs for which route-getting actually succeeds...

lightning/src/routing/scoring.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ macro_rules! define_score { ($($supertrait: path)*) => {
9292
///
9393
/// Scoring is in terms of fees willing to be paid in order to avoid routing through a channel.
9494
pub trait ScoreLookUp {
95+
#[cfg(not(c_bindings))]
9596
/// A configurable type which should contain various passed-in parameters for configuring the scorer,
9697
/// on a per-routefinding-call basis through to the scorer methods,
9798
/// which are used to determine the parameters for the suitability of channels for use.
99+
///
100+
/// Note that due to limitations in many other languages' generics features, language bindings
101+
/// use [`ProbabilisticScoringFeeParameters`] for the parameters on all scorers.
98102
type ScoreParams;
99103
/// Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
100104
/// given channel in the direction from `source` to `target`.
@@ -105,7 +109,7 @@ pub trait ScoreLookUp {
105109
/// [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
106110
/// Thus, implementations should be overflow-safe.
107111
fn channel_penalty_msat(
108-
&self, candidate: &CandidateRouteHop, usage: ChannelUsage, score_params: &Self::ScoreParams
112+
&self, candidate: &CandidateRouteHop, usage: ChannelUsage, score_params: &ProbabilisticScoringFeeParameters
109113
) -> u64;
110114
}
111115

@@ -143,9 +147,10 @@ impl<T: ScoreLookUp + ScoreUpdate $(+ $supertrait)*> Score for T {}
143147

144148
#[cfg(not(c_bindings))]
145149
impl<S: ScoreLookUp, T: Deref<Target=S>> ScoreLookUp for T {
150+
#[cfg(not(c_bindings))]
146151
type ScoreParams = S::ScoreParams;
147152
fn channel_penalty_msat(
148-
&self, candidate: &CandidateRouteHop, usage: ChannelUsage, score_params: &Self::ScoreParams
153+
&self, candidate: &CandidateRouteHop, usage: ChannelUsage, score_params: &ProbabilisticScoringFeeParameters
149154
) -> u64 {
150155
self.deref().channel_penalty_msat(candidate, usage, score_params)
151156
}
@@ -326,9 +331,10 @@ impl<'a, T: 'a + Score> Deref for MultiThreadedScoreLockRead<'a, T> {
326331

327332
#[cfg(c_bindings)]
328333
impl<'a, T: Score> ScoreLookUp for MultiThreadedScoreLockRead<'a, T> {
334+
#[cfg(not(c_bindings))]
329335
type ScoreParams = T::ScoreParams;
330336
fn channel_penalty_msat(
331-
&self, candidate: &CandidateRouteHop, usage: ChannelUsage, score_params: &Self::ScoreParams,
337+
&self, candidate: &CandidateRouteHop, usage: ChannelUsage, score_params: &ProbabilisticScoringFeeParameters,
332338
) -> u64 {
333339
self.0.channel_penalty_msat(candidate, usage, score_params)
334340
}
@@ -410,9 +416,10 @@ impl FixedPenaltyScorer {
410416
}
411417

412418
impl ScoreLookUp for FixedPenaltyScorer {
419+
#[cfg(not(c_bindings))]
413420
type ScoreParams = ();
414421
fn channel_penalty_msat(
415-
&self, _: &CandidateRouteHop, _: ChannelUsage, _score_params: &Self::ScoreParams,
422+
&self, _: &CandidateRouteHop, _: ChannelUsage, _score_params: &ProbabilisticScoringFeeParameters,
416423
) -> u64 {
417424
self.penalty_msat
418425
}
@@ -1673,6 +1680,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ScoreLookUp for Probabilistic
16731680
where
16741681
L::Target: Logger,
16751682
{
1683+
#[cfg(not(c_bindings))]
16761684
type ScoreParams = ProbabilisticScoringFeeParameters;
16771685
#[rustfmt::skip]
16781686
fn channel_penalty_msat(
@@ -1882,6 +1890,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref> ScoreLookUp for CombinedScore
18821890
where
18831891
L::Target: Logger,
18841892
{
1893+
#[cfg(not(c_bindings))]
18851894
type ScoreParams = ProbabilisticScoringFeeParameters;
18861895

18871896
fn channel_penalty_msat(

lightning/src/util/test_utils.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ pub struct TestRouter<'a> {
143143
&'a TestLogger,
144144
Arc<RandomBytes>,
145145
&'a RwLock<TestScorer>,
146-
(),
147-
TestScorer,
148146
>,
149147
pub network_graph: Arc<NetworkGraph<&'a TestLogger>>,
150148
pub next_routes: Mutex<VecDeque<(RouteParameters, Option<Result<Route, &'static str>>)>>,
@@ -2119,10 +2117,11 @@ impl crate::util::ser::Writeable for TestScorer {
21192117
}
21202118

21212119
impl ScoreLookUp for TestScorer {
2120+
#[cfg(not(c_bindings))]
21222121
type ScoreParams = ();
21232122
fn channel_penalty_msat(
21242123
&self, candidate: &CandidateRouteHop, usage: ChannelUsage,
2125-
_score_params: &Self::ScoreParams,
2124+
_score_params: &crate::routing::scoring::ProbabilisticScoringFeeParameters,
21262125
) -> u64 {
21272126
let short_channel_id = match candidate.globally_unique_short_channel_id() {
21282127
Some(scid) => scid,

0 commit comments

Comments
 (0)