@@ -17,7 +17,7 @@ use bitcoin::secp256k1::PublicKey;
17
17
use ln:: channelmanager:: ChannelDetails ;
18
18
use ln:: features:: { ChannelFeatures , InvoiceFeatures , NodeFeatures } ;
19
19
use 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 } ;
21
21
use routing:: scoring:: { ChannelUsage , Score } ;
22
22
use util:: ser:: { Writeable , Readable , Writer } ;
23
23
use util:: logger:: { Level , Logger } ;
@@ -690,16 +690,17 @@ fn default_node_features() -> NodeFeatures {
690
690
/// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
691
691
/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
692
692
/// [`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 > (
694
694
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 ,
696
696
scorer : & S , random_seed_bytes : & [ u8 ; 32 ]
697
697
) -> 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,
700
701
route_params. final_value_msat , route_params. final_cltv_expiry_delta , logger, scorer,
701
702
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) ;
703
704
Ok ( route)
704
705
}
705
706
@@ -1803,15 +1804,16 @@ fn add_random_cltv_offset(route: &mut Route, payment_params: &PaymentParameters,
1803
1804
/// exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
1804
1805
///
1805
1806
/// 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 > (
1807
1808
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 ]
1809
1810
) -> Result < Route , LightningError >
1810
- where L :: Target : Logger {
1811
+ where L :: Target : Logger , GL :: Target : Logger {
1812
+ let graph_lock = network_graph. read_only ( ) ;
1811
1813
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 ,
1813
1815
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) ;
1815
1817
Ok ( route)
1816
1818
}
1817
1819
0 commit comments