@@ -89,7 +89,7 @@ macro_rules! define_score { ($($supertrait: path)*) => {
89
89
/// `ScoreLookUp` is used to determine the penalty for a given channel.
90
90
///
91
91
/// Scoring is in terms of fees willing to be paid in order to avoid routing through a channel.
92
- pub trait ScoreLookUp $ ( : $supertrait ) * {
92
+ pub trait ScoreLookUp {
93
93
/// A configurable type which should contain various passed-in parameters for configuring the scorer,
94
94
/// on a per-routefinding-call basis through to the scorer methods,
95
95
/// which are used to determine the parameters for the suitability of channels for use.
@@ -108,7 +108,7 @@ pub trait ScoreLookUp $(: $supertrait)* {
108
108
}
109
109
110
110
/// `ScoreUpdate` is used to update the scorer's internal state after a payment attempt.
111
- pub trait ScoreUpdate $ ( : $supertrait ) * {
111
+ pub trait ScoreUpdate {
112
112
/// Handles updating channel penalties after failing to route through a channel.
113
113
fn payment_path_failed( & mut self , path: & Path , short_channel_id: u64 ) ;
114
114
@@ -122,7 +122,18 @@ pub trait ScoreUpdate $(: $supertrait)* {
122
122
fn probe_successful( & mut self , path: & Path ) ;
123
123
}
124
124
125
- impl <S : ScoreLookUp , T : Deref <Target =S > $( + $supertrait) * > ScoreLookUp for T {
125
+ /// A trait which can both lookup and update routing channel penalty scores.
126
+ ///
127
+ /// This is used in places where both bounds are required and implemented for all types which
128
+ /// implement [`ScoreLookUp`] and [`ScoreUpdate`].
129
+ ///
130
+ /// Bindings users may need to manually implement this for their custom scoring implementations.
131
+ pub trait Score : ScoreLookUp + ScoreUpdate $( + $supertrait) * { }
132
+
133
+ #[ cfg( not( c_bindings) ) ]
134
+ impl <T : ScoreLookUp + ScoreUpdate $( + $supertrait) * > Score for T { }
135
+
136
+ impl <S : ScoreLookUp , T : Deref <Target =S >> ScoreLookUp for T {
126
137
type ScoreParams = S :: ScoreParams ;
127
138
fn channel_penalty_msat(
128
139
& self , short_channel_id: u64 , source: & NodeId , target: & NodeId , usage: ChannelUsage , score_params: & Self :: ScoreParams
@@ -131,7 +142,7 @@ impl<S: ScoreLookUp, T: Deref<Target=S> $(+ $supertrait)*> ScoreLookUp for T {
131
142
}
132
143
}
133
144
134
- impl <S : ScoreUpdate , T : DerefMut <Target =S > $ ( + $supertrait ) * > ScoreUpdate for T {
145
+ impl <S : ScoreUpdate , T : DerefMut <Target =S >> ScoreUpdate for T {
135
146
fn payment_path_failed( & mut self , path: & Path , short_channel_id: u64 ) {
136
147
self . deref_mut( ) . payment_path_failed( path, short_channel_id)
137
148
}
@@ -192,7 +203,7 @@ pub trait WriteableScore<'a>: LockableScore<'a> + Writeable {}
192
203
#[ cfg( not( c_bindings) ) ]
193
204
impl < ' a , T > WriteableScore < ' a > for T where T : LockableScore < ' a > + Writeable { }
194
205
#[ cfg( not( c_bindings) ) ]
195
- impl < ' a , T : ' a + ScoreLookUp + ScoreUpdate > LockableScore < ' a > for Mutex < T > {
206
+ impl < ' a , T : Score + ' a > LockableScore < ' a > for Mutex < T > {
196
207
type ScoreUpdate = T ;
197
208
type ScoreLookUp = T ;
198
209
@@ -209,7 +220,7 @@ impl<'a, T: 'a + ScoreLookUp + ScoreUpdate> LockableScore<'a> for Mutex<T> {
209
220
}
210
221
211
222
#[ cfg( not( c_bindings) ) ]
212
- impl < ' a , T : ' a + ScoreUpdate + ScoreLookUp > LockableScore < ' a > for RefCell < T > {
223
+ impl < ' a , T : Score + ' a > LockableScore < ' a > for RefCell < T > {
213
224
type ScoreUpdate = T ;
214
225
type ScoreLookUp = T ;
215
226
@@ -226,7 +237,7 @@ impl<'a, T: 'a + ScoreUpdate + ScoreLookUp> LockableScore<'a> for RefCell<T> {
226
237
}
227
238
228
239
#[ cfg( not( c_bindings) ) ]
229
- impl < ' a , T : ' a + ScoreUpdate + ScoreLookUp > LockableScore < ' a > for RwLock < T > {
240
+ impl < ' a , T : Score + ' a > LockableScore < ' a > for RwLock < T > {
230
241
type ScoreUpdate = T ;
231
242
type ScoreLookUp = T ;
232
243
@@ -244,12 +255,12 @@ impl<'a, T: 'a + ScoreUpdate + ScoreLookUp> LockableScore<'a> for RwLock<T> {
244
255
245
256
#[ cfg( c_bindings) ]
246
257
/// A concrete implementation of [`LockableScore`] which supports multi-threading.
247
- pub struct MultiThreadedLockableScore < T : ScoreLookUp + ScoreUpdate > {
258
+ pub struct MultiThreadedLockableScore < T : Score > {
248
259
score : RwLock < T > ,
249
260
}
250
261
251
262
#[ cfg( c_bindings) ]
252
- impl < ' a , T : ' a + ScoreLookUp + ScoreUpdate > LockableScore < ' a > for MultiThreadedLockableScore < T > {
263
+ impl < ' a , T : Score + ' a > LockableScore < ' a > for MultiThreadedLockableScore < T > {
253
264
type ScoreUpdate = T ;
254
265
type ScoreLookUp = T ;
255
266
type WriteLocked = MultiThreadedScoreLockWrite < ' a , Self :: ScoreUpdate > ;
@@ -265,17 +276,17 @@ impl<'a, T: 'a + ScoreLookUp + ScoreUpdate> LockableScore<'a> for MultiThreadedL
265
276
}
266
277
267
278
#[ cfg( c_bindings) ]
268
- impl < T : ScoreUpdate + ScoreLookUp > Writeable for MultiThreadedLockableScore < T > {
279
+ impl < T : Score > Writeable for MultiThreadedLockableScore < T > {
269
280
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
270
281
self . score . read ( ) . unwrap ( ) . write ( writer)
271
282
}
272
283
}
273
284
274
285
#[ cfg( c_bindings) ]
275
- impl < ' a , T : ' a + ScoreUpdate + ScoreLookUp > WriteableScore < ' a > for MultiThreadedLockableScore < T > { }
286
+ impl < ' a , T : Score + ' a > WriteableScore < ' a > for MultiThreadedLockableScore < T > { }
276
287
277
288
#[ cfg( c_bindings) ]
278
- impl < T : ScoreLookUp + ScoreUpdate > MultiThreadedLockableScore < T > {
289
+ impl < T : Score > MultiThreadedLockableScore < T > {
279
290
/// Creates a new [`MultiThreadedLockableScore`] given an underlying [`Score`].
280
291
pub fn new ( score : T ) -> Self {
281
292
MultiThreadedLockableScore { score : RwLock :: new ( score) }
@@ -284,14 +295,14 @@ impl<T: ScoreLookUp + ScoreUpdate> MultiThreadedLockableScore<T> {
284
295
285
296
#[ cfg( c_bindings) ]
286
297
/// A locked `MultiThreadedLockableScore`.
287
- pub struct MultiThreadedScoreLockRead < ' a , T : ScoreLookUp > ( RwLockReadGuard < ' a , T > ) ;
298
+ pub struct MultiThreadedScoreLockRead < ' a , T : Score > ( RwLockReadGuard < ' a , T > ) ;
288
299
289
300
#[ cfg( c_bindings) ]
290
301
/// A locked `MultiThreadedLockableScore`.
291
- pub struct MultiThreadedScoreLockWrite < ' a , T : ScoreUpdate > ( RwLockWriteGuard < ' a , T > ) ;
302
+ pub struct MultiThreadedScoreLockWrite < ' a , T : Score > ( RwLockWriteGuard < ' a , T > ) ;
292
303
293
304
#[ cfg( c_bindings) ]
294
- impl < ' a , T : ' a + ScoreLookUp > Deref for MultiThreadedScoreLockRead < ' a , T > {
305
+ impl < ' a , T : ' a + Score > Deref for MultiThreadedScoreLockRead < ' a , T > {
295
306
type Target = T ;
296
307
297
308
fn deref ( & self ) -> & Self :: Target {
@@ -300,14 +311,14 @@ impl<'a, T: 'a + ScoreLookUp> Deref for MultiThreadedScoreLockRead<'a, T> {
300
311
}
301
312
302
313
#[ cfg( c_bindings) ]
303
- impl < ' a , T : ' a + ScoreUpdate > Writeable for MultiThreadedScoreLockWrite < ' a , T > {
314
+ impl < ' a , T : Score > Writeable for MultiThreadedScoreLockWrite < ' a , T > {
304
315
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
305
316
self . 0 . write ( writer)
306
317
}
307
318
}
308
319
309
320
#[ cfg( c_bindings) ]
310
- impl < ' a , T : ' a + ScoreUpdate > Deref for MultiThreadedScoreLockWrite < ' a , T > {
321
+ impl < ' a , T : ' a + Score > Deref for MultiThreadedScoreLockWrite < ' a , T > {
311
322
type Target = T ;
312
323
313
324
fn deref ( & self ) -> & Self :: Target {
@@ -316,7 +327,7 @@ impl<'a, T: 'a + ScoreUpdate> Deref for MultiThreadedScoreLockWrite<'a, T> {
316
327
}
317
328
318
329
#[ cfg( c_bindings) ]
319
- impl < ' a , T : ' a + ScoreUpdate > DerefMut for MultiThreadedScoreLockWrite < ' a , T > {
330
+ impl < ' a , T : ' a + Score > DerefMut for MultiThreadedScoreLockWrite < ' a , T > {
320
331
fn deref_mut ( & mut self ) -> & mut Self :: Target {
321
332
self . 0 . deref_mut ( )
322
333
}
@@ -1417,6 +1428,10 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ScoreUpdate for Prob
1417
1428
}
1418
1429
}
1419
1430
1431
+ #[ cfg( c_bindings) ]
1432
+ impl < G : Deref < Target = NetworkGraph < L > > , L : Deref , T : Time > Score for ProbabilisticScorerUsingTime < G , L , T >
1433
+ where L :: Target : Logger { }
1434
+
1420
1435
mod approx {
1421
1436
const BITS : u32 = 64 ;
1422
1437
const HIGHEST_BIT : u32 = BITS - 1 ;
0 commit comments