]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Correctly pick middle hop to victimize
authorJeffrey Czyz <jkczyz@gmail.com>
Wed, 30 Mar 2022 18:43:45 +0000 (13:43 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Wed, 30 Mar 2022 22:42:00 +0000 (17:42 -0500)
For even-length paths, preferring a later hop avoids overly limiting the
possible paths on the next iteration.

lightning/src/routing/router.rs

index 9f202557ff7066d485e59c0ce0a9710ae687e1be..003dc6006db6adc620637b8069e0fdfdc83d64c1 100644 (file)
@@ -1390,7 +1390,7 @@ where L::Target: Logger {
                                        // If we weren't capped by hitting a liquidity limit on a channel in the path,
                                        // we'll probably end up picking the same path again on the next iteration.
                                        // Decrease the available liquidity of a hop in the middle of the path.
-                                       let victim_scid = payment_path.hops[(payment_path.hops.len() - 1) / 2].0.candidate.short_channel_id();
+                                       let victim_scid = payment_path.hops[(payment_path.hops.len()) / 2].0.candidate.short_channel_id();
                                        log_trace!(logger, "Disabling channel {} for future path building iterations to avoid duplicates.", victim_scid);
                                        let victim_liquidity = bookkept_channels_liquidity_available_msat.get_mut(&victim_scid).unwrap();
                                        *victim_liquidity = 0;