Skip to content

Commit 733b8ae

Browse files
f clarify payee node id vars in get_route and switch to debug assertion
1 parent 5a3e383 commit 733b8ae

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lightning/src/routing/router.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,13 +1138,16 @@ pub(crate) fn get_route<L: Deref, S: Score>(
11381138
_random_seed_bytes: &[u8; 32]
11391139
) -> Result<Route, LightningError>
11401140
where L::Target: Logger {
1141-
let payee_node_id = payment_params.payee.node_id().map(|pk| NodeId::from_pubkey(&pk));
1141+
// If we're routing to a blinded recipient, we won't have their node id. Therefore, keep the
1142+
// unblinded payee id as an option. We also need a non-optional "payee id" for path construction,
1143+
// so use a dummy id for this in the blinded case.
1144+
let payee_node_id_opt = payment_params.payee.node_id().map(|pk| NodeId::from_pubkey(&pk));
11421145
const DUMMY_BLINDED_PAYEE_ID: [u8; 33] = [42u8; 33];
1143-
let target_pubkey = payment_params.payee.node_id().unwrap_or_else(|| PublicKey::from_slice(&DUMMY_BLINDED_PAYEE_ID).unwrap());
1144-
let target_node_id = NodeId::from_pubkey(&target_pubkey);
1146+
let maybe_dummy_payee_pk = payment_params.payee.node_id().unwrap_or_else(|| PublicKey::from_slice(&DUMMY_BLINDED_PAYEE_ID).unwrap());
1147+
let maybe_dummy_payee_node_id = NodeId::from_pubkey(&maybe_dummy_payee_pk);
11451148
let our_node_id = NodeId::from_pubkey(&our_node_pubkey);
11461149

1147-
if payee_node_id.map_or(false, |payee| payee == our_node_id) {
1150+
if payee_node_id_opt.map_or(false, |payee| payee == our_node_id) {
11481151
return Err(LightningError{err: "Cannot generate a route to ourselves".to_owned(), action: ErrorAction::IgnoreError});
11491152
}
11501153

@@ -1243,7 +1246,7 @@ where L::Target: Logger {
12431246
false
12441247
} else if let Some(features) = &payment_params.features {
12451248
features.supports_basic_mpp()
1246-
} else if let Some(payee) = payee_node_id {
1249+
} else if let Some(payee) = payee_node_id_opt {
12471250
network_nodes.get(&payee).map_or(false, |node| node.announcement_info.as_ref().map_or(false,
12481251
|info| info.features.supports_basic_mpp()))
12491252
} else { false };
@@ -1603,7 +1606,7 @@ where L::Target: Logger {
16031606
// Entries are added to dist in add_entry!() when there is a channel from a node.
16041607
// Because there are no channels from payee, it will not have a dist entry at this point.
16051608
// If we're processing any other node, it is always be the result of a channel from it.
1606-
assert_eq!($node_id, target_node_id);
1609+
debug_assert_eq!($node_id, maybe_dummy_payee_node_id);
16071610
false
16081611
};
16091612

@@ -1663,7 +1666,7 @@ where L::Target: Logger {
16631666

16641667
// If first hop is a private channel and the only way to reach the payee, this is the only
16651668
// place where it could be added.
1666-
payee_node_id.map(|payee| first_hop_targets.get(&payee).map(|first_channels| {
1669+
payee_node_id_opt.map(|payee| first_hop_targets.get(&payee).map(|first_channels| {
16671670
for details in first_channels {
16681671
let candidate = CandidateRouteHop::FirstHop { details };
16691672
let added = add_entry!(candidate, our_node_id, payee, 0, path_value_msat,
@@ -1675,7 +1678,7 @@ where L::Target: Logger {
16751678

16761679
// Add the payee as a target, so that the payee-to-payer
16771680
// search algorithm knows what to start with.
1678-
payee_node_id.map(|payee| match network_nodes.get(&payee) {
1681+
payee_node_id_opt.map(|payee| match network_nodes.get(&payee) {
16791682
// The payee is not in our network graph, so nothing to add here.
16801683
// There is still a chance of reaching them via last_hops though,
16811684
// so don't yet fail the payment here.
@@ -1706,7 +1709,7 @@ where L::Target: Logger {
17061709
// We start building the path from reverse, i.e., from payee
17071710
// to the first RouteHintHop in the path.
17081711
let hop_iter = route.0.iter().rev();
1709-
let prev_hop_iter = core::iter::once(&target_pubkey).chain(
1712+
let prev_hop_iter = core::iter::once(&maybe_dummy_payee_pk).chain(
17101713
route.0.iter().skip(1).rev().map(|hop| &hop.src_node_id));
17111714
let mut hop_used = true;
17121715
let mut aggregate_next_hops_fee_msat: u64 = 0;
@@ -1866,7 +1869,7 @@ where L::Target: Logger {
18661869
// save this path for the payment route. Also, update the liquidity
18671870
// remaining on the used hops, so that we take them into account
18681871
// while looking for more paths.
1869-
if ordered_hops.last().unwrap().0.node_id == target_node_id {
1872+
if ordered_hops.last().unwrap().0.node_id == maybe_dummy_payee_node_id {
18701873
break 'path_walk;
18711874
}
18721875

@@ -1949,7 +1952,7 @@ where L::Target: Logger {
19491952
// If we found a path back to the payee, we shouldn't try to process it again. This is
19501953
// the equivalent of the `elem.was_processed` check in
19511954
// add_entries_to_cheapest_to_target_node!() (see comment there for more info).
1952-
if node_id == target_node_id { continue 'path_construction; }
1955+
if node_id == maybe_dummy_payee_node_id { continue 'path_construction; }
19531956

19541957
// Otherwise, since the current target node is not us,
19551958
// keep "unrolling" the payment graph from payee to payer by

0 commit comments

Comments
 (0)