Skip to content

Commit

Permalink
chore(blockifier): add sierra to storage w append_block
Browse files Browse the repository at this point in the history
  • Loading branch information
avivg-starkware committed Nov 6, 2024
1 parent e7becf2 commit 1f1d1c4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl PyBlockExecutor {
previous_block_id: Option<PyFelt>,
py_block_info: PyBlockInfo,
py_state_diff: PyStateDiff,
declared_class_hash_to_class: HashMap<PyFelt, (PyFelt, String)>,
declared_class_hash_to_class: HashMap<PyFelt, (String, (PyFelt, String))>,
deprecated_declared_class_hash_to_class: HashMap<PyFelt, String>,
) -> NativeBlockifierResult<()> {
self.storage.append_block(
Expand Down
7 changes: 6 additions & 1 deletion crates/native_blockifier/src/py_block_executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cached::Cached;
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use pretty_assertions::assert_eq;
use starknet_api::class_hash;
use starknet_api::state::ContractClass;
use starknet_types_core::felt::Felt;

use crate::py_block_executor::{PyBlockExecutor, PyOsConfig};
Expand All @@ -19,6 +20,7 @@ use crate::test_utils::MockStorage;
fn global_contract_cache_update() {
// Initialize executor and set a contract class on the state.
let casm = CasmContractClass { compiler_version: "0.1.0".to_string(), ..Default::default() };
let sierra = ContractClass::default();
let contract_class =
RunnableContractClass::V1(ContractClassV1::try_from(casm.clone()).unwrap());
let class_hash = class_hash!("0x1");
Expand All @@ -38,7 +40,10 @@ fn global_contract_cache_update() {
PyStateDiff::default(),
HashMap::from([(
class_hash.into(),
(PyFelt::from(1_u8), serde_json::to_string(&casm).unwrap()),
(
serde_json::to_string(&sierra).unwrap(),
(PyFelt::from(1_u8), serde_json::to_string(&casm).unwrap()),
),
)]),
HashMap::default(),
)
Expand Down
15 changes: 9 additions & 6 deletions crates/native_blockifier/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Storage for PapyrusStorage {
previous_block_id: Option<PyFelt>,
py_block_info: PyBlockInfo,
py_state_diff: PyStateDiff,
declared_class_hash_to_class: HashMap<PyFelt, (PyFelt, String)>,
declared_class_hash_to_class: HashMap<PyFelt, (String, (PyFelt, String))>,
deprecated_declared_class_hash_to_class: HashMap<PyFelt, String>,
) -> NativeBlockifierResult<()> {
log::debug!(
Expand Down Expand Up @@ -167,7 +167,9 @@ impl Storage for PapyrusStorage {

let mut declared_classes = IndexMap::<ClassHash, (CompiledClassHash, ContractClass)>::new();
let mut undeclared_casm_contracts = Vec::<(ClassHash, CasmContractClass)>::new();
for (class_hash, (compiled_class_hash, raw_class)) in declared_class_hash_to_class {
for (class_hash, (raw_sierra, (compiled_class_hash, raw_casm))) in
declared_class_hash_to_class
{
let class_hash = ClassHash(class_hash.0);
let class_undeclared = self
.reader()
Expand All @@ -177,12 +179,13 @@ impl Storage for PapyrusStorage {
.is_none();

if class_undeclared {
let sierra_contract_class: ContractClass = serde_json::from_str(&raw_sierra)?;
declared_classes.insert(
class_hash,
(CompiledClassHash(compiled_class_hash.0), ContractClass::default()),
(CompiledClassHash(compiled_class_hash.0), sierra_contract_class),
);
let contract_class: CasmContractClass = serde_json::from_str(&raw_class)?;
undeclared_casm_contracts.push((class_hash, contract_class));
let casm_contract_class: CasmContractClass = serde_json::from_str(&raw_casm)?;
undeclared_casm_contracts.push((class_hash, casm_contract_class));
}
}

Expand Down Expand Up @@ -295,7 +298,7 @@ pub trait Storage {
previous_block_id: Option<PyFelt>,
py_block_info: PyBlockInfo,
py_state_diff: PyStateDiff,
declared_class_hash_to_class: HashMap<PyFelt, (PyFelt, String)>,
declared_class_hash_to_class: HashMap<PyFelt, (String, (PyFelt, String))>,
deprecated_declared_class_hash_to_class: HashMap<PyFelt, String>,
) -> NativeBlockifierResult<()>;

Expand Down
2 changes: 1 addition & 1 deletion crates/native_blockifier/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Storage for MockStorage {
_py_state_diff: crate::py_state_diff::PyStateDiff,
_declared_class_hash_to_class: HashMap<
crate::py_utils::PyFelt,
(crate::py_utils::PyFelt, String),
(String, (crate::py_utils::PyFelt, String)),
>,
_deprecated_declared_class_hash_to_class: HashMap<crate::py_utils::PyFelt, String>,
) -> NativeBlockifierResult<()> {
Expand Down

0 comments on commit 1f1d1c4

Please sign in to comment.