Skip to content

Commit e00af5d

Browse files
committed
Filter on a per-channel basis.
1 parent d3d982c commit e00af5d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lightning/src/routing/router.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,18 +1810,24 @@ fn build_route_from_hops_internal<L: Deref>(
18101810
network_graph: &ReadOnlyNetworkGraph, final_value_msat: u64, final_cltv_expiry_delta: u32,
18111811
logger: L, random_seed_bytes: &[u8; 32]) -> Result<Route, LightningError> where L::Target: Logger {
18121812

1813-
let filter_by_nodeids = |_short_channel_id: u64, _send_amt_msat: u64, _capacity_msat: u64,
1813+
let filter_channels = |_short_channel_id: u64, _send_amt_msat: u64, _capacity_msat: u64,
18141814
source: &NodeId, target: &NodeId| {
1815-
let mut hop_iter = core::iter::once(NodeId::from_pubkey(&our_node_pubkey)).chain(hops.iter().map(|hop_pubkey| NodeId::from_pubkey(&hop_pubkey)));
1816-
if hop_iter.clone().find(|x| *x == *source).is_some()
1817-
&& hop_iter.find(|x| *x == *target).is_some() {
1818-
0
1819-
} else {
1820-
u64::max_value()
1821-
}
1815+
1816+
let node_ids_iter = hops.iter().map(|hop_pubkey| NodeId::from_pubkey(&hop_pubkey));
1817+
let mut hop_iter = core::iter::once(NodeId::from_pubkey(&our_node_pubkey))
1818+
.chain(node_ids_iter.clone())
1819+
.zip(node_ids_iter);
1820+
1821+
match hop_iter.find(|(cur_id, next_id)| {
1822+
(*cur_id == *source && *next_id == *target) ||
1823+
(*cur_id == *target && *next_id == *source) })
1824+
{
1825+
Some(_) => 0,
1826+
None => u64::max_value()
1827+
}
18221828
};
18231829

1824-
let scorer = DynamicPenaltyScorer::with_penalty_func(filter_by_nodeids);
1830+
let scorer = DynamicPenaltyScorer::with_penalty_func(filter_channels);
18251831

18261832
get_route(our_node_pubkey, payment_params, network_graph, None, final_value_msat,
18271833
final_cltv_expiry_delta, logger, &scorer, random_seed_bytes)

0 commit comments

Comments
 (0)