Skip to content

Commit

Permalink
refactor: streamline config members on gateway compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Aug 6, 2024
1 parent dd513eb commit af04a8d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
6 changes: 3 additions & 3 deletions crates/gateway/src/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use starknet_sierra_compile::compile::SierraToCasmCompiler;
use starknet_sierra_compile::errors::CompilationUtilError;
use starknet_sierra_compile::utils::into_contract_class_for_compilation;

use crate::config::GatewayCompilerConfig;
use crate::config::{GatewayCompilerConfig, PostCompilationConfig};
use crate::errors::{GatewayError, GatewayResult};

#[cfg(test)]
Expand All @@ -19,14 +19,14 @@ mod compilation_test;
// TODO(Arni): Pass the compiler with dependancy injection.
#[derive(Clone)]
pub struct GatewayCompiler {
config: GatewayCompilerConfig,
config: PostCompilationConfig,
sierra_to_casm_compiler: SierraToCasmCompiler,
}

impl GatewayCompiler {
pub fn new(config: GatewayCompilerConfig) -> Self {
GatewayCompiler {
config,
config: config.post_compilation_config,
sierra_to_casm_compiler: SierraToCasmCompiler {
config: config.sierra_to_casm_compiler_config,
},
Expand Down
4 changes: 2 additions & 2 deletions crates/gateway/src/compilation_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use starknet_sierra_compile::config::SierraToCasmCompilationConfig;
use starknet_sierra_compile::errors::CompilationUtilError;

use crate::compilation::GatewayCompiler;
use crate::config::GatewayCompilerConfig;
use crate::config::{GatewayCompilerConfig, PostCompilationConfig};
use crate::errors::GatewayError;

#[fixture]
Expand Down Expand Up @@ -72,7 +72,7 @@ fn test_compile_contract_class_bytecode_size_validation(declare_tx_v3: RpcDeclar
#[rstest]
fn test_compile_contract_class_raw_class_size_validation(declare_tx_v3: RpcDeclareTransactionV3) {
let gateway_compiler = GatewayCompiler::new(GatewayCompilerConfig {
max_raw_casm_class_size: 1,
post_compilation_config: PostCompilationConfig { max_raw_casm_class_size: 1 },
..Default::default()
});

Expand Down
41 changes: 27 additions & 14 deletions crates/gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,33 +236,46 @@ impl StatefulTransactionValidatorConfig {
}
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, Validate, PartialEq)]
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, Validate, PartialEq)]
pub struct GatewayCompilerConfig {
pub sierra_to_casm_compiler_config: SierraToCasmCompilationConfig,
pub post_compilation_config: PostCompilationConfig,
}

impl SerializeConfig for GatewayCompilerConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
vec![
append_sub_config_name(
self.sierra_to_casm_compiler_config.dump(),
"sierra_to_casm_compiler_config",
),
append_sub_config_name(self.post_compilation_config.dump(), "post_compilation_config"),
]
.into_iter()
.flatten()
.collect()
}
}

/// The configuration for the post compilation process in the gateway compiler.
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Validate, PartialEq)]
pub struct PostCompilationConfig {
pub max_raw_casm_class_size: usize,
}

impl Default for GatewayCompilerConfig {
impl Default for PostCompilationConfig {
fn default() -> Self {
GatewayCompilerConfig {
max_raw_casm_class_size: MAX_RAW_CLASS_SIZE,
sierra_to_casm_compiler_config: SierraToCasmCompilationConfig::default(),
}
PostCompilationConfig { max_raw_casm_class_size: MAX_RAW_CLASS_SIZE }
}
}

impl SerializeConfig for GatewayCompilerConfig {
impl SerializeConfig for PostCompilationConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
let members = BTreeMap::from_iter([ser_param(
BTreeMap::from_iter([ser_param(
"max_raw_casm_class_size",
&self.max_raw_casm_class_size,
"Limitation of contract class object size.",
ParamPrivacyInput::Public,
)]);
let sub_configs = append_sub_config_name(
self.sierra_to_casm_compiler_config.dump(),
"sierra_to_casm_compiler_config",
);
vec![members, sub_configs].into_iter().flatten().collect()
)])
}
}

0 comments on commit af04a8d

Please sign in to comment.