Skip to content

Commit

Permalink
chore: add the gateway compiler to appstate
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Jul 8, 2024
1 parent 0f5d3d2 commit 132a963
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/gateway/src/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::utils::is_subsequence;
#[path = "compilation_test.rs"]
mod compilation_test;

#[derive(Clone)]
pub struct GatewayCompiler {
pub config: GatewayCompilerConfig,
}
Expand Down
5 changes: 4 additions & 1 deletion crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct AppState {
pub stateless_tx_validator: StatelessTransactionValidator,
pub stateful_tx_validator: Arc<StatefulTransactionValidator>,
pub state_reader_factory: Arc<dyn StateReaderFactory>,
pub gateway_compiler: GatewayCompiler,
pub mempool_client: SharedMempoolClient,
}

Expand All @@ -53,6 +54,7 @@ impl Gateway {
config: config.stateful_tx_validator_config.clone(),
}),
state_reader_factory,
gateway_compiler: GatewayCompiler { config: config.gateway_compiler_config.clone() },
mempool_client,
};
Gateway { config, app_state }
Expand Down Expand Up @@ -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,
)
})
Expand All @@ -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<MempoolInput> {
// TODO(Arni, 1/5/2024): Perform congestion control.
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion crates/gateway/src/gateway_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use test_utils::starknet_api_test_utils::{declare_tx, deploy_account_tx, invoke_
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::{
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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(),
),
Expand Down
10 changes: 6 additions & 4 deletions crates/gateway/src/stateful_transaction_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use test_utils::starknet_api_test_utils::{
};

use crate::compilation::GatewayCompiler;
use crate::compilation_config::GatewayCompilerConfig;
use crate::config::StatefulTransactionValidatorConfig;
use crate::errors::{StatefulTransactionValidatorError, StatefulTransactionValidatorResult};
use crate::state_reader_test_utils::{
Expand Down Expand Up @@ -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,
};

Expand Down

0 comments on commit 132a963

Please sign in to comment.