@@ -7,13 +7,16 @@ use mina_p2p_messages::v2::{
77
88use std:: { collections:: BTreeSet , time:: Duration } ;
99
10- use node:: { ActionKind , BlockProducerConfig , SnarkerConfig , SnarkerStrategy , State } ;
10+ use node:: {
11+ ActionKind , ActionWithMeta , BlockProducerConfig , SnarkerConfig , SnarkerStrategy , State ,
12+ } ;
1113
1214use crate :: {
1315 cluster:: ClusterNodeId ,
1416 node:: { Node , RustNodeBlockProducerTestingConfig , RustNodeTestingConfig } ,
1517 scenario:: ListenerNode ,
1618 scenarios:: { ClusterRunner , RunCfg } ,
19+ service:: NodeTestingService ,
1720} ;
1821
1922pub struct Simulator {
@@ -217,19 +220,46 @@ impl Simulator {
217220 self . wait_for_all_nodes_synced ( runner) . await ;
218221 }
219222
223+ pub async fn setup_and_run_with_listener < ' a , AL , ALF > (
224+ & mut self ,
225+ runner : & mut ClusterRunner < ' a > ,
226+ listener : ALF ,
227+ ) where
228+ ALF : FnMut ( ) -> AL ,
229+ AL : ' static
230+ + Send
231+ + FnMut ( ClusterNodeId , & State , & NodeTestingService , & ActionWithMeta ) -> bool ,
232+ {
233+ self . setup ( runner) . await ;
234+ self . run_with_listener ( runner, listener) . await ;
235+ }
236+
237+ pub async fn setup_and_run < ' a > ( & mut self , runner : & mut ClusterRunner < ' a > ) {
238+ self . setup ( runner) . await ;
239+ self . run_with_listener ( runner, || |_, _, _, _| false ) . await ;
240+ }
241+
220242 pub async fn setup < ' a > ( & mut self , runner : & mut ClusterRunner < ' a > ) {
221243 self . set_up_seed_nodes ( runner) . await ;
222244 self . set_up_normal_nodes ( runner) . await ;
223245 self . set_up_snark_worker_nodes ( runner) . await ;
224246 self . set_up_block_producer_nodes ( runner) . await ;
225247 }
226248
227- pub async fn setup_and_run < ' a > ( & mut self , runner : & mut ClusterRunner < ' a > ) {
228- self . setup ( runner) . await ;
229- self . run ( runner) . await ;
249+ pub async fn run < ' a > ( & mut self , runner : & mut ClusterRunner < ' a > ) {
250+ self . run_with_listener ( runner, || |_, _, _, _| false ) . await ;
230251 }
231252
232- pub async fn run < ' a > ( & mut self , runner : & mut ClusterRunner < ' a > ) {
253+ pub async fn run_with_listener < ' a , AL , ALF > (
254+ & mut self ,
255+ runner : & mut ClusterRunner < ' a > ,
256+ mut listener : ALF ,
257+ ) where
258+ ALF : FnMut ( ) -> AL ,
259+ AL : ' static
260+ + Send
261+ + FnMut ( ClusterNodeId , & State , & NodeTestingService , & ActionWithMeta ) -> bool ,
262+ {
233263 let run_until = self . config . run_until . clone ( ) ;
234264 let advance_time = self . config . advance_time . clone ( ) ;
235265 let start_t = * self . start_t . get_or_insert_with ( redux:: Instant :: now) ;
@@ -238,13 +268,11 @@ impl Simulator {
238268
239269 while start_t. elapsed ( ) < self . config . run_until_timeout {
240270 tokio:: task:: yield_now ( ) . await ;
241- let _ = runner
242- . run (
243- RunCfg :: default ( )
244- . advance_time ( advance_time. clone ( ) )
245- . timeout ( Duration :: ZERO ) ,
246- )
247- . await ;
271+ let cfg = RunCfg :: default ( )
272+ . advance_time ( advance_time. clone ( ) )
273+ . timeout ( Duration :: ZERO )
274+ . action_handler ( listener ( ) ) ;
275+ let _ = runner. run ( cfg) . await ;
248276
249277 let printed_elapsed_time = {
250278 let state = runner. nodes_iter ( ) . next ( ) . unwrap ( ) . 1 . state ( ) ;
0 commit comments