Skip to content

Commit 29c4a84

Browse files
starknet_os_runner: aviv refactor the rpc state reader to compute the compiled class hash
1 parent 6b263bc commit 29c4a84

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

crates/blockifier_reexecution/src/state_reader/rpc_state_reader.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use blockifier::state::state_reader_and_contract_manager::{
2626
FetchCompiledClasses,
2727
StateReaderAndContractManager,
2828
};
29+
use blockifier::state::utils::get_compiled_class_hash_v2 as default_get_compiled_class_hash_v2;
2930
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction;
3031
use serde::Serialize;
3132
use serde_json::{json, Value};
@@ -54,7 +55,6 @@ use crate::state_reader::offline_state_reader::{
5455
use crate::state_reader::reexecution_state_reader::{
5556
ConsecutiveReexecutionStateReaders,
5657
ReexecutionStateReader,
57-
DUMMY_COMPILED_CLASS_HASH,
5858
};
5959
use crate::utils::{
6060
disjoint_hashmap_union,
@@ -156,23 +156,18 @@ impl StateReader for RpcStateReader {
156156
}
157157
}
158158

159-
/// Returns a dummy compiled class hash for reexecution purposes.
160-
///
161-
/// This method is required since v0.14.1 for checking if compiled class hashes
162-
/// need to be migrated from v1 to v2 format.
163-
/// In reexecution we use a dummy value for both get_compiled_class_hash and
164-
/// get_compiled_class_hash_v2, to avoid the migration process.
165159
fn get_compiled_class_hash(&self, _class_hash: ClassHash) -> StateResult<CompiledClassHash> {
166-
Ok(DUMMY_COMPILED_CLASS_HASH)
160+
unimplemented!("The rpc state reader does not support get_compiled_class_hash.")
167161
}
168162

169-
/// returns the same value as get_compiled_class_hash, to avoid the migration process.
163+
/// Use the default implementation of get_compiled_class_hash_v2.
164+
/// Which compute the hash.
170165
fn get_compiled_class_hash_v2(
171166
&self,
172167
class_hash: ClassHash,
173-
_compiled_class: &RunnableCompiledClass,
168+
compiled_class: &RunnableCompiledClass,
174169
) -> StateResult<CompiledClassHash> {
175-
self.get_compiled_class_hash(class_hash)
170+
default_get_compiled_class_hash_v2(self, class_hash, compiled_class)
176171
}
177172
}
178173

@@ -291,15 +286,19 @@ impl RpcStateReader {
291286
.collect::<Result<_, _>>()
292287
}
293288

294-
pub fn get_versioned_constants(&self) -> ReexecutionResult<&'static VersionedConstants> {
295-
Ok(VersionedConstants::get(&self.get_starknet_version()?)?)
289+
pub fn get_versioned_constants(&self) -> ReexecutionResult<VersionedConstants> {
290+
let mut vc = VersionedConstants::get(&self.get_starknet_version()?)?.clone();
291+
// The rpc state reader does not support casm hash migration, which requires compiled class
292+
// hashes. .
293+
vc.enable_casm_hash_migration = false;
294+
Ok(vc)
296295
}
297296

298297
pub fn get_block_context(&self) -> ReexecutionResult<BlockContext> {
299298
Ok(BlockContext::new(
300299
self.get_block_info()?,
301300
get_chain_info(&self.chain_id),
302-
self.get_versioned_constants()?.clone(),
301+
self.get_versioned_constants()?,
303302
BouncerConfig::max(),
304303
))
305304
}
@@ -330,6 +329,8 @@ impl RpcStateReader {
330329
)?)
331330
}
332331

332+
/// Get the commitment state diff of the current block.
333+
/// Notice: we ignore migrated_compiled_classes.
333334
pub fn get_state_diff(&self) -> ReexecutionResult<CommitmentStateDiff> {
334335
let raw_statediff =
335336
&retry_request!(self.retry_config, || self.rpc_state_reader.send_rpc_request(

0 commit comments

Comments
 (0)