@@ -17,7 +17,7 @@ use bitcoin::secp256k1::PublicKey;
1717use ln:: channelmanager:: ChannelDetails ;
1818use ln:: features:: { ChannelFeatures , InvoiceFeatures , NodeFeatures } ;
1919use ln:: msgs:: { DecodeError , ErrorAction , LightningError , MAX_VALUE_MSAT } ;
20- use routing:: gossip:: { DirectedChannelInfoWithUpdate , EffectiveCapacity , ReadOnlyNetworkGraph , NodeId , RoutingFees } ;
20+ use routing:: gossip:: { DirectedChannelInfoWithUpdate , EffectiveCapacity , ReadOnlyNetworkGraph , NetworkGraph , NodeId , RoutingFees } ;
2121use routing:: scoring:: { ChannelUsage , Score } ;
2222use util:: ser:: { Writeable , Readable , Writer } ;
2323use util:: logger:: { Level , Logger } ;
@@ -690,16 +690,17 @@ fn default_node_features() -> NodeFeatures {
690690/// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
691691/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
692692/// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
693- pub fn find_route < L : Deref , S : Score > (
693+ pub fn find_route < L : Deref , GL : Deref , S : Score > (
694694 our_node_pubkey : & PublicKey , route_params : & RouteParameters ,
695- network_graph : & ReadOnlyNetworkGraph , first_hops : Option < & [ & ChannelDetails ] > , logger : L ,
695+ network_graph : & NetworkGraph < GL > , first_hops : Option < & [ & ChannelDetails ] > , logger : L ,
696696 scorer : & S , random_seed_bytes : & [ u8 ; 32 ]
697697) -> Result < Route , LightningError >
698- where L :: Target : Logger {
699- let mut route = get_route ( our_node_pubkey, & route_params. payment_params , network_graph, first_hops,
698+ where L :: Target : Logger , GL :: Target : Logger {
699+ let graph_lock = network_graph. read_only ( ) ;
700+ let mut route = get_route ( our_node_pubkey, & route_params. payment_params , & graph_lock, first_hops,
700701 route_params. final_value_msat , route_params. final_cltv_expiry_delta , logger, scorer,
701702 random_seed_bytes) ?;
702- add_random_cltv_offset ( & mut route, & route_params. payment_params , network_graph , random_seed_bytes) ;
703+ add_random_cltv_offset ( & mut route, & route_params. payment_params , & graph_lock , random_seed_bytes) ;
703704 Ok ( route)
704705}
705706
@@ -1803,15 +1804,16 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
18031804/// exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
18041805///
18051806/// Re-uses logic from `find_route`, so the restrictions described there also apply here.
1806- pub fn build_route_from_hops < L : Deref > (
1807+ pub fn build_route_from_hops < L : Deref , GL : Deref > (
18071808 our_node_pubkey : & PublicKey , hops : & [ PublicKey ] , route_params : & RouteParameters ,
1808- network_graph : & ReadOnlyNetworkGraph , logger : L , random_seed_bytes : & [ u8 ; 32 ]
1809+ network_graph : & NetworkGraph < GL > , logger : L , random_seed_bytes : & [ u8 ; 32 ]
18091810) -> Result < Route , LightningError >
1810- where L :: Target : Logger {
1811+ where L :: Target : Logger , GL :: Target : Logger {
1812+ let graph_lock = network_graph. read_only ( ) ;
18111813 let mut route = build_route_from_hops_internal (
1812- our_node_pubkey, hops, & route_params. payment_params , & network_graph ,
1814+ our_node_pubkey, hops, & route_params. payment_params , & graph_lock ,
18131815 route_params. final_value_msat , route_params. final_cltv_expiry_delta , logger, random_seed_bytes) ?;
1814- add_random_cltv_offset ( & mut route, & route_params. payment_params , & network_graph , random_seed_bytes) ;
1816+ add_random_cltv_offset ( & mut route, & route_params. payment_params , & graph_lock , random_seed_bytes) ;
18151817 Ok ( route)
18161818}
18171819
0 commit comments