Skip to content

Commit cf35b38

Browse files
committed
apollo_gateway: remove internal tx from blocking task
1 parent 5458f70 commit cf35b38

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

crates/apollo_gateway/src/gateway.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use apollo_network_types::network_types::BroadcastedMessageMetadata;
2525
use apollo_proc_macros::sequencer_latency_histogram;
2626
use apollo_state_sync_types::communication::SharedStateSyncClient;
2727
use axum::async_trait;
28+
use starknet_api::core::Nonce;
2829
use starknet_api::executable_transaction::AccountTransaction;
2930
use starknet_api::rpc_transaction::{
3031
InternalRpcTransaction,
@@ -149,19 +150,15 @@ impl Gateway {
149150
transaction_converter_err_to_deprecated_gw_err(&tx_signature, e)
150151
})?;
151152

152-
let blocking_task = ProcessTxBlockingTask::new(
153-
self,
154-
internal_tx,
155-
executable_tx,
156-
tokio::runtime::Handle::current(),
157-
);
153+
let blocking_task =
154+
ProcessTxBlockingTask::new(self, executable_tx, tokio::runtime::Handle::current());
158155
// Run the blocking task in the current span.
159156
let curr_span = Span::current();
160157
let handle =
161158
tokio::task::spawn_blocking(move || curr_span.in_scope(|| blocking_task.process_tx()));
162159
let handle_result = handle.await;
163-
let add_tx_args = match handle_result {
164-
Ok(Ok(add_tx_args)) => add_tx_args,
160+
let nonce = match handle_result {
161+
Ok(Ok(nonce)) => nonce,
165162
Ok(Err(starknet_err)) => {
166163
info!(
167164
"Gateway validation failed for tx with signature: {:?} with error: {}",
@@ -182,9 +179,12 @@ impl Gateway {
182179
}
183180
};
184181

185-
let gateway_output = create_gateway_output(&add_tx_args.tx);
182+
let gateway_output = create_gateway_output(&internal_tx);
186183

187-
let add_tx_args = AddTransactionArgsWrapper { args: add_tx_args, p2p_message_metadata };
184+
let add_tx_args = AddTransactionArgsWrapper {
185+
args: AddTransactionArgs::new(internal_tx, nonce),
186+
p2p_message_metadata,
187+
};
188188
match mempool_client_result_to_deprecated_gw_result(
189189
tx.signature(),
190190
self.mempool_client.add_tx(add_tx_args).await,
@@ -236,29 +236,26 @@ struct ProcessTxBlockingTask {
236236
stateful_tx_validator_factory: Arc<dyn StatefulTransactionValidatorFactoryTrait>,
237237
state_reader_factory: Arc<dyn StateReaderFactory>,
238238
mempool_client: SharedMempoolClient,
239-
internal_tx: InternalRpcTransaction,
240239
executable_tx: AccountTransaction,
241240
runtime: tokio::runtime::Handle,
242241
}
243242

244243
impl ProcessTxBlockingTask {
245244
pub fn new(
246245
gateway: &Gateway,
247-
internal_tx: InternalRpcTransaction,
248246
executable_tx: AccountTransaction,
249247
runtime: tokio::runtime::Handle,
250248
) -> Self {
251249
Self {
252250
stateful_tx_validator_factory: gateway.stateful_tx_validator_factory.clone(),
253251
state_reader_factory: gateway.state_reader_factory.clone(),
254252
mempool_client: gateway.mempool_client.clone(),
255-
internal_tx,
256253
executable_tx,
257254
runtime,
258255
}
259256
}
260257

261-
fn process_tx(self) -> GatewayResult<AddTransactionArgs> {
258+
fn process_tx(self) -> GatewayResult<Nonce> {
262259
let mut stateful_transaction_validator = self
263260
.stateful_tx_validator_factory
264261
.instantiate_validator(self.state_reader_factory.as_ref())?;
@@ -269,7 +266,7 @@ impl ProcessTxBlockingTask {
269266
self.runtime,
270267
)?;
271268

272-
Ok(AddTransactionArgs::new(self.internal_tx, nonce))
269+
Ok(nonce)
273270
}
274271
}
275272

crates/apollo_gateway/src/gateway_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ fn process_tx_task(
320320
stateful_tx_validator_factory: Arc::new(stateful_transaction_validator_factory),
321321
state_reader_factory: Arc::new(MockStateReaderFactory::new()),
322322
mempool_client: Arc::new(MockMempoolClient::new()),
323-
internal_tx: invoke_args().get_internal_tx(),
324323
executable_tx: executable_invoke_tx(invoke_args()),
325324
runtime: tokio::runtime::Handle::current(),
326325
}

0 commit comments

Comments
 (0)