Skip to content

Commit db93988

Browse files
committed
chore(perf): do not request for latest block number, reuse env
1 parent 6499785 commit db93988

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/tasks/block/sim.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
config::{BuilderConfig, RuProvider},
66
tasks::env::SimEnv,
77
};
8-
use alloy::{eips::BlockId, network::Ethereum, providers::Provider};
8+
use alloy::{eips::BlockId, network::Ethereum};
99
use init4_bin_base::{
1010
deps::tracing::{debug, error},
1111
utils::calc::SlotCalculator,
@@ -102,7 +102,7 @@ impl Simulator {
102102
debug!(block_number = block_env.number, tx_count = sim_items.len(), "starting block build",);
103103
let concurrency_limit = self.config.concurrency_limit();
104104

105-
let db = self.create_db().await.unwrap();
105+
let db = self.create_db(block_env.number).unwrap();
106106

107107
let block_build: BlockBuild<_, NoOpInspector> = BlockBuild::new(
108108
db,
@@ -226,19 +226,10 @@ impl Simulator {
226226
/// # Returns
227227
///
228228
/// An `Option` containing the wrapped database or `None` if an error occurs.
229-
async fn create_db(&self) -> Option<AlloyDatabaseProvider> {
230-
// Fetch latest block number
231-
let latest = match self.ru_provider.get_block_number().await {
232-
Ok(block_number) => block_number,
233-
Err(e) => {
234-
error!(error = %e, "failed to get latest block number");
235-
return None;
236-
}
237-
};
238-
229+
fn create_db(&self, latest_block_number: u64) -> Option<AlloyDatabaseProvider> {
239230
// Make an AlloyDB instance from the rollup provider with that latest block number
240231
let alloy_db: AlloyDB<Ethereum, RuProvider> =
241-
AlloyDB::new(self.ru_provider.clone(), BlockId::from(latest));
232+
AlloyDB::new(self.ru_provider.clone(), BlockId::from(latest_block_number));
242233

243234
// Wrap the AlloyDB instance in a WrapDatabaseAsync and return it.
244235
// This is safe to unwrap because the main function sets the proper runtime settings.

src/tasks/cache/tx.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl TxPoller {
5252
.get(url)
5353
.send()
5454
.await?
55+
.error_for_status()?
5556
.json()
5657
.await
5758
.map(|resp: TxPoolResponse| resp.transactions)

0 commit comments

Comments
 (0)