diff --git a/host/src/preflight.rs b/host/src/preflight.rs index 204b4836..b2090267 100644 --- a/host/src/preflight.rs +++ b/host/src/preflight.rs @@ -189,6 +189,7 @@ pub fn preflight( // Create the block builder, run the transactions and extract the DB let provider_db = ProviderDb::new( provider, + network, parent_block.header.number.unwrap().try_into().unwrap(), ); let mut builder = BlockBuilder::new(&input) diff --git a/host/src/provider_db.rs b/host/src/provider_db.rs index 183ce419..30503f91 100644 --- a/host/src/provider_db.rs +++ b/host/src/provider_db.rs @@ -19,7 +19,10 @@ use std::{ use alloy_consensus::Header as AlloyConsensusHeader; use alloy_provider::{Provider, ReqwestProvider}; use alloy_rpc_types::{BlockId, EIP1186AccountProofResponse}; -use raiko_lib::{clear_line, inplace_print, mem_db::MemDb, print_duration, taiko_utils::to_header}; +use raiko_lib::{ + clear_line, consts::Network, inplace_print, mem_db::MemDb, print_duration, + taiko_utils::to_header, +}; use raiko_primitives::{Address, B256, U256}; use revm::{ primitives::{Account, AccountInfo, Bytecode, HashMap}, @@ -31,6 +34,7 @@ use crate::preflight::{batch_get_history_headers, get_block}; pub struct ProviderDb { pub provider: ReqwestProvider, + pub network: Network, pub block_number: u64, pub initial_db: MemDb, pub current_db: MemDb, @@ -38,9 +42,10 @@ pub struct ProviderDb { } impl ProviderDb { - pub fn new(provider: ReqwestProvider, block_number: u64) -> Self { + pub fn new(provider: ReqwestProvider, network: Network, block_number: u64) -> Self { ProviderDb { provider, + network, block_number, initial_db: MemDb::default(), current_db: MemDb::default(), @@ -225,16 +230,35 @@ impl Database for ProviderDb { return Ok(block_hash); } - // Get the 256 history block hashes from the provider at first time for anchor - // transaction. let block_number = u64::try_from(number).unwrap(); - for block in batch_get_history_headers(&self.provider, &self.async_executor, block_number)? - { - let block_number = block.header.number.unwrap().try_into().unwrap(); - let block_hash = block.header.hash.unwrap(); + if self.network.is_taiko() { + // Get the 256 history block hashes from the provider at first time for anchor + // transaction. + for block in + batch_get_history_headers(&self.provider, &self.async_executor, block_number)? + { + let block_number = block.header.number.unwrap().try_into().unwrap(); + let block_hash = block.header.hash.unwrap(); + self.initial_db.insert_block_hash(block_number, block_hash); + } + self.block_hash(number) + } else { + // Get the block hash from the provider. + let block_hash = self.async_executor.block_on(async { + self.provider + .get_block_by_number(block_number.into(), false) + .await + .unwrap() + .unwrap() + .header + .hash + .unwrap() + .0 + .into() + }); self.initial_db.insert_block_hash(block_number, block_hash); + Ok(block_hash) } - self.block_hash(number) } fn code_by_hash(&mut self, _code_hash: B256) -> Result {