Skip to content

Commit

Permalink
chore(batcher): move papyrus_state_reader to a shared crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Yael-Starkware committed Nov 11, 2024
1 parent b43abae commit b02f45b
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 207 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ members = [
"crates/papyrus_proc_macros",
"crates/papyrus_protobuf",
"crates/papyrus_rpc",
"crates/papyrus_state_reader",
"crates/papyrus_storage",
"crates/papyrus_sync",
"crates/papyrus_test_utils",
Expand Down Expand Up @@ -166,6 +167,7 @@ papyrus_p2p_sync = { path = "crates/papyrus_p2p_sync", version = "0.0.0" }
papyrus_proc_macros = { path = "crates/papyrus_proc_macros", version = "0.0.0" }
papyrus_protobuf = { path = "crates/papyrus_protobuf", version = "0.0.0" }
papyrus_rpc = { path = "crates/papyrus_rpc", version = "0.0.0" }
papyrus_state_reader = { path = "crates/papyrus_state_reader", version = "0.0.0" }
papyrus_storage = { path = "crates/papyrus_storage", version = "0.0.0" }
papyrus_sync = { path = "crates/papyrus_sync", version = "0.0.0" }
papyrus_test_utils = { path = "crates/papyrus_test_utils", version = "0.0.0" }
Expand Down
3 changes: 2 additions & 1 deletion crates/batcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ blockifier.workspace = true
chrono.workspace = true
indexmap.workspace = true
papyrus_config.workspace = true
papyrus_state_reader.workspace = true
papyrus_storage.workspace = true
serde.workspace = true
starknet-types-core.workspace = true
starknet_api.workspace = true
starknet_batcher_types.workspace = true
starknet_mempool_types.workspace = true
Expand All @@ -33,4 +33,5 @@ futures.workspace = true
mempool_test_utils.workspace = true
mockall.workspace = true
rstest.workspace = true
starknet-types-core.workspace = true
starknet_api = { workspace = true, features = ["testing"] }
2 changes: 1 addition & 1 deletion crates/batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use papyrus_config::dumping::{
SerializeConfig,
};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use papyrus_state_reader::papyrus_state::PapyrusReader;
use papyrus_storage::StorageReader;
use serde::{Deserialize, Serialize};
use starknet_api::block::{BlockHashAndNumber, BlockNumber, BlockTimestamp, NonzeroGasPrice};
Expand All @@ -38,7 +39,6 @@ use thiserror::Error;
use tokio::sync::Mutex;
use tracing::{debug, error, info, trace};

use crate::papyrus_state::PapyrusReader;
use crate::transaction_executor::TransactionExecutorTrait;
use crate::transaction_provider::{NextTxs, TransactionProvider, TransactionProviderError};

Expand Down
1 change: 0 additions & 1 deletion crates/batcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod block_builder_test;
pub mod communication;
pub mod config;
pub mod fee_market;
pub mod papyrus_state;
mod proposal_manager;
#[cfg(test)]
mod proposal_manager_test;
Expand Down
146 changes: 0 additions & 146 deletions crates/batcher/src/papyrus_state.rs

This file was deleted.

1 change: 1 addition & 0 deletions crates/native_blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cairo-vm.workspace = true
indexmap.workspace = true
log.workspace = true
num-bigint.workspace = true
papyrus_state_reader.workspace = true
papyrus_storage = { workspace = true, features = ["testing"] }
pyo3 = { workspace = true, features = ["hashbrown", "num-bigint"] }
pyo3-log.workspace = true
Expand Down
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 @@ -12,6 +12,7 @@ use blockifier::transaction::objects::{ExecutionResourcesTraits, TransactionExec
use blockifier::transaction::transaction_execution::Transaction;
use blockifier::utils::usize_from_u64;
use blockifier::versioned_constants::VersionedConstants;
use papyrus_state_reader::papyrus_state::PapyrusReader;
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyList};
use pyo3::{FromPyObject, PyAny, Python};
Expand All @@ -27,7 +28,6 @@ use crate::py_objects::{PyBouncerConfig, PyConcurrencyConfig, PyVersionedConstan
use crate::py_state_diff::{PyBlockInfo, PyStateDiff};
use crate::py_transaction::{py_tx, PyClassInfo, PY_TX_PARSING_ERR};
use crate::py_utils::{int_to_chain_id, into_block_number_hash_pair, PyFelt};
use crate::state_readers::papyrus_state::PapyrusReader;
use crate::storage::{PapyrusStorage, Storage, StorageConfig};

pub(crate) type RawTransactionExecutionResult = Vec<u8>;
Expand Down
48 changes: 48 additions & 0 deletions 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::deprecated_contract_class::ContractClass as DeprecatedContractClass;
use starknet_types_core::felt::Felt;

use crate::py_block_executor::{PyBlockExecutor, PyOsConfig};
Expand All @@ -15,6 +16,8 @@ use crate::py_state_diff::{PyBlockInfo, PyStateDiff};
use crate::py_utils::PyFelt;
use crate::test_utils::MockStorage;

const LARGE_COMPILED_CONTRACT_JSON: &str = include_str!("resources/large_compiled_contract.json");

#[test]
fn global_contract_cache_update() {
// Initialize executor and set a contract class on the state.
Expand Down Expand Up @@ -92,3 +95,48 @@ fn get_block_id() {
expected_max_class_hash_as_py_felt
);
}

#[test]
/// Edge case: adding a large contract to the global contract cache.
fn global_contract_cache_update_large_contract() {
let mut raw_contract_class: serde_json::Value =
serde_json::from_str(LARGE_COMPILED_CONTRACT_JSON).unwrap();

// ABI is not required for execution.
raw_contract_class
.as_object_mut()
.expect("A compiled contract must be a JSON object.")
.remove("abi");

let dep_casm: DeprecatedContractClass = serde_json::from_value(raw_contract_class)
.expect("DeprecatedContractClass is not supported for this contract.");

let temp_storage_path = tempfile::tempdir().unwrap().into_path();
let mut block_executor = PyBlockExecutor::native_create_for_testing(
Default::default(),
Default::default(),
temp_storage_path,
4000,
);
block_executor
.append_block(
0,
None,
Default::default(),
Default::default(),
Default::default(),
HashMap::from([(PyFelt::from(1_u8), serde_json::to_string(&dep_casm).unwrap())]),
)
.unwrap();

block_executor
.append_block(
1,
Some(PyFelt(Felt::ZERO)),
PyBlockInfo { block_number: 1, ..PyBlockInfo::default() },
Default::default(),
Default::default(),
HashMap::from([(PyFelt::from(1_u8), serde_json::to_string(&dep_casm).unwrap())]),
)
.unwrap();
}
1 change: 0 additions & 1 deletion crates/native_blockifier/src/state_readers.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod papyrus_state;
pub mod py_state_reader;
18 changes: 18 additions & 0 deletions crates/papyrus_state_reader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "papyrus_state_reader"
version.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true

[lints]
workspace = true

[dependencies]
blockifier.workspace = true
papyrus_storage.workspace = true
starknet-types-core.workspace = true
starknet_api.workspace = true

[dev-dependencies]
indexmap.workspace = true
1 change: 1 addition & 0 deletions crates/papyrus_state_reader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod papyrus_state;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use starknet_types_core::felt::Felt;
mod test;

type RawPapyrusReader<'env> = papyrus_storage::StorageTxn<'env, RO>;

pub struct PapyrusReader {
storage_reader: StorageReader,
latest_block: BlockNumber,
Expand Down
Loading

0 comments on commit b02f45b

Please sign in to comment.