Skip to content

Commit fbb1184

Browse files
apollo_http_server: reload dynamic config upon tx processing
1 parent b5c2e1a commit fbb1184

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

crates/apollo_http_server/src/errors.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use apollo_config_manager_types::communication::ConfigManagerClientError;
12
use apollo_gateway_types::communication::GatewayClientError;
23
use apollo_gateway_types::deprecated_gateway_error::{
34
KnownStarknetErrorCode,
@@ -23,19 +24,24 @@ pub enum HttpServerRunError {
2324
#[derive(Error, Debug)]
2425
pub enum HttpServerError {
2526
#[error(transparent)]
26-
GatewayClientError(#[from] Box<GatewayClientError>),
27+
ConfigManagerClientError(#[from] ConfigManagerClientError),
28+
#[error(transparent)]
29+
DecompressionError(#[from] CompressionError),
2730
#[error(transparent)]
2831
DeserializationError(#[from] serde_json::Error),
2932
#[error(transparent)]
30-
DecompressionError(#[from] CompressionError),
33+
GatewayClientError(#[from] Box<GatewayClientError>),
3134
}
3235

3336
impl IntoResponse for HttpServerError {
3437
fn into_response(self) -> Response {
3538
match self {
36-
HttpServerError::GatewayClientError(e) => gw_client_err_into_response(*e),
37-
HttpServerError::DeserializationError(e) => serde_error_into_response(e),
39+
HttpServerError::ConfigManagerClientError(e) => {
40+
config_manager_client_err_into_response(e)
41+
}
3842
HttpServerError::DecompressionError(e) => compression_error_into_response(e),
43+
HttpServerError::DeserializationError(e) => serde_error_into_response(e),
44+
HttpServerError::GatewayClientError(e) => gw_client_err_into_response(*e),
3945
}
4046
}
4147
}
@@ -89,6 +95,15 @@ fn gw_client_err_into_response(err: GatewayClientError) -> Response {
8995
(response_code, response_body).into_response()
9096
}
9197

98+
fn config_manager_client_err_into_response(err: ConfigManagerClientError) -> Response {
99+
let (response_code, config_manager_error) = (
100+
StatusCode::INTERNAL_SERVER_ERROR,
101+
StarknetError::internal_with_logging("Failed to process client request", err),
102+
);
103+
let response_body = serialize_error(&config_manager_error);
104+
(response_code, response_body).into_response()
105+
}
106+
92107
/// Serializes a `StarknetError` into an HTTP response, encode the error message
93108
/// to defend potential Cross-Site risks.
94109
fn serialize_error(error: &StarknetError) -> Response {

crates/apollo_http_server/src/http_server.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ pub struct HttpServer {
5757

5858
#[derive(Clone)]
5959
pub struct AppState {
60-
// TODO(Tsabary): use the config manager in the tx processing.
61-
_config_manager_client: SharedConfigManagerClient,
60+
config_manager_client: SharedConfigManagerClient,
6261
pub gateway_client: SharedGatewayClient,
6362
}
6463

@@ -68,7 +67,7 @@ impl HttpServer {
6867
config_manager_client: SharedConfigManagerClient,
6968
gateway_client: SharedGatewayClient,
7069
) -> Self {
71-
let app_state = AppState { _config_manager_client: config_manager_client, gateway_client };
70+
let app_state = AppState { config_manager_client, gateway_client };
7271
HttpServer { config, app_state }
7372
}
7473

@@ -93,8 +92,7 @@ impl HttpServer {
9392
.with_state(self.app_state.clone())
9493
// Rest api endpoint
9594
.route("/gateway/add_transaction", post({
96-
let max_sierra_program_size = self.config.dynamic_config.max_sierra_program_size;
97-
move |app_state: State<AppState>, headers: HeaderMap, tx: String| add_tx(app_state, headers, tx, max_sierra_program_size)
95+
move |app_state: State<AppState>, headers: HeaderMap, tx: String| add_tx(app_state, headers, tx)
9896
}))
9997
.with_state(self.app_state.clone())
10098
// TODO(shahak): Remove this once we fix the centralized simulator to not use is_alive
@@ -129,11 +127,12 @@ async fn add_tx(
129127
State(app_state): State<AppState>,
130128
headers: HeaderMap,
131129
tx: String,
132-
max_sierra_program_size: usize,
133130
) -> HttpServerResult<Json<GatewayOutput>> {
134131
ADDED_TRANSACTIONS_TOTAL.increment(1);
135132
debug!("ADD_TX_START: Http server received a new transaction.");
136133

134+
let dynamic_config = app_state.config_manager_client.get_http_server_dynamic_config().await?;
135+
137136
let tx: DeprecatedGatewayTransactionV3 = match serde_json::from_str(&tx) {
138137
Ok(value) => value,
139138
Err(e) => {
@@ -148,7 +147,7 @@ async fn add_tx(
148147
}
149148
};
150149

151-
let rpc_tx = tx.convert_to_rpc_tx(max_sierra_program_size).inspect_err(|e| {
150+
let rpc_tx = tx.convert_to_rpc_tx(dynamic_config.max_sierra_program_size).inspect_err(|e| {
152151
debug!("Error while converting deprecated gateway transaction into RPC transaction: {}", e);
153152
})?;
154153

0 commit comments

Comments
 (0)