@@ -4,6 +4,7 @@ use bitcoin::Network;
4
4
use csv:: WriterBuilder ;
5
5
use lightning:: ln:: features:: NodeFeatures ;
6
6
use lightning:: ln:: PaymentHash ;
7
+ use random_activity:: RandomActivityError ;
7
8
use serde:: { Deserialize , Serialize } ;
8
9
use std:: collections:: HashSet ;
9
10
use std:: fmt:: { Display , Formatter } ;
@@ -23,6 +24,8 @@ pub mod cln;
23
24
pub mod lnd;
24
25
mod random_activity;
25
26
mod serializers;
27
+ #[ cfg( test) ]
28
+ mod test_utils;
26
29
27
30
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
28
31
#[ serde( untagged) ]
@@ -125,8 +128,8 @@ pub enum SimulationError {
125
128
CsvError ( #[ from] csv:: Error ) ,
126
129
#[ error( "File Error" ) ]
127
130
FileError ,
128
- #[ error( "Random activity Error: {0}" ) ]
129
- RandomActivityError ( String ) ,
131
+ #[ error( "{0}" ) ]
132
+ RandomActivityError ( RandomActivityError ) ,
130
133
}
131
134
132
135
// Phase 2: Event Queue
@@ -203,12 +206,15 @@ pub trait NetworkGenerator {
203
206
fn sample_node_by_capacity ( & self , source : PublicKey ) -> ( NodeInfo , u64 ) ;
204
207
}
205
208
209
+ #[ derive( Debug , Error ) ]
210
+ #[ error( "Payment generation error: {0}" ) ]
211
+ pub struct PaymentGenerationError ( String ) ;
206
212
pub trait PaymentGenerator {
207
213
// Returns the number of seconds that a node should wait until firing its next payment.
208
214
fn next_payment_wait ( & self ) -> time:: Duration ;
209
215
210
216
// Returns a payment amount based on the capacity of the sending and receiving node.
211
- fn payment_amount ( & self , destination_capacity : u64 ) -> Result < u64 , SimulationError > ;
217
+ fn payment_amount ( & self , destination_capacity : u64 ) -> Result < u64 , PaymentGenerationError > ;
212
218
}
213
219
214
220
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -642,9 +648,10 @@ impl Simulation {
642
648
producer_channels : HashMap < PublicKey , Sender < SimulationEvent > > ,
643
649
tasks : & mut JoinSet < ( ) > ,
644
650
) -> Result < ( ) , SimulationError > {
645
- let network_generator = Arc :: new ( Mutex :: new ( NetworkGraphView :: new (
646
- node_capacities. values ( ) . cloned ( ) . collect ( ) ,
647
- ) ?) ) ;
651
+ let network_generator = Arc :: new ( Mutex :: new (
652
+ NetworkGraphView :: new ( node_capacities. values ( ) . cloned ( ) . collect ( ) )
653
+ . map_err ( SimulationError :: RandomActivityError ) ?,
654
+ ) ) ;
648
655
649
656
log:: info!(
650
657
"Created network generator: {}." ,
@@ -655,18 +662,21 @@ impl Simulation {
655
662
let ( info, source_capacity) = match node_capacities. get ( & pk) {
656
663
Some ( ( info, capacity) ) => ( info. clone ( ) , * capacity) ,
657
664
None => {
658
- return Err ( SimulationError :: RandomActivityError ( format ! (
659
- "Random activity generator run for: {} with unknown capacity." ,
660
- pk
661
- ) ) ) ;
665
+ return Err ( SimulationError :: RandomActivityError (
666
+ RandomActivityError :: ValueError ( format ! (
667
+ "Random activity generator run for: {} with unknown capacity." ,
668
+ pk
669
+ ) ) ,
670
+ ) ) ;
662
671
}
663
672
} ;
664
673
665
674
let node_generator = PaymentActivityGenerator :: new (
666
675
source_capacity,
667
676
self . expected_payment_msat ,
668
677
self . activity_multiplier ,
669
- ) ?;
678
+ )
679
+ . map_err ( SimulationError :: RandomActivityError ) ?;
670
680
671
681
tasks. spawn ( produce_random_events (
672
682
info,
0 commit comments