Explicitly reject routes that double-back
authorshaavan <shaavan.github@gmail.com>
Tue, 21 Nov 2023 14:41:46 +0000 (20:11 +0530)
committershaavan <shaavan.github@gmail.com>
Wed, 22 Nov 2023 13:04:44 +0000 (18:34 +0530)
- 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

index 0fbb0f5eaf4ccdeffd32d2a7c9d2aea20888273c..dcb096d3e9a75530cf8b2a030b6cff7942cb7399 100644 (file)
@@ -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(()));
                }