@@ -1874,6 +1874,9 @@ where L::Target: Logger {
18741874 return Err ( LightningError { err : "Cannot send a payment of 0 msat" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
18751875 }
18761876
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 < _ > > ( ) ;
18771880 match & payment_params. payee {
18781881 Payee :: Clear { route_hints, node_id, .. } => {
18791882 for route in route_hints. iter ( ) {
@@ -1885,17 +1888,19 @@ where L::Target: Logger {
18851888 }
18861889 } ,
18871890 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) ) {
18891892 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 } ) ;
18901893 }
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 ( ) ) {
18921895 if blinded_path. blinded_hops . len ( ) == 0 {
18931896 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) {
18951898 log_info ! ( logger, "Got blinded path with ourselves as the introduction node, ignoring" ) ;
18961899 } 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)
18991904 {
19001905 return Err ( LightningError { err : format ! ( "1-hop blinded paths must all have matching introduction node ids" ) , action : ErrorAction :: IgnoreError } ) ;
19011906 }
@@ -2540,7 +2545,7 @@ where L::Target: Logger {
25402545 // Only add the hops in this route to our candidate set if either
25412546 // we have a direct channel to the first hop or the first hop is
25422547 // 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 ] {
25442549 Some ( node_id) => node_id,
25452550 None => match & hint. 1 . introduction_node {
25462551 IntroductionNode :: NodeId ( pubkey) => {
0 commit comments