Skip to content

Commit

Permalink
chore(cairo_native): add compiler file path configs
Browse files Browse the repository at this point in the history
  • Loading branch information
avi-starkware committed Jan 3, 2025
1 parent b6bf08d commit a73a7ce
Show file tree
Hide file tree
Showing 17 changed files with 343 additions and 202 deletions.
265 changes: 134 additions & 131 deletions Cargo.lock

Large diffs are not rendered by default.

49 changes: 47 additions & 2 deletions config/sequencer/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,31 @@
"privacy": "Public",
"value": 1000
},
"batcher_config.contract_class_manager_config.compiler_config.libcairo_native_runtime_path": {
"description": "The path to the Cairo native runtime library file.",
"privacy": "Public",
"value": ""
},
"batcher_config.contract_class_manager_config.compiler_config.libcairo_native_runtime_path.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"batcher_config.contract_class_manager_config.compiler_config.max_casm_bytecode_size": {
"description": "Limitation of compiled casm bytecode size.",
"privacy": "Public",
"value": 81920
},
"batcher_config.contract_class_manager_config.compiler_config.sierra_to_native_compiler_path": {
"description": "The path to the Sierra-to-Native compiler binary.",
"privacy": "Public",
"value": ""
},
"batcher_config.contract_class_manager_config.compiler_config.sierra_to_native_compiler_path.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"batcher_config.contract_class_manager_config.contract_cache_size": {
"description": "The size of the global contract cache.",
"privacy": "Public",
Expand Down Expand Up @@ -219,11 +244,31 @@
"param_type": "String",
"privacy": "TemporaryValue"
},
"compiler_config.max_bytecode_size": {
"description": "Limitation of contract bytecode size.",
"compiler_config.libcairo_native_runtime_path": {
"description": "The path to the Cairo native runtime library file.",
"privacy": "Public",
"value": ""
},
"compiler_config.libcairo_native_runtime_path.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"compiler_config.max_casm_bytecode_size": {
"description": "Limitation of compiled casm bytecode size.",
"privacy": "Public",
"value": 81920
},
"compiler_config.sierra_to_native_compiler_path": {
"description": "The path to the Sierra-to-Native compiler binary.",
"privacy": "Public",
"value": ""
},
"compiler_config.sierra_to_native_compiler_path.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"components.batcher.execution_mode": {
"description": "The component execution mode.",
"privacy": "Public",
Expand Down
38 changes: 19 additions & 19 deletions crates/bin/starknet-native-compile/Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ sha2.workspace = true
stacker = { workspace = true, optional = true }
starknet-types-core.workspace = true
starknet_api.workspace = true
starknet_sierra_compile = { workspace = true, optional = true }
starknet_sierra_compile.workspace = true
strum.workspace = true
strum_macros.workspace = true
tempfile.workspace = true
Expand Down
9 changes: 7 additions & 2 deletions crates/blockifier/src/blockifier/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::BTreeMap;
use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};
use starknet_sierra_compile::config::SierraCompilationConfig;

use crate::state::contract_class_manager::DEFAULT_COMPILATION_REQUEST_CHANNEL_SIZE;
use crate::state::global_cache::GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST;
Expand Down Expand Up @@ -71,6 +72,7 @@ pub struct ContractClassManagerConfig {
pub wait_on_native_compilation: bool,
pub contract_cache_size: usize,
pub channel_size: usize,
pub compiler_config: SierraCompilationConfig,
}

impl Default for ContractClassManagerConfig {
Expand All @@ -80,13 +82,14 @@ impl Default for ContractClassManagerConfig {
wait_on_native_compilation: false,
contract_cache_size: GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST,
channel_size: DEFAULT_COMPILATION_REQUEST_CHANNEL_SIZE,
compiler_config: SierraCompilationConfig::default(),
}
}
}

impl SerializeConfig for ContractClassManagerConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([
let mut dump = BTreeMap::from_iter([
ser_param(
"run_cairo_native",
&self.run_cairo_native,
Expand All @@ -111,6 +114,8 @@ impl SerializeConfig for ContractClassManagerConfig {
"The size of the compilation request channel.",
ParamPrivacyInput::Public,
),
])
]);
dump.append(&mut append_sub_config_name(self.compiler_config.dump(), "compiler_config"));
dump
}
}
4 changes: 1 addition & 3 deletions crates/blockifier/src/state/contract_class_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use starknet_api::state::SierraContractClass;
#[cfg(feature = "cairo_native")]
use starknet_sierra_compile::command_line_compiler::CommandLineCompiler;
#[cfg(feature = "cairo_native")]
use starknet_sierra_compile::config::SierraToCasmCompilationConfig;
#[cfg(feature = "cairo_native")]
use starknet_sierra_compile::utils::into_contract_class_for_compilation;
#[cfg(feature = "cairo_native")]
use starknet_sierra_compile::SierraToNativeCompiler;
Expand Down Expand Up @@ -81,7 +79,7 @@ impl ContractClassManager {
};
}

let compiler_config = SierraToCasmCompilationConfig::default();
let compiler_config = config.compiler_config.clone();
let compiler = Arc::new(CommandLineCompiler::new(compiler_config));
if config.wait_on_native_compilation {
// Compilation requests are processed synchronously. No need to start the worker.
Expand Down
7 changes: 6 additions & 1 deletion crates/native_blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ license-file.workspace = true
description = "A Bridge between the Rust blockifier crate and Python."

[features]
cairo_native = ["blockifier/cairo_native", "papyrus_state_reader/cairo_native"]
cairo_native = [
"blockifier/cairo_native",
"papyrus_state_reader/cairo_native",
"starknet_sierra_compile/cairo_native",
]
# Required for `cargo test` to work with Pyo3.
# On Python, make sure to compile this with the extension-module feature enabled.
# https://pyo3.rs/v0.19.1/faq#i-cant-run-cargo-test-or-i-cant-build-in-a-cargo-workspace-im-having-linker-issues-like-symbol-not-found-or-undefined-reference-to-_pyexc_systemerror
Expand Down Expand Up @@ -42,6 +46,7 @@ serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["arbitrary_precision"] }
starknet-types-core.workspace = true
starknet_api.workspace = true
starknet_sierra_compile.workspace = true
thiserror.workspace = true

[dev-dependencies]
Expand Down
42 changes: 41 additions & 1 deletion crates/native_blockifier/src/py_objects.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(non_local_definitions)]

use std::collections::HashMap;
use std::path::PathBuf;

use blockifier::abi::constants;
use blockifier::blockifier::config::{ConcurrencyConfig, ContractClassManagerConfig};
Expand All @@ -12,6 +13,7 @@ use cairo_vm::types::builtin_name::BuiltinName;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use pyo3::prelude::*;
use starknet_api::execution_resources::GasAmount;
use starknet_sierra_compile::config::SierraCompilationConfig;

use crate::errors::{
InvalidNativeBlockifierInputError,
Expand Down Expand Up @@ -160,13 +162,49 @@ impl From<PyConcurrencyConfig> for ConcurrencyConfig {
}
}
}
#[derive(Debug, Clone, FromPyObject)]
pub struct PySierraCompilationConfig {
pub sierra_to_native_compiler_path: String,
pub libcairo_native_runtime_path: String,
}

impl Default for PySierraCompilationConfig {
fn default() -> Self {
Self { sierra_to_native_compiler_path: "".into(), libcairo_native_runtime_path: "".into() }
}
}

impl From<PySierraCompilationConfig> for SierraCompilationConfig {
fn from(py_sierra_compilation_config: PySierraCompilationConfig) -> Self {
SierraCompilationConfig {
sierra_to_native_compiler_path: if py_sierra_compilation_config
.sierra_to_native_compiler_path
.is_empty()
{
None
} else {
Some(PathBuf::from(py_sierra_compilation_config.sierra_to_native_compiler_path))
},
libcairo_native_runtime_path: if py_sierra_compilation_config
.libcairo_native_runtime_path
.is_empty()
{
None
} else {
Some(PathBuf::from(py_sierra_compilation_config.libcairo_native_runtime_path))
},
..Default::default()
}
}
}

#[derive(Debug, Clone, Copy, FromPyObject)]
#[derive(Debug, Clone, FromPyObject)]
pub struct PyContractClassManagerConfig {
pub run_cairo_native: bool,
pub wait_on_native_compilation: bool,
pub contract_cache_size: usize,
pub channel_size: usize,
pub compiler_config: PySierraCompilationConfig,
}

impl Default for PyContractClassManagerConfig {
Expand All @@ -176,6 +214,7 @@ impl Default for PyContractClassManagerConfig {
wait_on_native_compilation: false,
contract_cache_size: GLOBAL_CONTRACT_CACHE_SIZE_FOR_TEST,
channel_size: DEFAULT_COMPILATION_REQUEST_CHANNEL_SIZE,
compiler_config: PySierraCompilationConfig::default(),
}
}
}
Expand All @@ -187,6 +226,7 @@ impl From<PyContractClassManagerConfig> for ContractClassManagerConfig {
wait_on_native_compilation: py_contract_class_manager_config.wait_on_native_compilation,
contract_cache_size: py_contract_class_manager_config.contract_cache_size,
channel_size: py_contract_class_manager_config.channel_size,
compiler_config: py_contract_class_manager_config.compiler_config.into(),
}
}
}
4 changes: 2 additions & 2 deletions crates/starknet_gateway/src/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use starknet_api::contract_class::{ClassInfo, ContractClass, SierraVersion};
use starknet_api::rpc_transaction::RpcDeclareTransaction;
use starknet_gateway_types::errors::GatewaySpecError;
use starknet_sierra_compile::command_line_compiler::CommandLineCompiler;
use starknet_sierra_compile::config::SierraToCasmCompilationConfig;
use starknet_sierra_compile::config::SierraCompilationConfig;
use starknet_sierra_compile::utils::into_contract_class_for_compilation;
use starknet_sierra_compile::SierraToCasmCompiler;
use tracing::{debug, error};
Expand All @@ -24,7 +24,7 @@ pub struct GatewayCompiler {
}

impl GatewayCompiler {
pub fn new_command_line_compiler(config: SierraToCasmCompilationConfig) -> Self {
pub fn new_command_line_compiler(config: SierraCompilationConfig) -> Self {
Self { sierra_to_casm_compiler: Arc::new(CommandLineCompiler::new(config)) }
}

Expand Down
Loading

0 comments on commit a73a7ce

Please sign in to comment.