@@ -487,38 +487,40 @@ pub trait SimNetwork: Send + Sync {
487487 fn list_nodes ( & self ) -> Vec < NodeInfo > ;
488488}
489489
490+ type LdkNetworkGraph = NetworkGraph < Arc < WrappedLog > > ;
491+
490492/// A wrapper struct used to implement the LightningNode trait (can be thought of as "the" lightning node). Passes
491493/// all functionality through to a coordinating simulation network. This implementation contains both the [`SimNetwork`]
492494/// implementation that will allow us to dispatch payments and a read-only NetworkGraph that is used for pathfinding.
493495/// While these two could be combined, we re-use the LDK-native struct to allow re-use of their pathfinding logic.
494- pub struct SimNode < ' a , T : SimNetwork > {
496+ pub struct SimNode < T : SimNetwork > {
495497 info : NodeInfo ,
496498 /// The underlying execution network that will be responsible for dispatching payments.
497499 network : Arc < Mutex < T > > ,
498500 /// Tracks the channel that will provide updates for payments by hash.
499501 in_flight : HashMap < PaymentHash , Receiver < Result < PaymentResult , LightningError > > > ,
500502 /// A read-only graph used for pathfinding.
501- pathfinding_graph : Arc < NetworkGraph < & ' a WrappedLog > > ,
503+ pathfinding_graph : Arc < LdkNetworkGraph > ,
502504 /// Probabilistic scorer used to rank paths through the network for routing. This is reused across
503505 /// multiple payments to maintain scoring state.
504- scorer : ProbabilisticScorer < Arc < NetworkGraph < & ' a WrappedLog > > , & ' a WrappedLog > ,
506+ scorer : ProbabilisticScorer < Arc < LdkNetworkGraph > , Arc < WrappedLog > > ,
505507}
506508
507- impl < ' a , T : SimNetwork > SimNode < ' a , T > {
509+ impl < T : SimNetwork > SimNode < T > {
508510 /// Creates a new simulation node that refers to the high level network coordinator provided to process payments
509511 /// on its behalf. The pathfinding graph is provided separately so that each node can handle its own pathfinding.
510512 pub fn new (
511513 info : NodeInfo ,
512514 payment_network : Arc < Mutex < T > > ,
513- pathfinding_graph : Arc < NetworkGraph < & ' a WrappedLog > > ,
515+ pathfinding_graph : Arc < LdkNetworkGraph > ,
514516 ) -> Self {
515517 // Initialize the probabilistic scorer with default parameters for learning from payment
516518 // history. These parameters control how much successful/failed payments affect routing
517519 // scores and how quickly these scores decay over time.
518520 let scorer = ProbabilisticScorer :: new (
519521 ProbabilisticScoringDecayParameters :: default ( ) ,
520522 pathfinding_graph. clone ( ) ,
521- & WrappedLog { } ,
523+ Arc :: new ( WrappedLog { } ) ,
522524 ) ;
523525
524526 SimNode {
@@ -584,12 +586,12 @@ fn node_info(pubkey: PublicKey, alias: String) -> NodeInfo {
584586
585587/// Uses LDK's pathfinding algorithm with default parameters to find a path from source to destination, with no
586588/// restrictions on fee budget.
587- fn find_payment_route < ' a > (
589+ fn find_payment_route (
588590 source : & PublicKey ,
589591 dest : PublicKey ,
590592 amount_msat : u64 ,
591- pathfinding_graph : & NetworkGraph < & ' a WrappedLog > ,
592- scorer : & ProbabilisticScorer < Arc < NetworkGraph < & ' a WrappedLog > > , & ' a WrappedLog > ,
593+ pathfinding_graph : & LdkNetworkGraph ,
594+ scorer : & ProbabilisticScorer < Arc < LdkNetworkGraph > , Arc < WrappedLog > > ,
593595) -> Result < Route , SimulationError > {
594596 find_route (
595597 source,
@@ -606,15 +608,15 @@ fn find_payment_route<'a>(
606608 pathfinding_graph,
607609 None ,
608610 & WrappedLog { } ,
609- scorer,
611+ & scorer,
610612 & Default :: default ( ) ,
611613 & [ 0 ; 32 ] ,
612614 )
613615 . map_err ( |e| SimulationError :: SimulatedNetworkError ( e. err ) )
614616}
615617
616618#[ async_trait]
617- impl < T : SimNetwork > LightningNode for SimNode < ' _ , T > {
619+ impl < T : SimNetwork > LightningNode for SimNode < T > {
618620 fn get_info ( & self ) -> & NodeInfo {
619621 & self . info
620622 }
@@ -1017,9 +1019,9 @@ impl SimGraph {
10171019/// Produces a map of node public key to lightning node implementation to be used for simulations.
10181020pub async fn ln_node_from_graph (
10191021 graph : Arc < Mutex < SimGraph > > ,
1020- routing_graph : Arc < NetworkGraph < & ' _ WrappedLog > > ,
1021- ) -> HashMap < PublicKey , Arc < Mutex < dyn LightningNode + ' _ > > > {
1022- let mut nodes: HashMap < PublicKey , Arc < Mutex < dyn LightningNode > > > = HashMap :: new ( ) ;
1022+ routing_graph : Arc < LdkNetworkGraph > ,
1023+ ) -> HashMap < PublicKey , Arc < Mutex < SimNode < SimGraph > > > > {
1024+ let mut nodes: HashMap < PublicKey , Arc < Mutex < SimNode < SimGraph > > > > = HashMap :: new ( ) ;
10231025
10241026 for node in graph. lock ( ) . await . nodes . iter ( ) {
10251027 nodes. insert (
@@ -1039,11 +1041,11 @@ pub async fn ln_node_from_graph(
10391041/// announcements, which has the effect of adding the nodes in each channel to the graph, because LDK does not export
10401042/// all of the fields required to apply node announcements. This means that we will not have node-level information
10411043/// (such as features) available in the routing graph.
1042- pub fn populate_network_graph < ' a , C : Clock > (
1044+ pub fn populate_network_graph < C : Clock > (
10431045 channels : Vec < SimulatedChannel > ,
10441046 clock : Arc < C > ,
1045- ) -> Result < NetworkGraph < & ' a WrappedLog > , LdkError > {
1046- let graph = NetworkGraph :: new ( Network :: Regtest , & WrappedLog { } ) ;
1047+ ) -> Result < LdkNetworkGraph , LdkError > {
1048+ let graph = NetworkGraph :: new ( Network :: Regtest , Arc :: new ( WrappedLog { } ) ) ;
10471049
10481050 let chain_hash = ChainHash :: using_genesis_block ( Network :: Regtest ) ;
10491051
@@ -2002,15 +2004,15 @@ mod tests {
20022004 }
20032005
20042006 /// Contains elements required to test dispatch_payment functionality.
2005- struct DispatchPaymentTestKit < ' a > {
2007+ struct DispatchPaymentTestKit {
20062008 graph : SimGraph ,
20072009 nodes : Vec < PublicKey > ,
2008- routing_graph : Arc < NetworkGraph < & ' a WrappedLog > > ,
2009- scorer : ProbabilisticScorer < Arc < NetworkGraph < & ' a WrappedLog > > , & ' a WrappedLog > ,
2010+ routing_graph : Arc < LdkNetworkGraph > ,
2011+ scorer : ProbabilisticScorer < Arc < LdkNetworkGraph > , Arc < WrappedLog > > ,
20102012 shutdown : ( Trigger , Listener ) ,
20112013 }
20122014
2013- impl DispatchPaymentTestKit < ' _ > {
2015+ impl DispatchPaymentTestKit {
20142016 /// Creates a test graph with a set of nodes connected by three channels, with all the capacity of the channel
20152017 /// on the side of the first node. For example, if called with capacity = 100 it will set up the following
20162018 /// network:
@@ -2031,7 +2033,7 @@ mod tests {
20312033 let scorer = ProbabilisticScorer :: new (
20322034 ProbabilisticScoringDecayParameters :: default ( ) ,
20332035 routing_graph. clone ( ) ,
2034- & WrappedLog { } ,
2036+ Arc :: new ( WrappedLog { } ) ,
20352037 ) ;
20362038
20372039 // Collect pubkeys in-order, pushing the last node on separately because they don't have an outgoing
0 commit comments