@@ -1874,6 +1874,9 @@ where L::Target: Logger {
1874
1874
return Err ( LightningError { err : "Cannot send a payment of 0 msat" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1875
1875
}
1876
1876
1877
+ let introduction_node_id_cache = payment_params. payee . blinded_route_hints ( ) . iter ( )
1878
+ . map ( |( _, path) | path. public_introduction_node_id ( network_graph) )
1879
+ . collect :: < Vec < _ > > ( ) ;
1877
1880
match & payment_params. payee {
1878
1881
Payee :: Clear { route_hints, node_id, .. } => {
1879
1882
for route in route_hints. iter ( ) {
@@ -1885,17 +1888,19 @@ where L::Target: Logger {
1885
1888
}
1886
1889
} ,
1887
1890
Payee :: Blinded { route_hints, .. } => {
1888
- if route_hints . iter ( ) . all ( |( _ , path ) | path . public_introduction_node_id ( network_graph ) == Some ( & our_node_id) ) {
1891
+ if introduction_node_id_cache . iter ( ) . all ( |introduction_node_id| * introduction_node_id == Some ( & our_node_id) ) {
1889
1892
return Err ( LightningError { err : "Cannot generate a route to blinded paths if we are the introduction node to all of them" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1890
1893
}
1891
- for ( _, blinded_path) in route_hints. iter ( ) {
1894
+ for ( ( _, blinded_path) , introduction_node_id ) in route_hints. iter ( ) . zip ( introduction_node_id_cache . iter ( ) ) {
1892
1895
if blinded_path. blinded_hops . len ( ) == 0 {
1893
1896
return Err ( LightningError { err : "0-hop blinded path provided" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1894
- } else if blinded_path . public_introduction_node_id ( network_graph ) == Some ( & our_node_id) {
1897
+ } else if * introduction_node_id == Some ( & our_node_id) {
1895
1898
log_info ! ( logger, "Got blinded path with ourselves as the introduction node, ignoring" ) ;
1896
1899
} else if blinded_path. blinded_hops . len ( ) == 1 &&
1897
- route_hints. iter ( ) . any ( |( _, p) | p. blinded_hops . len ( ) == 1
1898
- && p. public_introduction_node_id ( network_graph) != blinded_path. public_introduction_node_id ( network_graph) )
1900
+ route_hints
1901
+ . iter ( ) . zip ( introduction_node_id_cache. iter ( ) )
1902
+ . filter ( |( ( _, p) , _) | p. blinded_hops . len ( ) == 1 )
1903
+ . any ( |( _, p_introduction_node_id) | p_introduction_node_id != introduction_node_id)
1899
1904
{
1900
1905
return Err ( LightningError { err : format ! ( "1-hop blinded paths must all have matching introduction node ids" ) , action : ErrorAction :: IgnoreError } ) ;
1901
1906
}
@@ -2540,7 +2545,7 @@ where L::Target: Logger {
2540
2545
// Only add the hops in this route to our candidate set if either
2541
2546
// we have a direct channel to the first hop or the first hop is
2542
2547
// in the regular network graph.
2543
- let source_node_id = match hint . 1 . public_introduction_node_id ( network_graph ) {
2548
+ let source_node_id = match introduction_node_id_cache [ hint_idx ] {
2544
2549
Some ( node_id) => node_id,
2545
2550
None => match & hint. 1 . introduction_node {
2546
2551
IntroductionNode :: NodeId ( pubkey) => {
0 commit comments