1
- use crate :: clock:: Clock ;
1
+ use crate :: clock:: { Clock , SimulationClock } ;
2
2
use crate :: {
3
3
Graph , LightningError , LightningNode , NodeInfo , PaymentOutcome , PaymentResult , SimulationError ,
4
4
} ;
@@ -513,6 +513,8 @@ pub struct SimNode<T: SimNetwork> {
513
513
/// Probabilistic scorer used to rank paths through the network for routing. This is reused across
514
514
/// multiple payments to maintain scoring state.
515
515
scorer : ProbabilisticScorer < Arc < LdkNetworkGraph > , Arc < WrappedLog > > ,
516
+ /// Clock for tracking simulation time.
517
+ clock : SimulationClock ,
516
518
}
517
519
518
520
impl < T : SimNetwork > SimNode < T > {
@@ -522,7 +524,7 @@ impl<T: SimNetwork> SimNode<T> {
522
524
info : NodeInfo ,
523
525
payment_network : Arc < Mutex < T > > ,
524
526
pathfinding_graph : Arc < LdkNetworkGraph > ,
525
- ) -> Self {
527
+ ) -> Result < Self , LightningError > {
526
528
// Initialize the probabilistic scorer with default parameters for learning from payment
527
529
// history. These parameters control how much successful/failed payments affect routing
528
530
// scores and how quickly these scores decay over time.
@@ -532,13 +534,24 @@ impl<T: SimNetwork> SimNode<T> {
532
534
Arc :: new ( WrappedLog { } ) ,
533
535
) ;
534
536
535
- SimNode {
537
+ let clock = match SimulationClock :: new ( 1 ) {
538
+ Ok ( c) => c,
539
+ Err ( e) => {
540
+ return Err ( LightningError :: SendPaymentError ( format ! (
541
+ "Error creating simulation clock: {}" ,
542
+ e
543
+ ) ) ) ;
544
+ } ,
545
+ } ;
546
+
547
+ Ok ( SimNode {
536
548
info,
537
549
network : payment_network,
538
550
in_flight : HashMap :: new ( ) ,
539
551
pathfinding_graph,
540
552
scorer,
541
- }
553
+ clock,
554
+ } )
542
555
}
543
556
544
557
/// Dispatches a payment to a specified route. If `custom_records` is `Some`, they will be attached to the outgoing
@@ -1044,7 +1057,7 @@ impl SimGraph {
1044
1057
pub async fn ln_node_from_graph (
1045
1058
graph : Arc < Mutex < SimGraph > > ,
1046
1059
routing_graph : Arc < LdkNetworkGraph > ,
1047
- ) -> HashMap < PublicKey , Arc < Mutex < SimNode < SimGraph > > > > {
1060
+ ) -> Result < HashMap < PublicKey , Arc < Mutex < SimNode < SimGraph > > > > , LightningError > {
1048
1061
let mut nodes: HashMap < PublicKey , Arc < Mutex < SimNode < SimGraph > > > > = HashMap :: new ( ) ;
1049
1062
1050
1063
for node in graph. lock ( ) . await . nodes . iter ( ) {
@@ -1054,11 +1067,11 @@ pub async fn ln_node_from_graph(
1054
1067
node. 1 . 0 . clone ( ) ,
1055
1068
graph. clone ( ) ,
1056
1069
routing_graph. clone ( ) ,
1057
- ) ) ) ,
1070
+ ) ? ) ) ,
1058
1071
) ;
1059
1072
}
1060
1073
1061
- nodes
1074
+ Ok ( nodes)
1062
1075
}
1063
1076
1064
1077
/// Populates a network graph based on the set of simulated channels provided. This function *only* applies channel
@@ -1939,7 +1952,8 @@ mod tests {
1939
1952
node_info ( pk, String :: default ( ) ) ,
1940
1953
sim_network. clone ( ) ,
1941
1954
Arc :: new ( graph) ,
1942
- ) ;
1955
+ )
1956
+ . unwrap ( ) ;
1943
1957
1944
1958
// Prime mock to return node info from lookup and assert that we get the pubkey we're expecting.
1945
1959
let lookup_pk = channels[ 3 ] . node_1 . policy . pubkey ;
@@ -2333,7 +2347,8 @@ mod tests {
2333
2347
node_info ( test_kit. nodes [ 0 ] , String :: default ( ) ) ,
2334
2348
Arc :: new ( Mutex :: new ( test_kit. graph ) ) ,
2335
2349
test_kit. routing_graph . clone ( ) ,
2336
- ) ;
2350
+ )
2351
+ . unwrap ( ) ;
2337
2352
2338
2353
let route = build_route_from_hops (
2339
2354
& test_kit. nodes [ 0 ] ,
0 commit comments