Skip to content

Commit

Permalink
refactor(blockifier): use get versioned contract class in py state re…
Browse files Browse the repository at this point in the history
…ader
  • Loading branch information
AvivYossef-starkware committed Dec 15, 2024
1 parent 5a28773 commit 3a292c7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions crates/native_blockifier/src/state_readers/py_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use blockifier::execution::contract_class::{
};
use blockifier::state::errors::StateError;
use blockifier::state::state_api::{StateReader, StateResult};
use pyo3::types::PyTuple;
use pyo3::{FromPyObject, PyAny, PyErr, PyObject, PyResult, Python};
use starknet_api::contract_class::SierraVersion;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::state::StorageKey;
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -71,13 +73,23 @@ impl StateReader for PyStateReader {
fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult<RunnableCompiledClass> {
Python::with_gil(|py| -> Result<RunnableCompiledClass, PyErr> {
let args = (PyFelt::from(class_hash),);
let py_raw_compiled_class: PyRawCompiledClass = self
let py_versioned_raw_compiled_class: &PyTuple = self
.state_reader_proxy
.as_ref(py)
.call_method1("get_raw_compiled_class", args)?
.extract()?;
.call_method1("get_versioned_raw_compiled_class", args)?
.downcast()?;

Ok(RunnableCompiledClass::try_from(py_raw_compiled_class)?)
// Extract the raw compiled class
let py_raw_compiled_class: PyRawCompiledClass =
py_versioned_raw_compiled_class.get_item(0)?.extract()?;
let runnable_compiled_class = RunnableCompiledClass::try_from(py_raw_compiled_class)?;

// Extract and process the Sierra version
let (minor, major, patch): (u64, u64, u64) =
py_versioned_raw_compiled_class.get_item(1)?.extract()?;
// TODO(Aviv): Return it in the next PR after the change in the StateReader API.
let _sierra_version = SierraVersion::new(major, minor, patch);
Ok(runnable_compiled_class)
})
.map_err(|err| {
if Python::with_gil(|py| err.is_instance_of::<UndeclaredClassHashError>(py)) {
Expand Down

0 comments on commit 3a292c7

Please sign in to comment.