@@ -493,9 +493,6 @@ const MAX_PATH_LENGTH_ESTIMATE: u8 = 19;
493
493
/// The recipient of a payment.
494
494
#[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
495
495
pub struct PaymentParameters {
496
- /// The node id of the payee.
497
- pub payee_pubkey : PublicKey ,
498
-
499
496
/// Features supported by the payee.
500
497
///
501
498
/// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
@@ -547,11 +544,11 @@ impl Writeable for PaymentParameters {
547
544
let mut clear_hints = & vec ! [ ] ;
548
545
let mut blinded_hints = & vec ! [ ] ;
549
546
match & self . payee {
550
- Payee :: Clear { route_hints } => clear_hints = route_hints,
547
+ Payee :: Clear { route_hints, .. } => clear_hints = route_hints,
551
548
Payee :: Blinded ( hints) => blinded_hints = hints,
552
549
}
553
550
write_tlv_fields ! ( writer, {
554
- ( 0 , self . payee_pubkey , required ) ,
551
+ ( 0 , self . payee . node_id ( ) , option ) ,
555
552
( 1 , self . max_total_cltv_expiry_delta, required) ,
556
553
( 2 , self . features, option) ,
557
554
( 3 , self . max_path_count, required) ,
@@ -569,7 +566,7 @@ impl Writeable for PaymentParameters {
569
566
impl ReadableArgs < u32 > for PaymentParameters {
570
567
fn read < R : io:: Read > ( reader : & mut R , default_final_cltv_expiry_delta : u32 ) -> Result < Self , DecodeError > {
571
568
_init_and_read_tlv_fields ! ( reader, {
572
- ( 0 , payee_pubkey, required ) ,
569
+ ( 0 , payee_pubkey, option ) ,
573
570
( 1 , max_total_cltv_expiry_delta, ( default_value, DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ) ) ,
574
571
( 2 , features, option) ,
575
572
( 3 , max_path_count, ( default_value, DEFAULT_MAX_PATH_COUNT ) ) ,
@@ -583,13 +580,15 @@ impl ReadableArgs<u32> for PaymentParameters {
583
580
let clear_route_hints = route_hints. unwrap_or ( vec ! [ ] ) ;
584
581
let blinded_route_hints = blinded_route_hints. unwrap_or ( vec ! [ ] ) ;
585
582
let payee = if blinded_route_hints. len ( ) != 0 {
586
- if clear_route_hints. len ( ) != 0 { return Err ( DecodeError :: InvalidValue ) }
583
+ if clear_route_hints. len ( ) != 0 || payee_pubkey . is_some ( ) { return Err ( DecodeError :: InvalidValue ) }
587
584
Payee :: Blinded ( blinded_route_hints)
588
585
} else {
589
- Payee :: Clear { route_hints : clear_route_hints }
586
+ Payee :: Clear {
587
+ route_hints : clear_route_hints,
588
+ node_id : payee_pubkey. ok_or ( DecodeError :: InvalidValue ) ?,
589
+ }
590
590
} ;
591
591
Ok ( Self {
592
- payee_pubkey : _init_tlv_based_struct_field ! ( payee_pubkey, required) ,
593
592
max_total_cltv_expiry_delta : _init_tlv_based_struct_field ! ( max_total_cltv_expiry_delta, ( default_value, unused) ) ,
594
593
features,
595
594
max_path_count : _init_tlv_based_struct_field ! ( max_path_count, ( default_value, unused) ) ,
@@ -610,9 +609,8 @@ impl PaymentParameters {
610
609
/// provided.
611
610
pub fn from_node_id ( payee_pubkey : PublicKey , final_cltv_expiry_delta : u32 ) -> Self {
612
611
Self {
613
- payee_pubkey,
614
612
features : None ,
615
- payee : Payee :: Clear { route_hints : vec ! [ ] } ,
613
+ payee : Payee :: Clear { node_id : payee_pubkey , route_hints : vec ! [ ] } ,
616
614
expiry_time : None ,
617
615
max_total_cltv_expiry_delta : DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ,
618
616
max_path_count : DEFAULT_MAX_PATH_COUNT ,
@@ -644,8 +642,8 @@ impl PaymentParameters {
644
642
pub fn with_route_hints ( self , route_hints : Vec < RouteHint > ) -> Result < Self , ( ) > {
645
643
match self . payee {
646
644
Payee :: Blinded ( _) => Err ( ( ) ) ,
647
- Payee :: Clear { .. } =>
648
- Ok ( Self { payee : Payee :: Clear { route_hints } , ..self } )
645
+ Payee :: Clear { node_id , .. } =>
646
+ Ok ( Self { payee : Payee :: Clear { route_hints, node_id } , ..self } )
649
647
}
650
648
}
651
649
@@ -687,11 +685,22 @@ pub enum Payee {
687
685
Blinded ( Vec < ( BlindedPayInfo , BlindedPath ) > ) ,
688
686
/// The recipient included these route hints in their BOLT11 invoice.
689
687
Clear {
688
+ /// The node id of the payee.
689
+ node_id : PublicKey ,
690
690
/// Hints for routing to the payee, containing channels connecting the payee to public nodes.
691
691
route_hints : Vec < RouteHint > ,
692
692
} ,
693
693
}
694
694
695
+ impl Payee {
696
+ fn node_id ( & self ) -> Option < PublicKey > {
697
+ match self {
698
+ Self :: Clear { node_id, .. } => Some ( * node_id) ,
699
+ _ => None ,
700
+ }
701
+ }
702
+ }
703
+
695
704
/// A list of hops along a payment path terminating with a channel to the recipient.
696
705
#[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
697
706
pub struct RouteHint ( pub Vec < RouteHintHop > ) ;
@@ -1125,10 +1134,13 @@ pub(crate) fn get_route<L: Deref, S: Score>(
1125
1134
_random_seed_bytes : & [ u8 ; 32 ]
1126
1135
) -> Result < Route , LightningError >
1127
1136
where L :: Target : Logger {
1128
- let payee_node_id = NodeId :: from_pubkey ( & payment_params. payee_pubkey ) ;
1137
+ let payee_node_id = payment_params. payee . node_id ( ) . map ( |pk| NodeId :: from_pubkey ( & pk) ) ;
1138
+ const DUMMY_BLINDED_PAYEE_ID : [ u8 ; 33 ] = [ 42u8 ; 33 ] ;
1139
+ let target_pubkey = payment_params. payee . node_id ( ) . unwrap_or_else ( || PublicKey :: from_slice ( & DUMMY_BLINDED_PAYEE_ID ) . unwrap ( ) ) ;
1140
+ let target_node_id = NodeId :: from_pubkey ( & target_pubkey) ;
1129
1141
let our_node_id = NodeId :: from_pubkey ( & our_node_pubkey) ;
1130
1142
1131
- if payee_node_id == our_node_id {
1143
+ if payee_node_id. map_or ( false , |payee| payee == our_node_id) {
1132
1144
return Err ( LightningError { err : "Cannot generate a route to ourselves" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1133
1145
}
1134
1146
@@ -1141,10 +1153,10 @@ where L::Target: Logger {
1141
1153
}
1142
1154
1143
1155
match & payment_params. payee {
1144
- Payee :: Clear { route_hints } => {
1156
+ Payee :: Clear { route_hints, node_id } => {
1145
1157
for route in route_hints. iter ( ) {
1146
1158
for hop in & route. 0 {
1147
- if hop. src_node_id == payment_params . payee_pubkey {
1159
+ if hop. src_node_id == * node_id {
1148
1160
return Err ( LightningError { err : "Route hint cannot have the payee as the source." . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1149
1161
}
1150
1162
}
@@ -1227,14 +1239,13 @@ where L::Target: Logger {
1227
1239
false
1228
1240
} else if let Some ( features) = & payment_params. features {
1229
1241
features. supports_basic_mpp ( )
1230
- } else if let Some ( node) = network_nodes. get ( & payee_node_id) {
1231
- if let Some ( node_info) = node. announcement_info . as_ref ( ) {
1232
- node_info. features . supports_basic_mpp ( )
1233
- } else { false }
1242
+ } else if let Some ( payee) = payee_node_id {
1243
+ network_nodes. get ( & payee) . map_or ( false , |node| node. announcement_info . as_ref ( ) . map_or ( false ,
1244
+ |info| info. features . supports_basic_mpp ( ) ) )
1234
1245
} else { false } ;
1235
1246
1236
- log_trace ! ( logger, "Searching for a route from payer {} to payee {} {} MPP and {} first hops {}overriding the network graph" , our_node_pubkey,
1237
- payment_params. payee_pubkey , if allow_mpp { "with" } else { "without" } ,
1247
+ log_trace ! ( logger, "Searching for a route from payer {} to payee {:? } {} MPP and {} first hops {}overriding the network graph" , our_node_pubkey,
1248
+ payment_params. payee , if allow_mpp { "with" } else { "without" } ,
1238
1249
first_hops. map( |hops| hops. len( ) ) . unwrap_or( 0 ) , if first_hops. is_some( ) { "" } else { "not " } ) ;
1239
1250
1240
1251
// Step (1).
@@ -1337,7 +1348,9 @@ where L::Target: Logger {
1337
1348
} ) ;
1338
1349
}
1339
1350
1340
- log_trace ! ( logger, "Building path from {} (payee) to {} (us/payer) for value {} msat." , payment_params. payee_pubkey, our_node_pubkey, final_value_msat) ;
1351
+ log_trace ! ( logger, "Building path from {}payee with node id {:?} to payer {} for value {} msat." ,
1352
+ if payment_params. payee. node_id( ) . is_some( ) { "blinded " } else { "" } ,
1353
+ payment_params. payee. node_id( ) , our_node_pubkey, final_value_msat) ;
1341
1354
1342
1355
macro_rules! add_entry {
1343
1356
// Adds entry which goes from $src_node_id to $dest_node_id over the $candidate hop.
@@ -1586,7 +1599,7 @@ where L::Target: Logger {
1586
1599
// Entries are added to dist in add_entry!() when there is a channel from a node.
1587
1600
// Because there are no channels from payee, it will not have a dist entry at this point.
1588
1601
// If we're processing any other node, it is always be the result of a channel from it.
1589
- assert_eq!( $node_id, payee_node_id ) ;
1602
+ assert_eq!( $node_id, target_node_id ) ;
1590
1603
false
1591
1604
} ;
1592
1605
@@ -1646,35 +1659,35 @@ where L::Target: Logger {
1646
1659
1647
1660
// If first hop is a private channel and the only way to reach the payee, this is the only
1648
1661
// place where it could be added.
1649
- if let Some ( first_channels ) = first_hop_targets. get ( & payee_node_id ) {
1662
+ payee_node_id . map ( |payee| first_hop_targets. get ( & payee ) . map ( |first_channels| {
1650
1663
for details in first_channels {
1651
1664
let candidate = CandidateRouteHop :: FirstHop { details } ;
1652
- let added = add_entry ! ( candidate, our_node_id, payee_node_id , 0 , path_value_msat,
1665
+ let added = add_entry ! ( candidate, our_node_id, payee , 0 , path_value_msat,
1653
1666
0 , 0u64 , 0 , 0 ) ;
1654
1667
log_trace ! ( logger, "{} direct route to payee via SCID {}" ,
1655
1668
if added { "Added" } else { "Skipped" } , candidate. short_channel_id( ) ) ;
1656
1669
}
1657
- }
1670
+ } ) ) ;
1658
1671
1659
1672
// Add the payee as a target, so that the payee-to-payer
1660
1673
// search algorithm knows what to start with.
1661
- match network_nodes. get ( & payee_node_id ) {
1674
+ payee_node_id . map ( |payee| match network_nodes. get ( & payee ) {
1662
1675
// The payee is not in our network graph, so nothing to add here.
1663
1676
// There is still a chance of reaching them via last_hops though,
1664
1677
// so don't yet fail the payment here.
1665
1678
// If not, targets.pop() will not even let us enter the loop in step 2.
1666
1679
None => { } ,
1667
1680
Some ( node) => {
1668
- add_entries_to_cheapest_to_target_node ! ( node, payee_node_id , 0 , path_value_msat, 0 , 0u64 , 0 , 0 ) ;
1681
+ add_entries_to_cheapest_to_target_node ! ( node, payee , 0 , path_value_msat, 0 , 0u64 , 0 , 0 ) ;
1669
1682
} ,
1670
- }
1683
+ } ) ;
1671
1684
1672
1685
// Step (2).
1673
1686
// If a caller provided us with last hops, add them to routing targets. Since this happens
1674
1687
// earlier than general path finding, they will be somewhat prioritized, although currently
1675
1688
// it matters only if the fees are exactly the same.
1676
1689
let route_hints = match & payment_params. payee {
1677
- Payee :: Clear { route_hints } => route_hints,
1690
+ Payee :: Clear { route_hints, .. } => route_hints,
1678
1691
_ => return Err ( LightningError { err : "Routing to blinded paths isn't supported yet" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ,
1679
1692
} ;
1680
1693
for route in route_hints. iter ( ) . filter ( |route| !route. 0 . is_empty ( ) ) {
@@ -1689,7 +1702,7 @@ where L::Target: Logger {
1689
1702
// We start building the path from reverse, i.e., from payee
1690
1703
// to the first RouteHintHop in the path.
1691
1704
let hop_iter = route. 0 . iter ( ) . rev ( ) ;
1692
- let prev_hop_iter = core:: iter:: once ( & payment_params . payee_pubkey ) . chain (
1705
+ let prev_hop_iter = core:: iter:: once ( & target_pubkey ) . chain (
1693
1706
route. 0 . iter ( ) . skip ( 1 ) . rev ( ) . map ( |hop| & hop. src_node_id ) ) ;
1694
1707
let mut hop_used = true ;
1695
1708
let mut aggregate_next_hops_fee_msat: u64 = 0 ;
@@ -1849,7 +1862,7 @@ where L::Target: Logger {
1849
1862
// save this path for the payment route. Also, update the liquidity
1850
1863
// remaining on the used hops, so that we take them into account
1851
1864
// while looking for more paths.
1852
- if ordered_hops. last ( ) . unwrap ( ) . 0 . node_id == payee_node_id {
1865
+ if ordered_hops. last ( ) . unwrap ( ) . 0 . node_id == target_node_id {
1853
1866
break ' path_walk;
1854
1867
}
1855
1868
@@ -1932,7 +1945,7 @@ where L::Target: Logger {
1932
1945
// If we found a path back to the payee, we shouldn't try to process it again. This is
1933
1946
// the equivalent of the `elem.was_processed` check in
1934
1947
// add_entries_to_cheapest_to_target_node!() (see comment there for more info).
1935
- if node_id == payee_node_id { continue ' path_construction; }
1948
+ if node_id == target_node_id { continue ' path_construction; }
1936
1949
1937
1950
// Otherwise, since the current target node is not us,
1938
1951
// keep "unrolling" the payment graph from payee to payer by
@@ -2102,7 +2115,7 @@ where L::Target: Logger {
2102
2115
paths,
2103
2116
payment_params : Some ( payment_params. clone ( ) ) ,
2104
2117
} ;
2105
- log_info ! ( logger, "Got route to {} : {}" , payment_params . payee_pubkey , log_route!( route) ) ;
2118
+ log_info ! ( logger, "Got route: {}" , log_route!( route) ) ;
2106
2119
Ok ( route)
2107
2120
}
2108
2121
0 commit comments