Skip to content

Commit

Permalink
Restore non-optimized blockhash fetching path for non-taiko networks
Browse files Browse the repository at this point in the history
  • Loading branch information
Brechtpd committed Apr 10, 2024
1 parent 9f66fba commit 27bf1c3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions host/src/preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 33 additions & 9 deletions host/src/provider_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -31,16 +34,18 @@ 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,
async_executor: Handle,
}

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(),
Expand Down Expand Up @@ -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<Bytecode, Self::Error> {
Expand Down

0 comments on commit 27bf1c3

Please sign in to comment.