Skip to content

Commit 748beba

Browse files
committed
Remove unnecessary bounds in scoring
In our scoring logic we have a handful of unnecessary bounds, leading to extra diff in the bindings branch when those bounds have to be removed as well as a few cases where bindings generation simply gets confused. Here we remove a number of bounds across the scoring traits and impls, cleaning things up and simplifying bindings changes.
1 parent 26c1639 commit 748beba

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lightning/src/routing/router.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ pub trait Router {
112112
/// [`find_route`].
113113
///
114114
/// [`ScoreLookUp`]: crate::routing::scoring::ScoreLookUp
115-
pub struct ScorerAccountingForInFlightHtlcs<'a, SP: Sized, Sc: 'a + ScoreLookUp<ScoreParams = SP>, S: Deref<Target = Sc>> {
115+
pub struct ScorerAccountingForInFlightHtlcs<'a, S: Deref> where S::Target: ScoreLookUp {
116116
scorer: S,
117117
// Maps a channel's short channel id and its direction to the liquidity used up.
118118
inflight_htlcs: &'a InFlightHtlcs,
119119
}
120-
impl<'a, SP: Sized, Sc: ScoreLookUp<ScoreParams = SP>, S: Deref<Target = Sc>> ScorerAccountingForInFlightHtlcs<'a, SP, Sc, S> {
120+
impl<'a, S: Deref> ScorerAccountingForInFlightHtlcs<'a, S> where S::Target: ScoreLookUp {
121121
/// Initialize a new `ScorerAccountingForInFlightHtlcs`.
122122
pub fn new(scorer: S, inflight_htlcs: &'a InFlightHtlcs) -> Self {
123123
ScorerAccountingForInFlightHtlcs {
@@ -128,12 +128,12 @@ impl<'a, SP: Sized, Sc: ScoreLookUp<ScoreParams = SP>, S: Deref<Target = Sc>> Sc
128128
}
129129

130130
#[cfg(c_bindings)]
131-
impl<'a, SP: Sized, Sc: ScoreLookUp<ScoreParams = SP>, S: Deref<Target = Sc>> Writeable for ScorerAccountingForInFlightHtlcs<'a, SP, Sc, S> {
131+
impl<'a, S: Deref> Writeable for ScorerAccountingForInFlightHtlcs<'a, S> where S::Target: ScoreLookUp {
132132
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> { self.scorer.write(writer) }
133133
}
134134

135-
impl<'a, SP: Sized, Sc: 'a + ScoreLookUp<ScoreParams = SP>, S: Deref<Target = Sc>> ScoreLookUp for ScorerAccountingForInFlightHtlcs<'a, SP, Sc, S> {
136-
type ScoreParams = Sc::ScoreParams;
135+
impl<'a, S: Deref> ScoreLookUp for ScorerAccountingForInFlightHtlcs<'a, S> where S::Target: ScoreLookUp {
136+
type ScoreParams = <S::Target as ScoreLookUp>::ScoreParams;
137137
fn channel_penalty_msat(&self, short_channel_id: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage, score_params: &Self::ScoreParams) -> u64 {
138138
if let Some(used_liquidity) = self.inflight_htlcs.used_liquidity_msat(
139139
source, target, short_channel_id

lightning/src/routing/scoring.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ pub trait ScoreUpdate $(: $supertrait)* {
122122
fn probe_successful(&mut self, path: &Path);
123123
}
124124

125-
impl<SP: Sized, S: ScoreLookUp<ScoreParams = SP>, T: Deref<Target=S> $(+ $supertrait)*> ScoreLookUp for T {
126-
type ScoreParams = SP;
125+
impl<S: ScoreLookUp, T: Deref<Target=S> $(+ $supertrait)*> ScoreLookUp for T {
126+
type ScoreParams = S::ScoreParams;
127127
fn channel_penalty_msat(
128128
&self, short_channel_id: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage, score_params: &Self::ScoreParams
129129
) -> u64 {
@@ -226,7 +226,7 @@ impl<'a, T: 'a + ScoreUpdate + ScoreLookUp> LockableScore<'a> for RefCell<T> {
226226
}
227227

228228
#[cfg(not(c_bindings))]
229-
impl<'a, SP:Sized, T: 'a + ScoreUpdate + ScoreLookUp<ScoreParams = SP>> LockableScore<'a> for RwLock<T> {
229+
impl<'a, T: 'a + ScoreUpdate + ScoreLookUp> LockableScore<'a> for RwLock<T> {
230230
type ScoreUpdate = T;
231231
type ScoreLookUp = T;
232232

@@ -249,7 +249,7 @@ pub struct MultiThreadedLockableScore<T: ScoreLookUp + ScoreUpdate> {
249249
}
250250

251251
#[cfg(c_bindings)]
252-
impl<'a, SP:Sized, T: 'a + ScoreLookUp<ScoreParams = SP> + ScoreUpdate> LockableScore<'a> for MultiThreadedLockableScore<T> {
252+
impl<'a, T: 'a + ScoreLookUp + ScoreUpdate> LockableScore<'a> for MultiThreadedLockableScore<T> {
253253
type ScoreUpdate = T;
254254
type ScoreLookUp = T;
255255
type WriteLocked = MultiThreadedScoreLockWrite<'a, Self::ScoreUpdate>;

0 commit comments

Comments
 (0)