@@ -105,6 +105,9 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
105
105
// The minimum channel balance certainty required for using a channel in a blinded path.
106
106
const MIN_CHANNEL_CERTAINTY : f64 = 0.5 ;
107
107
108
+ // The minimum success probability required for using a channel in a blinded path.
109
+ const MIN_SUCCESS_PROBABILITY : f64 = 0.25 ;
110
+
108
111
let network_graph = self . network_graph . deref ( ) . read_only ( ) ;
109
112
let counterparty_channels = first_hops. into_iter ( )
110
113
. filter ( |details| details. counterparty . features . supports_route_blinding ( ) )
@@ -180,6 +183,21 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
180
183
//
181
184
// source --- info ---> counterparty --- counterparty_forward_node ---> recipient
182
185
. filter_map ( |( introduction_node_id, scid, info, counterparty_forward_node) | {
186
+ let amount_msat = amount_msats;
187
+ let effective_capacity = info. effective_capacity ( ) ;
188
+ let usage = ChannelUsage { amount_msat, inflight_htlc_msat : 0 , effective_capacity } ;
189
+ let success_probability = scorer. channel_success_probability (
190
+ scid, & info, usage, & self . score_params
191
+ ) ;
192
+
193
+ if !success_probability. is_finite ( ) {
194
+ return None ;
195
+ }
196
+
197
+ if success_probability < MIN_SUCCESS_PROBABILITY {
198
+ return None ;
199
+ }
200
+
183
201
let htlc_minimum_msat = info. direction ( ) . htlc_minimum_msat ;
184
202
let htlc_maximum_msat = info. direction ( ) . htlc_maximum_msat ;
185
203
let payment_relay: PaymentRelay = match info. try_into ( ) {
@@ -201,12 +219,13 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
201
219
node_id : introduction_node_id. as_pubkey ( ) . unwrap ( ) ,
202
220
htlc_maximum_msat,
203
221
} ;
204
- Some ( BlindedPath :: new_for_payment (
222
+ let path = BlindedPath :: new_for_payment (
205
223
& [ introduction_forward_node, counterparty_forward_node] , recipient,
206
224
tlvs. clone ( ) , u64:: MAX , MIN_FINAL_CLTV_EXPIRY_DELTA , entropy_source, secp_ctx
207
- ) )
208
- } )
209
- . take ( MAX_PAYMENT_PATHS ) ;
225
+ ) ;
226
+
227
+ Some ( path. map ( |path| ( path, success_probability) ) )
228
+ } ) ;
210
229
211
230
let two_hop_paths = counterparty_channels
212
231
. map ( |( forward_node, _) | {
@@ -220,6 +239,10 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
220
239
three_hop_paths
221
240
. collect :: < Result < Vec < _ > , _ > > ( ) . ok ( )
222
241
. and_then ( |paths| ( !paths. is_empty ( ) ) . then ( || paths) )
242
+ . map ( |mut paths| {
243
+ paths. sort_unstable_by ( |a, b| b. 1 . partial_cmp ( & a. 1 ) . unwrap ( ) ) ;
244
+ paths. into_iter ( ) . map ( |( path, _) | path) . take ( MAX_PAYMENT_PATHS ) . collect :: < Vec < _ > > ( )
245
+ } )
223
246
. or_else ( || two_hop_paths. collect :: < Result < Vec < _ > , _ > > ( ) . ok ( ) )
224
247
. and_then ( |paths| ( !paths. is_empty ( ) ) . then ( || paths) )
225
248
. or_else ( || network_graph
0 commit comments