Merge pull request #2741 from shaavan/issue-2215
[rust-lightning] / lightning / src / ln / outbound_payment.rs
index b449e27983ecd09efdc88a90ff22235d0f7d0f67..e1748dca7f2ac11978035b2b44c4b66f8a2973d0 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(()));
                }