@@ -63,6 +63,16 @@ lazy_static::lazy_static! {
6363/// We set out snap build to set this environment variable to the real home directory,
6464/// because by default, snaps run in a confined environment where the home directory is not
6565/// the user's actual home directory.
66+ fn parse_drop_rate ( s : & str ) -> Result < f64 , String > {
67+ let v: f64 = s
68+ . parse ( )
69+ . map_err ( |_| format ! ( "'{}' is not a valid number" , s) ) ?;
70+ if !( 0.0 ..=1.0 ) . contains ( & v) {
71+ return Err ( format ! ( "drop rate must be between 0.0 and 1.0, got {}" , v) ) ;
72+ }
73+ Ok ( v)
74+ }
75+
6676pub fn get_home_dir ( ) -> String {
6777 if let Ok ( real_home) = env:: var ( "SNAP_REAL_HOME" ) {
6878 let path_buf = PathBuf :: from ( real_home) ;
@@ -276,6 +286,14 @@ pub struct StartSimnet {
276286 /// Skip signature verification for all transactions (eg. surfpool start --skip-signature-verification)
277287 #[ clap( long = "skip-signature-verification" , action=ArgAction :: SetTrue , default_value = "false" ) ]
278288 pub skip_signature_verification : bool ,
289+ /// Probability (0.0–1.0) that a transaction is randomly dropped, simulating packet loss or leader rejection.
290+ /// E.g. 0.1 means 10% of transactions will be dropped. (eg. surfpool start --transaction-drop-rate 0.1)
291+ #[ arg( long = "transaction-drop-rate" , value_parser = parse_drop_rate) ]
292+ pub transaction_drop_rate : Option < f64 > ,
293+ /// Maximum random delay in milliseconds before executing a transaction, simulating out-of-order execution.
294+ /// Each transaction waits a random duration from 0 to this value. (eg. surfpool start --transaction-execution-delay-ms 200)
295+ #[ arg( long = "transaction-execution-delay-ms" ) ]
296+ pub transaction_execution_delay_ms : Option < u64 > ,
279297}
280298
281299#[ derive( clap:: ValueEnum , PartialEq , Clone , Debug ) ]
@@ -426,6 +444,8 @@ impl StartSimnet {
426444 skip_signature_verification : self . skip_signature_verification ,
427445 surfnet_id : self . surfnet_id . clone ( ) ,
428446 snapshot,
447+ transaction_drop_rate : self . transaction_drop_rate ,
448+ transaction_execution_delay_ms : self . transaction_execution_delay_ms ,
429449 }
430450 }
431451
0 commit comments