diff --git a/crates/gateway/src/compilation.rs b/crates/gateway/src/compilation.rs index c7641d62..5814bff8 100644 --- a/crates/gateway/src/compilation.rs +++ b/crates/gateway/src/compilation.rs @@ -19,6 +19,7 @@ use crate::utils::is_subsequence; #[path = "compilation_test.rs"] mod compilation_test; +#[derive(Clone)] pub struct GatewayCompiler { #[allow(dead_code)] pub config: GatewayCompilerConfig, diff --git a/crates/gateway/src/gateway.rs b/crates/gateway/src/gateway.rs index 87bc6e5a..50b51ce3 100644 --- a/crates/gateway/src/gateway.rs +++ b/crates/gateway/src/gateway.rs @@ -36,6 +36,7 @@ pub struct AppState { pub stateless_tx_validator: StatelessTransactionValidator, pub stateful_tx_validator: Arc, pub state_reader_factory: Arc, + pub gateway_compiler: GatewayCompiler, pub mempool_client: SharedMempoolClient, } @@ -53,6 +54,7 @@ impl Gateway { config: config.stateful_tx_validator_config.clone(), }), state_reader_factory, + gateway_compiler: GatewayCompiler { config: config.compiler_config.clone() }, mempool_client, }; Gateway { config, app_state } @@ -91,6 +93,7 @@ async fn add_tx( app_state.stateless_tx_validator, app_state.stateful_tx_validator.as_ref(), app_state.state_reader_factory.as_ref(), + app_state.gateway_compiler, tx, ) }) @@ -111,6 +114,7 @@ fn process_tx( stateless_tx_validator: StatelessTransactionValidator, stateful_tx_validator: &StatefulTransactionValidator, state_reader_factory: &dyn StateReaderFactory, + gateway_compiler: GatewayCompiler, tx: RPCTransaction, ) -> GatewayResult { // TODO(Arni, 1/5/2024): Perform congestion control. @@ -121,7 +125,6 @@ fn process_tx( // Compile Sierra to Casm. let optional_class_info = match &tx { RPCTransaction::Declare(declare_tx) => { - let gateway_compiler = GatewayCompiler { config: Default::default() }; Some(gateway_compiler.compile_contract_class(declare_tx)?) } _ => None, diff --git a/crates/gateway/src/gateway_test.rs b/crates/gateway/src/gateway_test.rs index e4288afe..e9e70d28 100644 --- a/crates/gateway/src/gateway_test.rs +++ b/crates/gateway/src/gateway_test.rs @@ -17,6 +17,7 @@ use starknet_mempool_types::communication::{MempoolClientImpl, MempoolRequestAnd use tokio::sync::mpsc::channel; use tokio::task; +use crate::compilation_config::GatewayCompilerConfig; use crate::config::{StatefulTransactionValidatorConfig, StatelessTransactionValidatorConfig}; use crate::gateway::{add_tx, AppState, GatewayCompiler, SharedMempoolClient}; use crate::state_reader_test_utils::{ @@ -52,6 +53,7 @@ pub fn app_state( stateful_tx_validator: Arc::new(StatefulTransactionValidator { config: StatefulTransactionValidatorConfig::create_for_testing(), }), + gateway_compiler: GatewayCompiler { config: GatewayCompilerConfig {} }, state_reader_factory: Arc::new(state_reader_factory), mempool_client, } @@ -111,7 +113,7 @@ async fn to_bytes(res: Response) -> Bytes { fn calculate_hash(external_tx: &RPCTransaction) -> TransactionHash { let optional_class_info = match &external_tx { RPCTransaction::Declare(declare_tx) => Some( - GatewayCompiler { config: Default::default() } + GatewayCompiler { config: GatewayCompilerConfig {} } .compile_contract_class(declare_tx) .unwrap(), ), diff --git a/crates/gateway/src/stateful_transaction_validator_test.rs b/crates/gateway/src/stateful_transaction_validator_test.rs index ba1a038f..9800ac70 100644 --- a/crates/gateway/src/stateful_transaction_validator_test.rs +++ b/crates/gateway/src/stateful_transaction_validator_test.rs @@ -14,6 +14,7 @@ use starknet_api::rpc_transaction::RPCTransaction; use starknet_api::transaction::TransactionHash; use crate::compilation::GatewayCompiler; +use crate::compilation_config::GatewayCompilerConfig; use crate::config::StatefulTransactionValidatorConfig; use crate::errors::{StatefulTransactionValidatorError, StatefulTransactionValidatorResult}; use crate::state_reader_test_utils::{ @@ -81,10 +82,11 @@ fn test_stateful_tx_validator( }, }; let optional_class_info = match &external_tx { - RPCTransaction::Declare(declare_tx) => { - let gateway_compiler = GatewayCompiler { config: Default::default() }; - Some(gateway_compiler.compile_contract_class(declare_tx).unwrap()) - } + RPCTransaction::Declare(declare_tx) => Some( + GatewayCompiler { config: GatewayCompilerConfig {} } + .compile_contract_class(declare_tx) + .unwrap(), + ), _ => None, };