From: shaavan Date: Tue, 21 Nov 2023 14:41:46 +0000 (+0530) Subject: Explicitly reject routes that double-back X-Git-Tag: v0.0.119~45^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=9bd1cc76609e14c286477522cf2b56f17bd4346d;p=rust-lightning Explicitly reject routes that double-back - If a path within a route passes through the same channelID twice, that shows the path is looped and will be rejected by nodes. - Add a check to explicitly reject such payment before trying to send them. --- diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 0fbb0f5ea..dcb096d3e 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -1337,6 +1337,13 @@ impl OutboundPayments { continue 'path_check; } } + for (i, hop) in path.hops.iter().enumerate() { + // Check for duplicate channel_id in the remaining hops of the path + if path.hops.iter().skip(i + 1).any(|other_hop| other_hop.short_channel_id == hop.short_channel_id) { + path_errs.push(Err(APIError::InvalidRoute{err: "Path went through the same channel twice".to_owned()})); + continue 'path_check; + } + } total_value += path.final_value_msat(); path_errs.push(Ok(())); }