From 9bd1cc76609e14c286477522cf2b56f17bd4346d Mon Sep 17 00:00:00 2001 From: shaavan Date: Tue, 21 Nov 2023 20:11:46 +0530 Subject: [PATCH] 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. --- lightning/src/ln/outbound_payment.rs | 7 +++++++ 1 file changed, 7 insertions(+) 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(())); } -- 2.39.5