Skip to content

Commit b7e8194

Browse files
starknet_os_runner: aviv refactor the rpc state reader to compute the compiled class hash
1 parent 731f5de commit b7e8194

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, to_value, Value};
@@ -61,7 +62,6 @@ use crate::state_reader::offline_state_reader::{
6162
use crate::state_reader::reexecution_state_reader::{
6263
ConsecutiveReexecutionStateReaders,
6364
ReexecutionStateReader,
64-
DUMMY_COMPILED_CLASS_HASH,
6565
};
6666
use crate::utils::{
6767
disjoint_hashmap_union,
@@ -163,23 +163,18 @@ impl StateReader for RpcStateReader {
163163
}
164164
}
165165

166-
/// Returns a dummy compiled class hash for reexecution purposes.
167-
///
168-
/// This method is required since v0.14.1 for checking if compiled class hashes
169-
/// need to be migrated from v1 to v2 format.
170-
/// In reexecution we use a dummy value for both get_compiled_class_hash and
171-
/// get_compiled_class_hash_v2, to avoid the migration process.
172166
fn get_compiled_class_hash(&self, _class_hash: ClassHash) -> StateResult<CompiledClassHash> {
173-
Ok(DUMMY_COMPILED_CLASS_HASH)
167+
unimplemented!("The rpc state reader does not support get_compiled_class_hash.")
174168
}
175169

176-
/// returns the same value as get_compiled_class_hash, to avoid the migration process.
170+
/// Use the default implementation of get_compiled_class_hash_v2.
171+
/// Which compute the hash.
177172
fn get_compiled_class_hash_v2(
178173
&self,
179174
class_hash: ClassHash,
180-
_compiled_class: &RunnableCompiledClass,
175+
compiled_class: &RunnableCompiledClass,
181176
) -> StateResult<CompiledClassHash> {
182-
self.get_compiled_class_hash(class_hash)
177+
default_get_compiled_class_hash_v2(self, class_hash, compiled_class)
183178
}
184179
}
185180

@@ -309,15 +304,19 @@ impl RpcStateReader {
309304
.collect::<Result<_, _>>()
310305
}
311306

312-
pub fn get_versioned_constants(&self) -> ReexecutionResult<&'static VersionedConstants> {
313-
Ok(VersionedConstants::get(&self.get_starknet_version()?)?)
307+
pub fn get_versioned_constants(&self) -> ReexecutionResult<VersionedConstants> {
308+
let mut vc = VersionedConstants::get(&self.get_starknet_version()?)?.clone();
309+
// The rpc state reader does not support casm hash migration, which requires compiled class
310+
// hashes. .
311+
vc.enable_casm_hash_migration = false;
312+
Ok(vc)
314313
}
315314

316315
pub fn get_block_context(&self) -> ReexecutionResult<BlockContext> {
317316
Ok(BlockContext::new(
318317
self.get_block_info()?,
319318
get_chain_info(&self.chain_id),
320-
self.get_versioned_constants()?.clone(),
319+
self.get_versioned_constants()?,
321320
BouncerConfig::max(),
322321
))
323322
}
@@ -348,6 +347,8 @@ impl RpcStateReader {
348347
)?)
349348
}
350349

350+
/// Get the commitment state diff of the current block.
351+
/// Notice: we ignore migrated_compiled_classes.
351352
pub fn get_state_diff(&self) -> ReexecutionResult<CommitmentStateDiff> {
352353
let raw_statediff =
353354
&retry_request!(self.retry_config, || self.rpc_state_reader.send_rpc_request(

0 commit comments

Comments
 (0)