From f44908d7cd2eafa8f2580f2c82c92ef0dbfbed2a Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Mon, 8 Jul 2024 09:23:31 +0300 Subject: [PATCH] chore: add the gateway compiler to appstate --- crates/gateway/src/compilation.rs | 1 + crates/gateway/src/gateway.rs | 5 ++++- crates/gateway/src/gateway_test.rs | 4 +++- .../gateway/src/stateful_transaction_validator_test.rs | 10 ++++++---- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/gateway/src/compilation.rs b/crates/gateway/src/compilation.rs index 58ec1869..ff1a126d 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 { 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 6cad7f72..0b2e51ce 100644 --- a/crates/gateway/src/stateful_transaction_validator_test.rs +++ b/crates/gateway/src/stateful_transaction_validator_test.rs @@ -13,6 +13,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::{ @@ -80,10 +81,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, };