Skip to content

Commit

Permalink
feat(papyrus_storage): add sierra version to papyrus cache
Browse files Browse the repository at this point in the history
  • Loading branch information
AvivYossef-starkware committed Dec 15, 2024
1 parent 925eedd commit 0646db2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub enum RunnableCompiledClass {
}

/// Represents a runnable compiled class for Cairo, with the Sierra version (for Cairo 1).
#[derive(Clone)]
pub enum VersionedRunnableCompiledClass {
Cairo0(RunnableCompiledClass),
Cairo1((RunnableCompiledClass, SierraVersion)),
Expand Down
4 changes: 2 additions & 2 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use blockifier::blockifier::transaction_executor::{TransactionExecutor, Transact
use blockifier::bouncer::BouncerConfig;
use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses};
use blockifier::execution::call_info::CallInfo;
use blockifier::execution::contract_class::RunnableCompiledClass;
use blockifier::execution::contract_class::VersionedRunnableCompiledClass;
use blockifier::fee::receipt::TransactionReceipt;
use blockifier::state::global_cache::GlobalContractCache;
use blockifier::transaction::objects::{ExecutionResourcesTraits, TransactionExecutionInfo};
Expand Down Expand Up @@ -138,7 +138,7 @@ pub struct PyBlockExecutor {
/// `Send` trait is required for `pyclass` compatibility as Python objects must be threadsafe.
pub storage: Box<dyn Storage + Send>,
pub contract_class_manager_config: ContractClassManagerConfig,
pub global_contract_cache: GlobalContractCache<RunnableCompiledClass>,
pub global_contract_cache: GlobalContractCache<VersionedRunnableCompiledClass>,
}

#[pymethods]
Expand Down
18 changes: 9 additions & 9 deletions crates/papyrus_state_reader/src/papyrus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ type RawPapyrusReader<'env> = papyrus_storage::StorageTxn<'env, RO>;
pub struct PapyrusReader {
storage_reader: StorageReader,
latest_block: BlockNumber,
global_class_hash_to_class: GlobalContractCache<RunnableCompiledClass>,
global_class_hash_to_class: GlobalContractCache<VersionedRunnableCompiledClass>,
}

impl PapyrusReader {
pub fn new(
storage_reader: StorageReader,
latest_block: BlockNumber,
global_class_hash_to_class: GlobalContractCache<RunnableCompiledClass>,
global_class_hash_to_class: GlobalContractCache<VersionedRunnableCompiledClass>,
) -> Self {
Self { storage_reader, latest_block, global_class_hash_to_class }
}
Expand Down Expand Up @@ -132,16 +132,16 @@ impl StateReader for PapyrusReader {

fn get_compiled_class(&self, class_hash: ClassHash) -> StateResult<RunnableCompiledClass> {
// Assumption: the global cache is cleared upon reverted blocks.
let contract_class = self.global_class_hash_to_class.get(&class_hash);
let versioned_contract_class = self.global_class_hash_to_class.get(&class_hash);

match contract_class {
Some(contract_class) => Ok(contract_class),
match versioned_contract_class {
Some(contract_class) => Ok(RunnableCompiledClass::from(contract_class)),
None => {
let contract_class_from_db =
RunnableCompiledClass::from(self.get_compiled_class_inner(class_hash)?);
let versioned_contract_class_from_db = self.get_compiled_class_inner(class_hash)?;
// The class was declared in a previous (finalized) state; update the global cache.
self.global_class_hash_to_class.set(class_hash, contract_class_from_db.clone());
Ok(contract_class_from_db)
self.global_class_hash_to_class
.set(class_hash, versioned_contract_class_from_db.clone());
Ok(RunnableCompiledClass::from(versioned_contract_class_from_db))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/starknet_batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use blockifier::blockifier::transaction_executor::{
};
use blockifier::bouncer::{BouncerConfig, BouncerWeights};
use blockifier::context::{BlockContext, ChainInfo};
use blockifier::execution::contract_class::RunnableCompiledClass;
use blockifier::execution::contract_class::VersionedRunnableCompiledClass;
use blockifier::state::cached_state::CommitmentStateDiff;
use blockifier::state::errors::StateError;
use blockifier::state::global_cache::GlobalContractCache;
Expand Down Expand Up @@ -277,7 +277,7 @@ impl SerializeConfig for BlockBuilderConfig {
pub struct BlockBuilderFactory {
pub block_builder_config: BlockBuilderConfig,
pub storage_reader: StorageReader,
pub global_class_hash_to_class: GlobalContractCache<RunnableCompiledClass>,
pub global_class_hash_to_class: GlobalContractCache<VersionedRunnableCompiledClass>,
}

impl BlockBuilderFactory {
Expand Down

0 comments on commit 0646db2

Please sign in to comment.