1
1
use crate :: {
2
- delays:: { heterogeneous_symmetric_delay, spacial_delay_2d , DelayFunction } ,
2
+ delays:: { heterogeneous_symmetric_delay, DelayFunction } ,
3
3
framework:: {
4
4
network:: { InjectedLocalNetwork , Network , NetworkInjection } ,
5
- timer:: InjectedTimerService ,
5
+ timer:: { clock_skew_injection , InjectedTimerService } ,
6
6
NodeId , Protocol ,
7
7
} ,
8
8
leader_schedule:: round_robin,
9
9
multichain:: { Config , MultiChainBft } ,
10
+ raikou:: { dissemination, dissemination:: fake:: FakeDisseminationLayer } ,
10
11
} ;
11
12
use rand:: { seq:: SliceRandom , thread_rng, Rng } ;
12
13
use std:: { collections:: BTreeMap , iter, sync:: Arc , time:: Duration } ;
@@ -29,7 +30,7 @@ const JOLTEON_TIMEOUT: u32 = 3; // in Deltas
29
30
30
31
// TODO: generalize this to any protocol
31
32
fn multichain_network_injection (
32
- delay_function : impl DelayFunction < multichain :: Message > ,
33
+ delay_function : impl DelayFunction ,
33
34
crashes : Vec < ( NodeId , Slot ) > ,
34
35
) -> impl NetworkInjection < multichain:: Message > {
35
36
let crashes = Arc :: new ( BTreeMap :: from_iter ( crashes) ) ;
@@ -52,29 +53,29 @@ fn multichain_network_injection(
52
53
}
53
54
}
54
55
55
- let delay = f64:: max ( delay_function ( from, to, & message ) , 0. ) ;
56
+ let delay = f64:: max ( delay_function ( from, to) , 0. ) ;
56
57
tokio:: time:: sleep ( Duration :: from_secs_f64 ( delay) ) . await ;
57
58
Some ( message)
58
59
}
59
60
}
60
61
}
61
62
fn network_injection < M : Send > (
62
- delay_function : impl DelayFunction < M > ,
63
+ delay_function : impl DelayFunction ,
63
64
// crashes: Vec<(NodeId, Instant)>,
64
65
) -> impl NetworkInjection < M > {
65
66
move |from, to, message| {
66
67
let delay_function = delay_function. clone ( ) ;
67
68
68
69
async move {
69
- let delay = f64:: max ( delay_function ( from, to, & message ) , 0. ) ;
70
+ let delay = f64:: max ( delay_function ( from, to) , 0. ) ;
70
71
tokio:: time:: sleep ( Duration :: from_secs_f64 ( delay) ) . await ;
71
72
Some ( message)
72
73
}
73
74
}
74
75
}
75
76
76
77
async fn test_multichain (
77
- delay_function : impl DelayFunction < multichain :: Message > ,
78
+ delay_function : impl DelayFunction ,
78
79
n_nodes : usize ,
79
80
slots_per_delta : Slot ,
80
81
delta : f64 ,
@@ -158,7 +159,7 @@ async fn test_multichain(
158
159
// network_service.clear_inbox().await;
159
160
160
161
// println!("Spawning node {node_id}");
161
- let node = tokio:: sync:: Mutex :: new ( MultiChainBft :: new_node (
162
+ let node = Arc :: new ( tokio:: sync:: Mutex :: new ( MultiChainBft :: new_node (
162
163
node_id,
163
164
config,
164
165
start_time,
@@ -169,10 +170,10 @@ async fn test_multichain(
169
170
batch_commit_time : batch_commit_time_sender,
170
171
indirectly_committed_slots : indirectly_committed_slots_sender,
171
172
} ,
172
- ) ) ;
173
+ ) ) ) ;
173
174
174
175
semaphore. add_permits ( 1 ) ;
175
- Protocol :: run ( & node, node_id, network_service, timer) . await
176
+ Protocol :: run ( node, node_id, network_service, timer) . await
176
177
} ) ) ;
177
178
}
178
179
@@ -235,7 +236,7 @@ async fn test_multichain(
235
236
}
236
237
237
238
async fn test_multichain_with_random_crashes (
238
- delay_function : impl DelayFunction < multichain :: Message > ,
239
+ delay_function : impl DelayFunction ,
239
240
n_nodes : usize ,
240
241
slots_per_delta : Slot ,
241
242
delta : f64 ,
@@ -268,7 +269,7 @@ async fn test_multichain_with_random_crashes(
268
269
}
269
270
270
271
async fn test_multichain_with_consecutive_faulty_leaders_in_a_chain (
271
- delay_function : impl DelayFunction < multichain :: Message > ,
272
+ delay_function : impl DelayFunction ,
272
273
n_nodes : usize ,
273
274
slots_per_delta : Slot ,
274
275
delta : f64 ,
@@ -298,7 +299,7 @@ async fn test_multichain_with_consecutive_faulty_leaders_in_a_chain(
298
299
}
299
300
300
301
async fn test_jolteon (
301
- delay_function : impl DelayFunction < jolteon :: Message < ( ) > > ,
302
+ delay_function : impl DelayFunction ,
302
303
n_nodes : usize ,
303
304
delta : f64 ,
304
305
warmup_duration_in_delta : u32 ,
@@ -377,16 +378,16 @@ async fn test_jolteon(
377
378
let ( _, txns_receiver) = mpsc:: channel :: < ( ) > ( 100 ) ;
378
379
379
380
// println!("Spawning node {node_id}");
380
- let node = tokio:: sync:: Mutex :: new ( jolteon:: JolteonNode :: new (
381
+ let node = Arc :: new ( tokio:: sync:: Mutex :: new ( jolteon:: JolteonNode :: new (
381
382
node_id,
382
383
config,
383
384
txns_receiver,
384
385
start_time,
385
386
node_id == monitored_node,
386
- ) ) ;
387
+ ) ) ) ;
387
388
388
389
semaphore. add_permits ( 1 ) ;
389
- Protocol :: run ( & node, node_id, network_service, timer) . await
390
+ Protocol :: run ( node, node_id, network_service, timer) . await
390
391
} ) ) ;
391
392
}
392
393
@@ -449,7 +450,7 @@ async fn test_jolteon(
449
450
}
450
451
451
452
async fn test_jolteon_with_fast_qs (
452
- delay_function : impl DelayFunction < jolteon_fast_qs :: Message < ( ) > > ,
453
+ delay_function : impl DelayFunction ,
453
454
n_nodes : usize ,
454
455
delta : f64 ,
455
456
warmup_duration_in_delta : u32 ,
@@ -532,7 +533,7 @@ async fn test_jolteon_with_fast_qs(
532
533
let next_txn = || ( ) ;
533
534
534
535
// println!("Spawning node {node_id}");
535
- let node = tokio:: sync:: Mutex :: new ( jolteon_fast_qs:: JolteonNode :: new (
536
+ let node = Arc :: new ( tokio:: sync:: Mutex :: new ( jolteon_fast_qs:: JolteonNode :: new (
536
537
node_id,
537
538
config,
538
539
next_txn,
@@ -544,10 +545,10 @@ async fn test_jolteon_with_fast_qs(
544
545
batch_commit_time : batch_commit_time_sender,
545
546
// indirectly_committed_slots: indirectly_committed_slots_sender,
546
547
} ,
547
- ) ) ;
548
+ ) ) ) ;
548
549
549
550
semaphore. add_permits ( 1 ) ;
550
- Protocol :: run ( & node, node_id, network_service, timer) . await
551
+ Protocol :: run ( node, node_id, network_service, timer) . await
551
552
} ) ) ;
552
553
}
553
554
@@ -612,7 +613,7 @@ async fn test_jolteon_with_fast_qs(
612
613
}
613
614
614
615
async fn test_raikou (
615
- delay_function : impl DelayFunction < raikou :: Message > ,
616
+ delay_function : impl DelayFunction + Clone ,
616
617
n_nodes : usize ,
617
618
delta : f64 ,
618
619
spawn_period_in_delta : u32 ,
@@ -631,6 +632,8 @@ async fn test_raikou(
631
632
rand_distr:: Uniform :: new ( 1. * delta, spawn_period_in_delta as f64 * delta) ;
632
633
let clock_speed_distr = rand_distr:: Normal :: new ( 1. , 0.01 ) . unwrap ( ) ;
633
634
635
+ let mut diss_network =
636
+ InjectedLocalNetwork :: new ( n_nodes, network_injection ( delay_function. clone ( ) ) ) ;
634
637
let mut network = InjectedLocalNetwork :: new ( n_nodes, network_injection ( delay_function) ) ;
635
638
636
639
let f = ( n_nodes - 1 ) / 3 ;
@@ -663,15 +666,14 @@ async fn test_raikou(
663
666
let start_time = Instant :: now ( ) ;
664
667
for node_id in 0 ..n_nodes {
665
668
let config = config. clone ( ) ;
669
+ let diss_network_service = diss_network. service ( node_id) ;
666
670
let network_service = network. service ( node_id) ;
667
671
668
672
let clock_speed = { thread_rng ( ) . sample ( clock_speed_distr) } ;
669
- let timer = InjectedTimerService :: local ( move |duration, event| {
670
- (
671
- Duration :: from_secs_f64 ( duration. as_secs_f64 ( ) / clock_speed) ,
672
- event,
673
- )
674
- } ) ;
673
+
674
+ // introduce artificial clock skew.
675
+ let diss_timer = InjectedTimerService :: local ( clock_skew_injection ( clock_speed) ) ;
676
+ let timer = InjectedTimerService :: local ( clock_skew_injection ( clock_speed) ) ;
675
677
676
678
// let propose_time_sender = Some(propose_time.new_sender());
677
679
// let enter_time_sender = if node_id == monitored_node {
@@ -698,10 +700,23 @@ async fn test_raikou(
698
700
// // Before starting the node, "drop" all messages sent to it during the spawn delay.
699
701
// network_service.clear_inbox().await;
700
702
703
+ let txns_iter = iter:: repeat_with ( || vec ! [ ] ) ;
704
+
705
+ let dissemination = FakeDisseminationLayer :: new (
706
+ node_id,
707
+ dissemination:: fake:: Config {
708
+ n_nodes,
709
+ ac_quorum : 2 * f + 1 ,
710
+ batch_interval : Duration :: from_secs_f64 ( delta * 0.1 ) ,
711
+ } ,
712
+ txns_iter,
713
+ ) ;
714
+
701
715
// println!("Spawning node {node_id}");
702
- let node = tokio:: sync:: Mutex :: new ( raikou:: RaikouNode :: new (
716
+ let node = Arc :: new ( tokio:: sync:: Mutex :: new ( raikou:: RaikouNode :: new (
703
717
node_id,
704
718
config,
719
+ dissemination. clone ( ) ,
705
720
start_time,
706
721
node_id == monitored_node,
707
722
raikou:: Metrics {
@@ -710,10 +725,17 @@ async fn test_raikou(
710
725
batch_commit_time : batch_commit_time_sender,
711
726
// indirectly_committed_slots: indirectly_committed_slots_sender,
712
727
} ,
728
+ ) ) ) ;
729
+
730
+ spawn ( Protocol :: run (
731
+ dissemination. protocol ( ) ,
732
+ node_id,
733
+ diss_network_service,
734
+ diss_timer,
713
735
) ) ;
736
+ spawn ( Protocol :: run ( node, node_id, network_service, timer) ) ;
714
737
715
738
semaphore. add_permits ( 1 ) ;
716
- Protocol :: run ( & node, node_id, network_service, timer) . await
717
739
} ) ) ;
718
740
}
719
741
0 commit comments