@@ -20,7 +20,7 @@ use crate::ln::features::{Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelF
20
20
use crate :: ln:: msgs:: { DecodeError , ErrorAction , LightningError , MAX_VALUE_MSAT } ;
21
21
use crate :: offers:: invoice:: { BlindedPayInfo , Bolt12Invoice } ;
22
22
use crate :: routing:: gossip:: { DirectedChannelInfo , EffectiveCapacity , ReadOnlyNetworkGraph , NetworkGraph , NodeId , RoutingFees } ;
23
- use crate :: routing:: scoring:: { ChannelUsage , LockableScore , Score } ;
23
+ use crate :: routing:: scoring:: { ChannelUsage , LockableScore , ScoreLookUp } ;
24
24
use crate :: util:: ser:: { Writeable , Readable , ReadableArgs , Writer } ;
25
25
use crate :: util:: logger:: { Level , Logger } ;
26
26
use crate :: util:: chacha20:: ChaCha20 ;
@@ -33,9 +33,9 @@ use core::{cmp, fmt};
33
33
use core:: ops:: Deref ;
34
34
35
35
/// A [`Router`] implemented using [`find_route`].
36
- pub struct DefaultRouter < G : Deref < Target = NetworkGraph < L > > , L : Deref , S : Deref , SP : Sized , Sc : Score < ScoreParams = SP > > where
36
+ pub struct DefaultRouter < G : Deref < Target = NetworkGraph < L > > , L : Deref , S : Deref , SP : Sized , Sc : ScoreLookUp < ScoreParams = SP > > where
37
37
L :: Target : Logger ,
38
- S :: Target : for < ' a > LockableScore < ' a , Score = Sc > ,
38
+ S :: Target : for < ' a > LockableScore < ' a , ScoreLookUp = Sc > ,
39
39
{
40
40
network_graph : G ,
41
41
logger : L ,
@@ -44,9 +44,9 @@ pub struct DefaultRouter<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref,
44
44
score_params : SP
45
45
}
46
46
47
- impl < G : Deref < Target = NetworkGraph < L > > , L : Deref , S : Deref , SP : Sized , Sc : Score < ScoreParams = SP > > DefaultRouter < G , L , S , SP , Sc > where
47
+ impl < G : Deref < Target = NetworkGraph < L > > , L : Deref , S : Deref , SP : Sized , Sc : ScoreLookUp < ScoreParams = SP > > DefaultRouter < G , L , S , SP , Sc > where
48
48
L :: Target : Logger ,
49
- S :: Target : for < ' a > LockableScore < ' a , Score = Sc > ,
49
+ S :: Target : for < ' a > LockableScore < ' a , ScoreLookUp = Sc > ,
50
50
{
51
51
/// Creates a new router.
52
52
pub fn new ( network_graph : G , logger : L , random_seed_bytes : [ u8 ; 32 ] , scorer : S , score_params : SP ) -> Self {
@@ -55,9 +55,9 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref, SP: Sized, Sc: Scor
55
55
}
56
56
}
57
57
58
- impl < G : Deref < Target = NetworkGraph < L > > , L : Deref , S : Deref , SP : Sized , Sc : Score < ScoreParams = SP > > Router for DefaultRouter < G , L , S , SP , Sc > where
58
+ impl < G : Deref < Target = NetworkGraph < L > > , L : Deref , S : Deref , SP : Sized , Sc : ScoreLookUp < ScoreParams = SP > > Router for DefaultRouter < G , L , S , SP , Sc > where
59
59
L :: Target : Logger ,
60
- S :: Target : for < ' a > LockableScore < ' a , Score = Sc > ,
60
+ S :: Target : for < ' a > LockableScore < ' a , ScoreLookUp = Sc > ,
61
61
{
62
62
fn find_route (
63
63
& self ,
@@ -106,18 +106,18 @@ pub trait Router {
106
106
}
107
107
}
108
108
109
- /// [`Score `] implementation that factors in in-flight HTLC liquidity.
109
+ /// [`ScoreLookUp `] implementation that factors in in-flight HTLC liquidity.
110
110
///
111
- /// Useful for custom [`Router`] implementations to wrap their [`Score `] on-the-fly when calling
111
+ /// Useful for custom [`Router`] implementations to wrap their [`ScoreLookUp `] on-the-fly when calling
112
112
/// [`find_route`].
113
113
///
114
- /// [`Score `]: crate::routing::scoring::Score
115
- pub struct ScorerAccountingForInFlightHtlcs < ' a , SP : Sized , Sc : ' a + Score < ScoreParams = SP > , S : LockableScore < ' a , Score = Sc > + ?Sized > {
114
+ /// [`ScoreLookUp `]: crate::routing::scoring::ScoreLookUp
115
+ pub struct ScorerAccountingForInFlightHtlcs < ' a , SP : Sized , Sc : ' a + ScoreLookUp < ScoreParams = SP > , S : LockableScore < ' a , ScoreLookUp = Sc > + ?Sized > {
116
116
scorer : & ' a S ,
117
117
// Maps a channel's short channel id and its direction to the liquidity used up.
118
118
inflight_htlcs : & ' a InFlightHtlcs ,
119
119
}
120
- impl < ' a , SP : Sized , Sc : Score < ScoreParams = SP > , S : LockableScore < ' a , Score = Sc > + ?Sized > ScorerAccountingForInFlightHtlcs < ' a , SP , Sc , S > {
120
+ impl < ' a , SP : Sized , Sc : ScoreLookUp < ScoreParams = SP > , S : LockableScore < ' a , ScoreLookUp = Sc > + ?Sized > ScorerAccountingForInFlightHtlcs < ' a , SP , Sc , S > {
121
121
/// Initialize a new `ScorerAccountingForInFlightHtlcs`.
122
122
pub fn new ( scorer : & ' a S , inflight_htlcs : & ' a InFlightHtlcs ) -> Self {
123
123
ScorerAccountingForInFlightHtlcs {
@@ -128,11 +128,11 @@ impl<'a, SP: Sized, Sc: Score<ScoreParams = SP>, S: LockableScore<'a, Score = Sc
128
128
}
129
129
130
130
#[ cfg( c_bindings) ]
131
- impl < ' a , SP : Sized , Sc : Score < ScoreParams = SP > , S : LockableScore < ' a , Score = Sc > + ?Sized > Writeable for ScorerAccountingForInFlightHtlcs < ' a , SP , Sc , S > {
131
+ impl < ' a , SP : Sized , Sc : ScoreLookUp < ScoreParams = SP > , S : LockableScore < ' a , ScoreLookUp = Sc > + ?Sized > Writeable for ScorerAccountingForInFlightHtlcs < ' a , SP , Sc , S > {
132
132
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > { self . scorer . write_lock ( ) . write ( writer) }
133
133
}
134
134
135
- impl < ' a , SP : Sized , Sc : ' a + Score < ScoreParams = SP > , S : LockableScore < ' a , Score = Sc > + ?Sized > Score for ScorerAccountingForInFlightHtlcs < ' a , SP , Sc , S > {
135
+ impl < ' a , SP : Sized , Sc : ' a + ScoreLookUp < ScoreParams = SP > , S : LockableScore < ' a , ScoreLookUp = Sc > + ?Sized > ScoreLookUp for ScorerAccountingForInFlightHtlcs < ' a , SP , Sc , S > {
136
136
type ScoreParams = Sc :: ScoreParams ;
137
137
fn channel_penalty_msat ( & self , short_channel_id : u64 , source : & NodeId , target : & NodeId , usage : ChannelUsage , score_params : & Self :: ScoreParams ) -> u64 {
138
138
if let Some ( used_liquidity) = self . inflight_htlcs . used_liquidity_msat (
@@ -148,22 +148,6 @@ impl<'a, SP: Sized, Sc: 'a + Score<ScoreParams = SP>, S: LockableScore<'a, Score
148
148
self . scorer . read_lock ( ) . channel_penalty_msat ( short_channel_id, source, target, usage, score_params)
149
149
}
150
150
}
151
-
152
- fn payment_path_failed ( & mut self , path : & Path , short_channel_id : u64 ) {
153
- self . scorer . write_lock ( ) . payment_path_failed ( path, short_channel_id)
154
- }
155
-
156
- fn payment_path_successful ( & mut self , path : & Path ) {
157
- self . scorer . write_lock ( ) . payment_path_successful ( path)
158
- }
159
-
160
- fn probe_failed ( & mut self , path : & Path , short_channel_id : u64 ) {
161
- self . scorer . write_lock ( ) . probe_failed ( path, short_channel_id)
162
- }
163
-
164
- fn probe_successful ( & mut self , path : & Path ) {
165
- self . scorer . write_lock ( ) . probe_successful ( path)
166
- }
167
151
}
168
152
169
153
/// A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
@@ -1409,7 +1393,7 @@ fn sort_first_hop_channels(
1409
1393
/// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
1410
1394
/// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
1411
1395
/// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
1412
- pub fn find_route < L : Deref , GL : Deref , S : Score > (
1396
+ pub fn find_route < L : Deref , GL : Deref , S : ScoreLookUp > (
1413
1397
our_node_pubkey : & PublicKey , route_params : & RouteParameters ,
1414
1398
network_graph : & NetworkGraph < GL > , first_hops : Option < & [ & ChannelDetails ] > , logger : L ,
1415
1399
scorer : & S , score_params : & S :: ScoreParams , random_seed_bytes : & [ u8 ; 32 ]
@@ -1423,7 +1407,7 @@ where L::Target: Logger, GL::Target: Logger {
1423
1407
Ok ( route)
1424
1408
}
1425
1409
1426
- pub ( crate ) fn get_route < L : Deref , S : Score > (
1410
+ pub ( crate ) fn get_route < L : Deref , S : ScoreLookUp > (
1427
1411
our_node_pubkey : & PublicKey , payment_params : & PaymentParameters , network_graph : & ReadOnlyNetworkGraph ,
1428
1412
first_hops : Option < & [ & ChannelDetails ] > , final_value_msat : u64 , logger : L , scorer : & S , score_params : & S :: ScoreParams ,
1429
1413
_random_seed_bytes : & [ u8 ; 32 ]
@@ -2613,7 +2597,7 @@ fn build_route_from_hops_internal<L: Deref>(
2613
2597
hop_ids : [ Option < NodeId > ; MAX_PATH_LENGTH_ESTIMATE as usize ] ,
2614
2598
}
2615
2599
2616
- impl Score for HopScorer {
2600
+ impl ScoreLookUp for HopScorer {
2617
2601
type ScoreParams = ( ) ;
2618
2602
fn channel_penalty_msat ( & self , _short_channel_id : u64 , source : & NodeId , target : & NodeId ,
2619
2603
_usage : ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64
@@ -2631,14 +2615,6 @@ fn build_route_from_hops_internal<L: Deref>(
2631
2615
}
2632
2616
u64:: max_value ( )
2633
2617
}
2634
-
2635
- fn payment_path_failed ( & mut self , _path : & Path , _short_channel_id : u64 ) { }
2636
-
2637
- fn payment_path_successful ( & mut self , _path : & Path ) { }
2638
-
2639
- fn probe_failed ( & mut self , _path : & Path , _short_channel_id : u64 ) { }
2640
-
2641
- fn probe_successful ( & mut self , _path : & Path ) { }
2642
2618
}
2643
2619
2644
2620
impl < ' a > Writeable for HopScorer {
@@ -2672,7 +2648,7 @@ mod tests {
2672
2648
use crate :: routing:: router:: { get_route, build_route_from_hops_internal, add_random_cltv_offset, default_node_features,
2673
2649
BlindedTail , InFlightHtlcs , Path , PaymentParameters , Route , RouteHint , RouteHintHop , RouteHop , RoutingFees ,
2674
2650
DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA , MAX_PATH_LENGTH_ESTIMATE } ;
2675
- use crate :: routing:: scoring:: { ChannelUsage , FixedPenaltyScorer , Score , ProbabilisticScorer , ProbabilisticScoringFeeParameters , ProbabilisticScoringDecayParameters } ;
2651
+ use crate :: routing:: scoring:: { ChannelUsage , FixedPenaltyScorer , ScoreLookUp , ProbabilisticScorer , ProbabilisticScoringFeeParameters , ProbabilisticScoringDecayParameters } ;
2676
2652
use crate :: routing:: test_utils:: { add_channel, add_or_update_node, build_graph, build_line_graph, id_to_feature_flags, get_nodes, update_channel} ;
2677
2653
use crate :: chain:: transaction:: OutPoint ;
2678
2654
use crate :: sign:: EntropySource ;
@@ -5720,16 +5696,11 @@ mod tests {
5720
5696
impl Writeable for BadChannelScorer {
5721
5697
fn write < W : Writer > ( & self , _w : & mut W ) -> Result < ( ) , crate :: io:: Error > { unimplemented ! ( ) }
5722
5698
}
5723
- impl Score for BadChannelScorer {
5699
+ impl ScoreLookUp for BadChannelScorer {
5724
5700
type ScoreParams = ( ) ;
5725
5701
fn channel_penalty_msat ( & self , short_channel_id : u64 , _: & NodeId , _: & NodeId , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5726
5702
if short_channel_id == self . short_channel_id { u64:: max_value ( ) } else { 0 }
5727
5703
}
5728
-
5729
- fn payment_path_failed ( & mut self , _path : & Path , _short_channel_id : u64 ) { }
5730
- fn payment_path_successful ( & mut self , _path : & Path ) { }
5731
- fn probe_failed ( & mut self , _path : & Path , _short_channel_id : u64 ) { }
5732
- fn probe_successful ( & mut self , _path : & Path ) { }
5733
5704
}
5734
5705
5735
5706
struct BadNodeScorer {
@@ -5741,16 +5712,11 @@ mod tests {
5741
5712
fn write < W : Writer > ( & self , _w : & mut W ) -> Result < ( ) , crate :: io:: Error > { unimplemented ! ( ) }
5742
5713
}
5743
5714
5744
- impl Score for BadNodeScorer {
5715
+ impl ScoreLookUp for BadNodeScorer {
5745
5716
type ScoreParams = ( ) ;
5746
5717
fn channel_penalty_msat ( & self , _: u64 , _: & NodeId , target : & NodeId , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
5747
5718
if * target == self . node_id { u64:: max_value ( ) } else { 0 }
5748
5719
}
5749
-
5750
- fn payment_path_failed ( & mut self , _path : & Path , _short_channel_id : u64 ) { }
5751
- fn payment_path_successful ( & mut self , _path : & Path ) { }
5752
- fn probe_failed ( & mut self , _path : & Path , _short_channel_id : u64 ) { }
5753
- fn probe_successful ( & mut self , _path : & Path ) { }
5754
5720
}
5755
5721
5756
5722
#[ test]
@@ -6721,6 +6687,7 @@ pub(crate) mod bench_utils {
6721
6687
use bitcoin:: secp256k1:: { PublicKey , Secp256k1 , SecretKey } ;
6722
6688
6723
6689
use crate :: chain:: transaction:: OutPoint ;
6690
+ use crate :: routing:: scoring:: ScoreUpdate ;
6724
6691
use crate :: sign:: { EntropySource , KeysManager } ;
6725
6692
use crate :: ln:: channelmanager:: { self , ChannelCounterparty , ChannelDetails } ;
6726
6693
use crate :: ln:: features:: Bolt11InvoiceFeatures ;
@@ -6814,7 +6781,7 @@ pub(crate) mod bench_utils {
6814
6781
}
6815
6782
}
6816
6783
6817
- pub ( crate ) fn generate_test_routes < S : Score > ( graph : & NetworkGraph < & TestLogger > , scorer : & mut S ,
6784
+ pub ( crate ) fn generate_test_routes < S : ScoreLookUp + ScoreUpdate > ( graph : & NetworkGraph < & TestLogger > , scorer : & mut S ,
6818
6785
score_params : & S :: ScoreParams , features : Bolt11InvoiceFeatures , mut seed : u64 ,
6819
6786
starting_amount : u64 , route_count : usize ,
6820
6787
) -> Vec < ( ChannelDetails , PaymentParameters , u64 ) > {
@@ -6894,6 +6861,7 @@ pub(crate) mod bench_utils {
6894
6861
#[ cfg( ldk_bench) ]
6895
6862
pub mod benches {
6896
6863
use super :: * ;
6864
+ use crate :: routing:: scoring:: { ScoreUpdate , ScoreLookUp } ;
6897
6865
use crate :: sign:: { EntropySource , KeysManager } ;
6898
6866
use crate :: ln:: channelmanager;
6899
6867
use crate :: ln:: features:: Bolt11InvoiceFeatures ;
@@ -6956,7 +6924,7 @@ pub mod benches {
6956
6924
"generate_large_mpp_routes_with_probabilistic_scorer" ) ;
6957
6925
}
6958
6926
6959
- fn generate_routes < S : Score > (
6927
+ fn generate_routes < S : ScoreLookUp + ScoreUpdate > (
6960
6928
bench : & mut Criterion , graph : & NetworkGraph < & TestLogger > , mut scorer : S ,
6961
6929
score_params : & S :: ScoreParams , features : Bolt11InvoiceFeatures , starting_amount : u64 ,
6962
6930
bench_name : & ' static str ,
0 commit comments