Skip to content

Commit 88df009

Browse files
committed
hotfix(provider): historical state update not being fetched correctly from forked provider
1 parent 0506350 commit 88df009

File tree

1 file changed

+15
-2
lines changed
  • crates/storage/provider/provider/src/providers/fork

1 file changed

+15
-2
lines changed

crates/storage/provider/provider/src/providers/fork/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use katana_provider_api::transaction::{
2828
};
2929
use katana_provider_api::ProviderError;
3030
use katana_rpc_types::{GetBlockWithReceiptsResponse, RpcTxWithReceipt, StateUpdate};
31+
use tracing::trace;
3132

3233
use super::db::{self, DbProvider};
3334
use crate::{DbProviderFactory, MutableProvider, ProviderFactory, ProviderResult};
@@ -68,6 +69,8 @@ impl ForkedDb {
6869

6970
/// Fetches historical blocks before the fork point.
7071
fn fetch_historical_blocks(&self, block_id: BlockHashOrNumber) -> ProviderResult<bool> {
72+
trace!(%block_id, "Fetching historical block from the forked network");
73+
7174
let block = match block_id {
7275
BlockHashOrNumber::Num(number) => {
7376
if !self.should_fetch_externally(number) {
@@ -353,8 +356,18 @@ impl<Tx1: DbTx> BlockStatusProvider for ForkedProvider<Tx1> {
353356

354357
impl<Tx1: DbTx> StateUpdateProvider for ForkedProvider<Tx1> {
355358
fn state_update(&self, block_id: BlockHashOrNumber) -> ProviderResult<Option<StateUpdates>> {
356-
if let Some(value) = self.local_db.state_update(block_id)? {
357-
return Ok(Some(value));
359+
// hotfix: because of how `self.local_db.state_update` is implemented (ie the tables may or
360+
// may not have the values):
361+
//
362+
// `if let Some(value) = self.local_db.state_update(block_id)?` will always return Some even
363+
// for fork block.
364+
//
365+
// it's because of the call to `let block_num = self.block_number_by_id(block_id)?;` inside
366+
// of it.
367+
if self.local_db.header(block_id)?.is_some() {
368+
if let Some(value) = self.local_db.state_update(block_id)? {
369+
return Ok(Some(value));
370+
}
358371
}
359372

360373
if let Some(value) = self.fork_db.db.provider().state_update(block_id)? {

0 commit comments

Comments
 (0)