|
1 | 1 | use super::state_reader::PathfinderStateReader; |
2 | | -use crate::state_reader::LruCachedReader; |
3 | | -use blockifier::{block_context::BlockContext, state::cached_state::CachedState}; |
| 2 | +use crate::{state_reader::LruCachedReader, IntoStarkFelt}; |
| 3 | +use anyhow::Context; |
| 4 | +use blockifier::{ |
| 5 | + block_context::BlockContext, |
| 6 | + state::{cached_state::CachedState, state_api::State}, |
| 7 | +}; |
4 | 8 | use pathfinder_common::{BlockHeader, ChainId, StateUpdate}; |
5 | 9 |
|
6 | 10 | pub struct ExecutionState<'tx> { |
@@ -33,6 +37,31 @@ impl<'tx> ExecutionState<'tx> { |
33 | 37 | ); |
34 | 38 | let mut cached_state = LruCachedReader::new_cached_state(raw_reader)?; |
35 | 39 |
|
| 40 | + // Perform system contract updates if we are executing ontop of a parent block. |
| 41 | + // Currently this is only the block hash from 10 blocks ago. |
| 42 | + if self.execute_on_parent_state && self.header.number.get() >= 10 { |
| 43 | + let block_number_whose_hash_becomes_available = |
| 44 | + pathfinder_common::BlockNumber::new_or_panic(self.header.number.get() - 10); |
| 45 | + let (_, block_hash) = self |
| 46 | + .transaction |
| 47 | + .block_id(block_number_whose_hash_becomes_available.into())? |
| 48 | + .context("Getting historical block hash")?; |
| 49 | + |
| 50 | + tracing::trace!(%block_number_whose_hash_becomes_available, %block_hash, "Setting historical block hash"); |
| 51 | + |
| 52 | + cached_state.set_storage_at( |
| 53 | + starknet_api::core::ContractAddress(starknet_api::core::PatriciaKey::try_from( |
| 54 | + starknet_api::hash::StarkFelt::from(1u8), |
| 55 | + )?), |
| 56 | + starknet_api::state::StorageKey(starknet_api::core::PatriciaKey::try_from( |
| 57 | + starknet_api::hash::StarkFelt::from( |
| 58 | + block_number_whose_hash_becomes_available.get(), |
| 59 | + ), |
| 60 | + )?), |
| 61 | + block_hash.0.into_starkfelt(), |
| 62 | + ) |
| 63 | + } |
| 64 | + |
36 | 65 | self.pending_state.as_ref().map(|pending_state| { |
37 | 66 | super::pending::apply_pending_update(&mut cached_state, pending_state) |
38 | 67 | }); |
|
0 commit comments