File tree Expand file tree Collapse file tree 2 files changed +67
-1
lines changed Expand file tree Collapse file tree 2 files changed +67
-1
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ use std::net::TcpListener;
28
28
use std:: path:: PathBuf ;
29
29
use std:: str:: FromStr ;
30
30
use std:: sync:: { Arc , LazyLock } ;
31
- use std:: time:: SystemTime ;
31
+ use std:: time:: { Duration , SystemTime } ;
32
32
use std:: { fs:: File , io:: BufReader , time:: UNIX_EPOCH } ;
33
33
use testcontainers:: core:: ContainerPort ;
34
34
use testcontainers:: core:: client:: docker_client_instance;
@@ -385,6 +385,7 @@ pub struct SimpleBlockGenerator {
385
385
timestamp : u64 ,
386
386
genesis : Genesis ,
387
387
current_block_number : u64 ,
388
+ block_time : Duration ,
388
389
}
389
390
390
391
impl SimpleBlockGenerator {
@@ -400,9 +401,14 @@ impl SimpleBlockGenerator {
400
401
timestamp : genesis. timestamp ,
401
402
genesis,
402
403
current_block_number : 0 ,
404
+ block_time : Duration :: from_secs ( 1 ) ,
403
405
}
404
406
}
405
407
408
+ pub fn set_block_time ( & mut self , block_time : Duration ) {
409
+ self . block_time = block_time;
410
+ }
411
+
406
412
/// Initialize the block generator by fetching the latest block
407
413
pub async fn init ( & mut self ) -> eyre:: Result < ( ) > {
408
414
let latest_block = self . engine_api . latest ( ) . await ?. expect ( "block not found" ) ;
Original file line number Diff line number Diff line change
1
+ mod common;
2
+
3
+ use common:: RollupBoostTestHarnessBuilder ;
4
+ use common:: proxy:: ProxyHandler ;
5
+ use futures:: FutureExt ;
6
+ use serde_json:: Value ;
7
+ use std:: pin:: Pin ;
8
+ use std:: sync:: Arc ;
9
+ use std:: time:: Duration ;
10
+
11
+ // TODO: Use the same implementation as in builder_full_delay.rs
12
+ struct DelayHandler {
13
+ delay : Duration ,
14
+ }
15
+
16
+ impl DelayHandler {
17
+ pub fn new ( delay : Duration ) -> Self {
18
+ Self { delay }
19
+ }
20
+ }
21
+
22
+ impl ProxyHandler for DelayHandler {
23
+ fn handle (
24
+ & self ,
25
+ _method : String ,
26
+ _params : Value ,
27
+ _result : Value ,
28
+ ) -> Pin < Box < dyn Future < Output = Option < Value > > + Send > > {
29
+ let delay = self . delay ;
30
+ async move {
31
+ tokio:: time:: sleep ( delay) . await ;
32
+ None
33
+ }
34
+ . boxed ( )
35
+ }
36
+ }
37
+
38
+ #[ tokio:: test]
39
+ async fn fcu_no_block_time_delay ( ) -> eyre:: Result < ( ) > {
40
+ // This test ensures that even with delay in between RB and the external builder (50ms) the
41
+ // builder can still build the block if there is an avalanche of FCUs without block time delay
42
+ let delay = DelayHandler :: new ( Duration :: from_millis ( 50 ) ) ;
43
+
44
+ let harness = RollupBoostTestHarnessBuilder :: new ( "fcu_no_block_time_delay" )
45
+ . proxy_handler ( Arc :: new ( delay) )
46
+ . build ( )
47
+ . await ?;
48
+ let mut block_generator = harness. block_generator ( ) . await ?;
49
+ block_generator. set_block_time ( Duration :: from_millis ( 0 ) ) ;
50
+
51
+ for _ in 0 ..30 {
52
+ let ( _block, block_creator) = block_generator. generate_block ( false ) . await ?;
53
+ assert ! (
54
+ block_creator. is_builder( ) ,
55
+ "Block creator should be the builder"
56
+ ) ;
57
+ }
58
+
59
+ Ok ( ( ) )
60
+ }
You can’t perform that action at this time.
0 commit comments