Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
refactor(native_blockifier): remove unused py objects (#1864)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoni-Starkware authored May 6, 2024
1 parent 938d287 commit 78b6e20
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 274 deletions.
11 changes: 2 additions & 9 deletions crates/native_blockifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ pub mod py_declare;
pub mod py_deploy_account;
pub mod py_invoke_function;
pub mod py_l1_handler;
pub mod py_objects;
pub mod py_state_diff;
#[cfg(any(feature = "testing", test))]
pub mod py_test_utils;
// TODO(Dori, 1/4/2023): If and when supported in the Python build environment, use #[cfg(test)].
pub mod py_testing_wrappers;
pub mod py_transaction;
pub mod py_transaction_execution_info;
pub mod py_utils;
pub mod py_validator;
pub mod state_readers;
Expand All @@ -27,10 +27,7 @@ pub mod test_utils;

use errors::{add_py_exceptions, UndeclaredClassHashError};
use py_block_executor::PyBlockExecutor;
use py_transaction_execution_info::{
PyCallInfo, PyExecutionResources, PyOrderedEvent, PyOrderedL2ToL1Message,
PyTransactionExecutionInfo,
};
use py_objects::PyExecutionResources;
use py_validator::PyValidator;
use pyo3::prelude::*;
use storage::StorageConfig;
Expand All @@ -48,11 +45,7 @@ fn native_blockifier(py: Python<'_>, py_module: &PyModule) -> PyResult<()> {
pyo3_log::init();

py_module.add_class::<PyBlockExecutor>()?;
py_module.add_class::<PyCallInfo>()?;
py_module.add_class::<PyOrderedEvent>()?;
py_module.add_class::<PyOrderedL2ToL1Message>()?;
py_module.add_class::<PyStateDiff>()?;
py_module.add_class::<PyTransactionExecutionInfo>()?;
py_module.add_class::<PyValidator>()?;
py_module.add_class::<PyExecutionResources>()?;
py_module.add_class::<StorageConfig>()?;
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 @@ -27,9 +27,9 @@ use crate::errors::{
InvalidNativeBlockifierInputError, NativeBlockifierError, NativeBlockifierInputError,
NativeBlockifierResult,
};
use crate::py_objects::PyBouncerConfig;
use crate::py_state_diff::{PyBlockInfo, PyStateDiff};
use crate::py_transaction::{get_py_tx_type, py_tx, PyClassInfo, PY_TX_PARSING_ERR};
use crate::py_transaction_execution_info::PyBouncerConfig;
use crate::py_utils::{int_to_chain_id, PyFelt};
use crate::state_readers::papyrus_state::PapyrusReader;
use crate::storage::{PapyrusStorage, Storage, StorageConfig};
Expand Down
65 changes: 65 additions & 0 deletions crates/native_blockifier/src/py_objects.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use std::collections::HashMap;

use blockifier::abi::constants;
use blockifier::bouncer::{BouncerConfig, BouncerWeights, BuiltinCount};
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use pyo3::prelude::*;

// From Rust to Python.

#[pyclass]
#[derive(Clone, Default)]
pub struct PyExecutionResources {
#[pyo3(get)]
pub n_steps: usize,
#[pyo3(get)]
pub builtin_instance_counter: HashMap<String, usize>,
#[pyo3(get)]
pub n_memory_holes: usize,
}

impl From<ExecutionResources> for PyExecutionResources {
fn from(resources: ExecutionResources) -> Self {
Self {
n_steps: resources.n_steps,
builtin_instance_counter: resources.builtin_instance_counter,
n_memory_holes: resources.n_memory_holes,
}
}
}

// From Python to Rust.

#[derive(Clone, Debug, FromPyObject)]
pub struct PyBouncerConfig {
pub full_total_weights_with_keccak: HashMap<String, usize>,
pub full_total_weights: HashMap<String, usize>,
}

impl From<PyBouncerConfig> for BouncerConfig {
fn from(py_bouncer_config: PyBouncerConfig) -> Self {
BouncerConfig {
block_max_capacity: hash_map_into_bouncer_weights(
py_bouncer_config.full_total_weights.clone(),
),
block_max_capacity_with_keccak: hash_map_into_bouncer_weights(
py_bouncer_config.full_total_weights_with_keccak.clone(),
),
}
}
}

fn hash_map_into_bouncer_weights(mut data: HashMap<String, usize>) -> BouncerWeights {
BouncerWeights {
gas: data.remove(constants::L1_GAS_USAGE).expect("gas_weight must be present"),
n_steps: data.remove(constants::N_STEPS_RESOURCE).expect("n_steps must be present"),
message_segment_length: data
.remove(constants::MESSAGE_SEGMENT_LENGTH)
.expect("message_segment_length must be present"),
state_diff_size: data
.remove(constants::STATE_DIFF_SIZE)
.expect("state_diff_size must be present"),
n_events: data.remove(constants::N_EVENTS).expect("n_events must be present"),
builtin_count: BuiltinCount::from(data),
}
}
2 changes: 1 addition & 1 deletion crates/native_blockifier/src/py_testing_wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cairo_lang_starknet_classes::NestedIntList;
use pyo3::{pyfunction, PyResult};

use crate::errors::NativeBlockifierResult;
use crate::py_transaction_execution_info::PyExecutionResources;
use crate::py_objects::PyExecutionResources;

#[pyfunction]
pub fn raise_error_for_testing() -> NativeBlockifierResult<()> {
Expand Down
263 changes: 0 additions & 263 deletions crates/native_blockifier/src/py_transaction_execution_info.rs

This file was deleted.

0 comments on commit 78b6e20

Please sign in to comment.