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