Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(blockifier): use get versioned contract class in py state reader #2614

Open
wants to merge 1 commit into
base: aviv/refactor_papyrus_rpc_get_contract_class
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 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,20 +73,32 @@ 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)) {
StateError::UndeclaredClassHash(class_hash)
} else {
StateError::StateReadError(err.to_string())
}
Python::with_gil(|py| {
if err.is_instance_of::<UndeclaredClassHashError>(py) {
StateError::UndeclaredClassHash(class_hash)
} else {
StateError::StateReadError(err.to_string())
}
})
})
}

Expand Down
Loading