Skip to content

Commit 81322b4

Browse files
starknet_os_runner: prev block hash
1 parent 8ef8bb3 commit 81322b4

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

crates/starknet_os_runner/src/runner.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ where
149149
tx_execution_infos,
150150
block_info: execution_data.block_context.block_info().clone(),
151151
initial_reads: execution_data.initial_reads,
152-
// TODO(Aviv): Use the actual previous block hash.
153-
prev_base_block_hash: BlockHash::default(),
152+
prev_base_block_hash: execution_data.prev_base_block_hash,
154153
compiled_classes: classes.compiled_classes,
155154
};
156155

crates/starknet_os_runner/src/storage_proofs_test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::HashSet;
33
use blockifier::context::BlockContext;
44
use blockifier::state::cached_state::StateMaps;
55
use rstest::rstest;
6-
use starknet_api::block::BlockNumber;
6+
use starknet_api::block::{BlockHash, BlockNumber};
77
use starknet_api::core::ContractAddress;
88
use starknet_api::state::StorageKey;
99
use starknet_rust::providers::Provider;
@@ -47,6 +47,7 @@ fn test_get_storage_proofs_from_rpc(
4747
block_context: BlockContext::create_for_account_testing(),
4848
initial_reads: state_maps,
4949
executed_class_hashes: HashSet::new(),
50+
prev_base_block_hash: BlockHash::default(),
5051
};
5152

5253
let result = rpc_provider.get_storage_proofs(BlockNumber(block_number), &execution_data);

crates/starknet_os_runner/src/virtual_block_executor.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use blockifier::state::state_reader_and_contract_manager::{
1414
};
1515
use blockifier::transaction::account_transaction::ExecutionFlags;
1616
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction;
17+
use blockifier_reexecution::state_reader::reexecution_state_reader::ReexecutionStateReader;
1718
use blockifier_reexecution::state_reader::rpc_state_reader::RpcStateReader;
18-
use starknet_api::block::BlockNumber;
19+
use starknet_api::block::{BlockHash, BlockNumber};
1920
use starknet_api::core::{ChainId, ClassHash};
2021
use starknet_api::transaction::fields::Fee;
2122
use starknet_api::transaction::{InvokeTransaction, Transaction, TransactionHash};
@@ -36,6 +37,8 @@ pub struct VirtualBlockExecutionData {
3637
pub initial_reads: StateMaps,
3738
/// The class hashes of all contracts executed in the virtual block.
3839
pub executed_class_hashes: HashSet<ClassHash>,
40+
/// The block hash of the state at the start of the virtual block.
41+
pub prev_base_block_hash: BlockHash,
3942
}
4043

4144
/// Executes a virtual block of transactions.
@@ -86,6 +89,7 @@ pub trait VirtualBlockExecutor {
8689
let blockifier_txs = self.convert_invoke_txs(txs)?;
8790
let block_context = self.block_context(block_number)?;
8891
let state_reader = self.state_reader(block_number)?;
92+
let prev_base_block_hash = self.prev_base_block_hash(block_number)?;
8993

9094
// Create state reader with contract manager.
9195
let state_reader_and_contract_manager =
@@ -132,6 +136,7 @@ pub trait VirtualBlockExecutor {
132136
block_context,
133137
initial_reads,
134138
executed_class_hashes,
139+
prev_base_block_hash,
135140
})
136141
}
137142

@@ -172,6 +177,12 @@ pub trait VirtualBlockExecutor {
172177
block_number: BlockNumber,
173178
) -> Result<BlockContext, VirtualBlockExecutorError>;
174179

180+
/// Returns the block hash of the state at the start of the virtual block.
181+
fn prev_base_block_hash(
182+
&self,
183+
block_number: BlockNumber,
184+
) -> Result<BlockHash, VirtualBlockExecutorError>;
185+
175186
/// Returns a state reader that implements `FetchCompiledClasses` for the given block number.
176187
/// Must be `Send + Sync + 'static` to be used in the transaction executor.
177188
fn state_reader(
@@ -219,6 +230,15 @@ impl VirtualBlockExecutor for RpcVirtualBlockExecutor {
219230
.map_err(|e| VirtualBlockExecutorError::ReexecutionError(Box::new(e)))
220231
}
221232

233+
fn prev_base_block_hash(
234+
&self,
235+
block_number: BlockNumber,
236+
) -> Result<BlockHash, VirtualBlockExecutorError> {
237+
self.rpc_state_reader
238+
.get_old_block_hash(block_number)
239+
.map_err(|e| VirtualBlockExecutorError::ReexecutionError(Box::new(e)))
240+
}
241+
222242
fn state_reader(
223243
&self,
224244
_block_number: BlockNumber,

0 commit comments

Comments
 (0)