Skip to content

Commit fb85bbd

Browse files
f just call add_entry on blinded hints since they each have 1 hop
1 parent 690b10d commit fb85bbd

File tree

1 file changed

+50
-33
lines changed

1 file changed

+50
-33
lines changed

lightning/src/routing/router.rs

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -658,10 +658,17 @@ pub enum Hints {
658658
}
659659

660660
impl Hints {
661-
fn blinded_len(&self) -> usize {
661+
fn blinded(&self) -> &[(BlindedPayInfo, BlindedPath)] {
662662
match self {
663-
Self::Blinded(hints) => hints.len(),
664-
Self::Clear(_) => 0,
663+
Self::Blinded(hints) => &hints[..],
664+
Self::Clear(_) => &[]
665+
}
666+
}
667+
668+
fn clear(&self) -> &[RouteHint] {
669+
match self {
670+
Self::Blinded(_) => &[],
671+
Self::Clear(hints) => &hints[..]
665672
}
666673
}
667674
}
@@ -1249,27 +1256,27 @@ where L::Target: Logger {
12491256
}
12501257
}
12511258

1252-
// Marshall route hints
1253-
let mut route_hints = Vec::with_capacity(payment_params.route_hints.blinded_len());
1254-
let route_hints_ref = match &payment_params.route_hints {
1255-
Hints::Clear(hints) => hints,
1256-
Hints::Blinded(blinded_hints) => {
1257-
for (blinded_payinfo, blinded_path) in blinded_hints {
1258-
route_hints.push(RouteHint(vec![RouteHintHop {
1259-
src_node_id: blinded_path.introduction_node_id,
1260-
short_channel_id: BLINDED_PATH_SCID,
1261-
fees: RoutingFees {
1262-
base_msat: blinded_payinfo.fee_base_msat,
1263-
proportional_millionths: blinded_payinfo.fee_proportional_millionths,
1264-
},
1265-
cltv_expiry_delta: blinded_payinfo.cltv_expiry_delta,
1266-
htlc_minimum_msat: Some(blinded_payinfo.htlc_minimum_msat),
1267-
htlc_maximum_msat: Some(blinded_payinfo.htlc_maximum_msat),
1268-
}]));
1269-
}
1270-
&route_hints
1259+
// Marshall blinded route hints
1260+
let mut blinded_route_hints = Vec::with_capacity(payment_params.route_hints.blinded().len());
1261+
for (blinded_payinfo, blinded_path) in payment_params.route_hints.blinded().iter() {
1262+
if blinded_path.blinded_hops.len() == 1 {
1263+
// If the introduction node is the destination, this hint is for a public node and we can just
1264+
// use the public network graph
1265+
blinded_route_hints = Vec::new();
1266+
break
12711267
}
1272-
};
1268+
blinded_route_hints.push(RouteHintHop {
1269+
src_node_id: blinded_path.introduction_node_id,
1270+
short_channel_id: BLINDED_PATH_SCID,
1271+
fees: RoutingFees {
1272+
base_msat: blinded_payinfo.fee_base_msat,
1273+
proportional_millionths: blinded_payinfo.fee_proportional_millionths,
1274+
},
1275+
cltv_expiry_delta: blinded_payinfo.cltv_expiry_delta,
1276+
htlc_minimum_msat: Some(blinded_payinfo.htlc_minimum_msat),
1277+
htlc_maximum_msat: Some(blinded_payinfo.htlc_maximum_msat),
1278+
});
1279+
}
12731280

12741281
// The main heap containing all candidate next-hops sorted by their score (max(fee,
12751282
// htlc_minimum)). Ideally this would be a heap which allowed cheap score reduction instead of
@@ -1683,7 +1690,20 @@ where L::Target: Logger {
16831690
// If a caller provided us with last hops, add them to routing targets. Since this happens
16841691
// earlier than general path finding, they will be somewhat prioritized, although currently
16851692
// it matters only if the fees are exactly the same.
1686-
for route in route_hints_ref.iter().filter(|route| !route.0.is_empty()) {
1693+
for hint in blinded_route_hints.iter() {
1694+
let have_hop_src_in_graph =
1695+
// Only add the hops in this route to our candidate set if either
1696+
// we have a direct channel to the first hop or the first hop is
1697+
// in the regular network graph.
1698+
first_hop_targets.get(&NodeId::from_pubkey(&hint.src_node_id)).is_some() ||
1699+
network_nodes.get(&NodeId::from_pubkey(&hint.src_node_id)).is_some();
1700+
if have_hop_src_in_graph {
1701+
add_entry!(CandidateRouteHop::PrivateHop { hint },
1702+
NodeId::from_pubkey(&hint.src_node_id),
1703+
NodeId::from_pubkey(&payment_params.payee_pubkey), 0, path_value_msat, 0, 0_u64, 0, 0);
1704+
}
1705+
}
1706+
for route in payment_params.route_hints.clear().iter().filter(|route| !route.0.is_empty()) {
16871707
let first_hop_in_route = &(route.0)[0];
16881708
let have_hop_src_in_graph =
16891709
// Only add the hops in this route to our candidate set if either
@@ -2102,15 +2122,12 @@ where L::Target: Logger {
21022122
for results_vec in selected_paths {
21032123
let mut hops = Vec::new();
21042124
for res in results_vec { hops.push(res?); }
2105-
let mut blinded_tail = None;
2106-
if let Hints::Blinded(hints) = &payment_params.route_hints {
2107-
blinded_tail = hints.iter()
2108-
.find(|(_, p)| {
2109-
let intro_node_idx = if p.blinded_hops.len() == 1 { hops.len() - 1 } else { hops.len() - 2 };
2110-
p.introduction_node_id == hops[intro_node_idx].pubkey
2111-
})
2112-
.map(|(_, p)| p.clone());
2113-
}
2125+
let blinded_tail = payment_params.route_hints.blinded().iter()
2126+
.find(|(_, p)| {
2127+
let intro_node_idx = if p.blinded_hops.len() == 1 { hops.len() - 1 } else { hops.len() - 2 };
2128+
p.introduction_node_id == hops[intro_node_idx].pubkey
2129+
})
2130+
.map(|(_, p)| p.clone());
21142131
paths.push(Path { hops, blinded_tail });
21152132
}
21162133
let route = Route {

0 commit comments

Comments
 (0)