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