From: Jeffrey Czyz Date: Wed, 30 Mar 2022 18:43:45 +0000 (-0500) Subject: Correctly pick middle hop to victimize X-Git-Tag: v0.0.106~2^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=rust-lightning;a=commitdiff_plain;h=30b6873d03e59fd2b329725f71e9df98eaba1c2c Correctly pick middle hop to victimize For even-length paths, preferring a later hop avoids overly limiting the possible paths on the next iteration. --- diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 9f202557..003dc600 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -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;