@@ -1138,13 +1138,16 @@ pub(crate) fn get_route<L: Deref, S: Score>(
1138
1138
_random_seed_bytes : & [ u8 ; 32 ]
1139
1139
) -> Result < Route , LightningError >
1140
1140
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) ) ;
1142
1145
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 ) ;
1145
1148
let our_node_id = NodeId :: from_pubkey ( & our_node_pubkey) ;
1146
1149
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) {
1148
1151
return Err ( LightningError { err : "Cannot generate a route to ourselves" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1149
1152
}
1150
1153
@@ -1243,7 +1246,7 @@ where L::Target: Logger {
1243
1246
false
1244
1247
} else if let Some ( features) = & payment_params. features {
1245
1248
features. supports_basic_mpp ( )
1246
- } else if let Some ( payee) = payee_node_id {
1249
+ } else if let Some ( payee) = payee_node_id_opt {
1247
1250
network_nodes. get ( & payee) . map_or ( false , |node| node. announcement_info . as_ref ( ) . map_or ( false ,
1248
1251
|info| info. features . supports_basic_mpp ( ) ) )
1249
1252
} else { false } ;
@@ -1603,7 +1606,7 @@ where L::Target: Logger {
1603
1606
// Entries are added to dist in add_entry!() when there is a channel from a node.
1604
1607
// Because there are no channels from payee, it will not have a dist entry at this point.
1605
1608
// 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 ) ;
1607
1610
false
1608
1611
} ;
1609
1612
@@ -1663,7 +1666,7 @@ where L::Target: Logger {
1663
1666
1664
1667
// If first hop is a private channel and the only way to reach the payee, this is the only
1665
1668
// 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| {
1667
1670
for details in first_channels {
1668
1671
let candidate = CandidateRouteHop :: FirstHop { details } ;
1669
1672
let added = add_entry ! ( candidate, our_node_id, payee, 0 , path_value_msat,
@@ -1675,7 +1678,7 @@ where L::Target: Logger {
1675
1678
1676
1679
// Add the payee as a target, so that the payee-to-payer
1677
1680
// 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) {
1679
1682
// The payee is not in our network graph, so nothing to add here.
1680
1683
// There is still a chance of reaching them via last_hops though,
1681
1684
// so don't yet fail the payment here.
@@ -1706,7 +1709,7 @@ where L::Target: Logger {
1706
1709
// We start building the path from reverse, i.e., from payee
1707
1710
// to the first RouteHintHop in the path.
1708
1711
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 (
1710
1713
route. 0 . iter ( ) . skip ( 1 ) . rev ( ) . map ( |hop| & hop. src_node_id ) ) ;
1711
1714
let mut hop_used = true ;
1712
1715
let mut aggregate_next_hops_fee_msat: u64 = 0 ;
@@ -1866,7 +1869,7 @@ where L::Target: Logger {
1866
1869
// save this path for the payment route. Also, update the liquidity
1867
1870
// remaining on the used hops, so that we take them into account
1868
1871
// 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 {
1870
1873
break ' path_walk;
1871
1874
}
1872
1875
@@ -1949,7 +1952,7 @@ where L::Target: Logger {
1949
1952
// If we found a path back to the payee, we shouldn't try to process it again. This is
1950
1953
// the equivalent of the `elem.was_processed` check in
1951
1954
// 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; }
1953
1956
1954
1957
// Otherwise, since the current target node is not us,
1955
1958
// keep "unrolling" the payment graph from payee to payer by
0 commit comments