Skip to content

Commit eb33cb3

Browse files
committed
refactor: delete sim error
1 parent 710eacb commit eb33cb3

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

src/tasks/block.rs

+14-25
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use alloy::{
1414
providers::Provider,
1515
};
1616
use chrono::{DateTime, Utc};
17-
use eyre::Report;
17+
use eyre::{Context, bail};
1818
use init4_bin_base::{
1919
deps::tracing::{debug, error, info, warn},
2020
utils::calc::SlotCalculator,
@@ -28,7 +28,6 @@ use std::{
2828
},
2929
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
3030
};
31-
use thiserror::Error;
3231
use tokio::{
3332
select,
3433
sync::mpsc::{self},
@@ -46,14 +45,6 @@ use trevm::{
4645
},
4746
};
4847

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-
5748
/// `Simulator` is responsible for periodically building blocks and submitting them for
5849
/// signing and inclusion in the blockchain. It wraps a rollup provider and a slot
5950
/// calculator with a builder configuration.
@@ -106,7 +97,7 @@ impl Simulator {
10697
sim_items: SimCache,
10798
finish_by: Instant,
10899
block: PecorinoBlockEnv,
109-
) -> Result<BuiltBlock, SimulatorError> {
100+
) -> eyre::Result<BuiltBlock> {
110101
let db = self.create_db().await.unwrap();
111102

112103
let block_build: BlockBuild<_, NoOpInspector> = BlockBuild::new(
@@ -335,7 +326,7 @@ impl Simulator {
335326
/// # Arguments
336327
///
337328
/// - 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> {
339330
let remaining = finish_by.duration_since(Instant::now());
340331
let finish_time = SystemTime::now() + remaining;
341332
let deadline: DateTime<Utc> = finish_time.into();
@@ -345,8 +336,8 @@ impl Simulator {
345336
let latest_block_number = match self.ru_provider.get_block_number().await {
346337
Ok(num) => num,
347338
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)
350341
}
351342
};
352343
debug!(next_block_num = latest_block_number + 1, "preparing block env");
@@ -379,17 +370,15 @@ impl Simulator {
379370
///
380371
/// The basefee of the previous (latest) block if the request was successful,
381372
/// 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)
393382
}
394383
}
395384

0 commit comments

Comments
 (0)