Skip to content

Commit

Permalink
fix: placeholder block hash when in forked mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Jan 11, 2025
1 parent ccf38a6 commit 775ddf1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions crates/katana/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::sync::Arc;
use gas_oracle::L1GasOracle;
use katana_executor::{ExecutionOutput, ExecutionResult, ExecutorFactory};
use katana_primitives::block::{
BlockNumber, FinalityStatus, Header, PartialHeader, SealedBlock, SealedBlockWithStatus,
BlockHash, BlockNumber, FinalityStatus, Header, PartialHeader, SealedBlock,
SealedBlockWithStatus,
};
use katana_primitives::chain_spec::ChainSpec;
use katana_primitives::da::L1DataAvailabilityMode;
Expand Down Expand Up @@ -110,11 +111,16 @@ impl<EF: ExecutorFactory> Backend<EF> {

if block_number >= STORED_BLOCK_HASH_BUFFER {
let block_number = block_number - STORED_BLOCK_HASH_BUFFER;
let block_hash = self
.blockchain
.provider()
.block_hash_by_num(block_number)?
.expect("qed; missing block hash");
let block_hash = self.blockchain.provider().block_hash_by_num(block_number)?;

// When in forked mode, we might not have the older block hash in the database. This
// could be the case where the `block_number - STORED_BLOCK_HASH_BUFFER` is
// earlier than the forked block, which right now, Katana doesn't
// yet have the ability to fetch older blocks on the database level. So, we default to
// `BlockHash::ZERO` in this case.
//
// TODO: Fix quick!
let block_hash = block_hash.unwrap_or(BlockHash::ZERO);

let storages = state_updates.storage_updates.entry(address!("0x1")).or_default();
storages.insert(block_number.into(), block_hash);
Expand Down

0 comments on commit 775ddf1

Please sign in to comment.