@@ -14,7 +14,7 @@ use alloy::{
14
14
providers:: Provider ,
15
15
} ;
16
16
use chrono:: { DateTime , Utc } ;
17
- use eyre:: Report ;
17
+ use eyre:: { Context , bail } ;
18
18
use init4_bin_base:: {
19
19
deps:: tracing:: { debug, error, info, warn} ,
20
20
utils:: calc:: SlotCalculator ,
@@ -28,7 +28,6 @@ use std::{
28
28
} ,
29
29
time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ,
30
30
} ;
31
- use thiserror:: Error ;
32
31
use tokio:: {
33
32
select,
34
33
sync:: mpsc:: { self } ,
@@ -46,14 +45,6 @@ use trevm::{
46
45
} ,
47
46
} ;
48
47
49
- /// Different error types that the Simulator handles
50
- #[ derive( Debug , Error ) ]
51
- pub enum SimulatorError {
52
- /// Wraps errors encountered when interacting with the RPC
53
- #[ error( "RPC error: {0}" ) ]
54
- Rpc ( #[ source] Report ) ,
55
- }
56
-
57
48
/// `Simulator` is responsible for periodically building blocks and submitting them for
58
49
/// signing and inclusion in the blockchain. It wraps a rollup provider and a slot
59
50
/// calculator with a builder configuration.
@@ -106,7 +97,7 @@ impl Simulator {
106
97
sim_items : SimCache ,
107
98
finish_by : Instant ,
108
99
block : PecorinoBlockEnv ,
109
- ) -> Result < BuiltBlock , SimulatorError > {
100
+ ) -> eyre :: Result < BuiltBlock > {
110
101
let db = self . create_db ( ) . await . unwrap ( ) ;
111
102
112
103
let block_build: BlockBuild < _ , NoOpInspector > = BlockBuild :: new (
@@ -335,7 +326,7 @@ impl Simulator {
335
326
/// # Arguments
336
327
///
337
328
/// - finish_by: The deadline at which block simulation will end.
338
- async fn next_block_env ( & self , finish_by : Instant ) -> Result < PecorinoBlockEnv , SimulatorError > {
329
+ async fn next_block_env ( & self , finish_by : Instant ) -> eyre :: Result < PecorinoBlockEnv > {
339
330
let remaining = finish_by. duration_since ( Instant :: now ( ) ) ;
340
331
let finish_time = SystemTime :: now ( ) + remaining;
341
332
let deadline: DateTime < Utc > = finish_time. into ( ) ;
@@ -345,8 +336,8 @@ impl Simulator {
345
336
let latest_block_number = match self . ru_provider . get_block_number ( ) . await {
346
337
Ok ( num) => num,
347
338
Err ( err) => {
348
- error ! ( error = %err, "RPC error during block build" ) ;
349
- return Err ( SimulatorError :: Rpc ( Report :: new ( err) ) ) ;
339
+ error ! ( %err, "RPC error during block build" ) ;
340
+ bail ! ( err)
350
341
}
351
342
} ;
352
343
debug ! ( next_block_num = latest_block_number + 1 , "preparing block env" ) ;
@@ -379,17 +370,15 @@ impl Simulator {
379
370
///
380
371
/// The basefee of the previous (latest) block if the request was successful,
381
372
/// or a sane default if the RPC failed.
382
- async fn get_basefee ( & self ) -> Result < Option < u64 > , SimulatorError > {
383
- match self . ru_provider . get_block_by_number ( Latest ) . await {
384
- Ok ( maybe_block) => match maybe_block {
385
- Some ( block) => {
386
- debug ! ( basefee = ?block. header. base_fee_per_gas, "basefee found" ) ;
387
- Ok ( block. header . base_fee_per_gas )
388
- }
389
- None => Ok ( None ) ,
390
- } ,
391
- Err ( err) => Err ( SimulatorError :: Rpc ( err. into ( ) ) ) ,
392
- }
373
+ async fn get_basefee ( & self ) -> eyre:: Result < Option < u64 > > {
374
+ let Some ( block) =
375
+ self . ru_provider . get_block_by_number ( Latest ) . await . wrap_err ( "basefee error" ) ?
376
+ else {
377
+ return Ok ( None ) ;
378
+ } ;
379
+
380
+ debug ! ( basefee = ?block. header. base_fee_per_gas, "basefee found" ) ;
381
+ Ok ( block. header . base_fee_per_gas )
393
382
}
394
383
}
395
384
0 commit comments