Skip to content

Commit

Permalink
chore(blockifier_reexecution): implement get_old_block_hash_and_numbe…
Browse files Browse the repository at this point in the history
…r for offline state reader
  • Loading branch information
aner-starkware committed Nov 6, 2024
1 parent 2c95d3b commit 2070e7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions crates/blockifier_reexecution/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use blockifier::abi::constants;
use blockifier_reexecution::assert_eq_state_diff;
use blockifier_reexecution::state_reader::reexecution_state_reader::ReexecutionStateReader;
use blockifier_reexecution::state_reader::test_state_reader::{
Expand Down Expand Up @@ -114,6 +115,13 @@ fn main() {

let block_info_next_block = next_block_state_reader.get_block_info().unwrap();

let old_block_number = BlockNumber(
block_info_next_block.block_number.0 - constants::STORED_BLOCK_HASH_BUFFER,
);

let old_block_hash =
last_block_state_reader.get_old_block_hash(old_block_number).unwrap();

let starknet_version = next_block_state_reader.get_starknet_version().unwrap();

let state_diff_next_block = next_block_state_reader.get_state_diff().unwrap();
Expand Down Expand Up @@ -146,6 +154,7 @@ fn main() {
transactions_next_block,
contract_class_mapping,
state_diff_next_block,
old_block_hash,
};

serializable_offline_reexecution_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub struct SerializableOfflineReexecutionData {
pub transactions_next_block: Vec<(Transaction, TransactionHash)>,
pub state_diff_next_block: CommitmentStateDiff,
pub contract_class_mapping: StarknetContractClassMapping,
pub old_block_hash: BlockHash,
}

impl SerializableOfflineReexecutionData {
Expand All @@ -97,6 +98,7 @@ impl From<SerializableOfflineReexecutionData> for OfflineReexecutionData {
let offline_state_reader_prev_block = OfflineStateReader {
state_maps: value.state_maps.try_into().expect("Failed to deserialize state maps."),
contract_class_mapping: value.contract_class_mapping,
old_block_hash: value.old_block_hash,
};
let transactions_next_block = offline_state_reader_prev_block
.api_txs_to_blockifier_txs_next_block(value.transactions_next_block)
Expand Down Expand Up @@ -466,6 +468,7 @@ impl ConsecutiveStateReaders<TestStateReader> for ConsecutiveTestStateReaders {
pub struct OfflineStateReader {
pub state_maps: StateMaps,
pub contract_class_mapping: StarknetContractClassMapping,
pub old_block_hash: BlockHash,
}

impl StateReader for OfflineStateReader {
Expand Down Expand Up @@ -531,7 +534,7 @@ impl ReexecutionStateReader for OfflineStateReader {
}

fn get_old_block_hash(&self, _old_block_number: BlockNumber) -> ReexecutionResult<BlockHash> {
todo!()
Ok(self.old_block_hash)
}
}

Expand Down

0 comments on commit 2070e7b

Please sign in to comment.