Skip to content

Commit 4fb6110

Browse files
apollo_gateway: use proof manager
1 parent 77fc5f5 commit 4fb6110

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

crates/apollo_gateway/src/errors.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use apollo_gateway_types::errors::GatewaySpecError;
1010
use apollo_gateway_types::gateway_types::SUPPORTED_TRANSACTION_VERSIONS;
1111
use apollo_mempool_types::communication::{MempoolClientError, MempoolClientResult};
1212
use apollo_mempool_types::errors::MempoolError;
13+
use apollo_proof_manager_types::{ProofManagerClientError, ProofManagerError};
1314
use blockifier::state::errors::StateError;
1415
use reqwest::StatusCode;
1516
use serde_json::{Error as SerdeError, Value};
@@ -453,3 +454,25 @@ fn convert_sn_api_error(err: StarknetApiError) -> StarknetError {
453454
StarknetApiError::InvalidProofFacts(_) => todo!(),
454455
}
455456
}
457+
458+
pub fn convert_proof_manager_error(err: ProofManagerClientError) -> StarknetError {
459+
match err {
460+
ProofManagerClientError::ClientError(client_error) => {
461+
StarknetError::internal_with_logging("Proof manager client error", &client_error)
462+
}
463+
ProofManagerClientError::ProofManagerError(proof_manager_error) => {
464+
match proof_manager_error {
465+
ProofManagerError::Client(_) => StarknetError::internal_with_logging(
466+
"Proof manager error",
467+
&proof_manager_error,
468+
),
469+
ProofManagerError::ProofStorage(_) | ProofManagerError::Io(_) => {
470+
StarknetError::internal_with_logging(
471+
"Proof manager storage error",
472+
&proof_manager_error,
473+
)
474+
}
475+
}
476+
}
477+
}
478+
}

crates/apollo_gateway/src/gateway.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ use starknet_api::rpc_transaction::{
3232
InternalRpcTransaction,
3333
InternalRpcTransactionWithoutTxHash,
3434
RpcDeclareTransaction,
35+
RpcInvokeTransaction,
3536
RpcTransaction,
3637
};
3738
use starknet_api::transaction::fields::TransactionSignature;
3839
use tracing::{debug, warn};
3940

4041
use crate::errors::{
42+
convert_proof_manager_error,
4143
mempool_client_result_to_deprecated_gw_result,
4244
transaction_converter_err_to_deprecated_gw_err,
4345
GatewayResult,
@@ -135,6 +137,18 @@ impl Gateway {
135137
// Perform stateless validations.
136138
self.stateless_tx_validator.validate(&tx)?;
137139

140+
// TODO(Einat): Consider moving to `convert_rpc_tx_to_internal_and_executable_txs` function.
141+
// If a transaction has a proof then we add it to the proof manager.
142+
if let RpcTransaction::Invoke(RpcInvokeTransaction::V3(ref tx)) = tx {
143+
if !tx.proof_facts.is_empty() {
144+
let proof_facts_hash = tx.proof_facts.hash();
145+
self.proof_manager_client
146+
.set_proof(proof_facts_hash, tx.proof.clone())
147+
.await
148+
.map_err(convert_proof_manager_error)?;
149+
}
150+
}
151+
138152
let tx_signature = tx.signature().clone();
139153
let (internal_tx, executable_tx) =
140154
self.convert_rpc_tx_to_internal_and_executable_txs(tx, &tx_signature).await?;

crates/apollo_gateway/src/gateway_test.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use starknet_api::executable_transaction::AccountTransaction;
5353
use starknet_api::rpc_transaction::{
5454
InternalRpcTransaction,
5555
RpcDeclareTransaction,
56+
RpcInvokeTransaction,
5657
RpcTransaction,
5758
RpcTransactionLabelValue,
5859
};
@@ -278,7 +279,17 @@ async fn setup_mock_state(
278279
) {
279280
let input_tx = tx_args.get_rpc_tx();
280281
let expected_internal_tx = tx_args.get_internal_tx();
281-
282+
if let RpcTransaction::Invoke(RpcInvokeTransaction::V3(ref v3_tx)) = input_tx {
283+
if !v3_tx.proof_facts.is_empty() {
284+
let proof_facts_hash = v3_tx.proof_facts.hash();
285+
mock_dependencies
286+
.mock_proof_manager_client
287+
.expect_set_proof()
288+
.once()
289+
.with(eq(proof_facts_hash), eq(v3_tx.proof.clone()))
290+
.return_once(|_, _| Ok(()));
291+
}
292+
}
282293
setup_transaction_converter_mock(&mut mock_dependencies.mock_transaction_converter, tx_args);
283294

284295
let address = expected_internal_tx.contract_address();
@@ -570,6 +581,18 @@ async fn add_tx_returns_error_when_extract_state_nonce_and_run_validations_fails
570581
.return_once(|| Ok(Box::new(mock_stateful_transaction_validator)));
571582

572583
let tx_args = invoke_args();
584+
let input_tx = tx_args.get_rpc_tx();
585+
if let RpcTransaction::Invoke(RpcInvokeTransaction::V3(ref v3_tx)) = input_tx {
586+
if !v3_tx.proof_facts.is_empty() {
587+
let proof_facts_hash = v3_tx.proof_facts.hash();
588+
mock_dependencies
589+
.mock_proof_manager_client
590+
.expect_set_proof()
591+
.once()
592+
.with(eq(proof_facts_hash), eq(v3_tx.proof.clone()))
593+
.return_once(|_, _| Ok(()));
594+
}
595+
}
573596
setup_transaction_converter_mock(&mut mock_dependencies.mock_transaction_converter, &tx_args);
574597
let gateway = Gateway {
575598
config: Arc::new(mock_dependencies.config),
@@ -580,7 +603,7 @@ async fn add_tx_returns_error_when_extract_state_nonce_and_run_validations_fails
580603
proof_manager_client: Arc::new(mock_dependencies.mock_proof_manager_client),
581604
};
582605

583-
let result = gateway.add_tx(tx_args.get_rpc_tx(), None).await;
606+
let result = gateway.add_tx(input_tx, None).await;
584607

585608
assert!(result.is_err());
586609
assert_eq!(result.unwrap_err().code, error_code);
@@ -600,6 +623,7 @@ async fn stateless_transaction_validator_error(mut mock_dependencies: MockDepend
600623
.expect_validate()
601624
.return_once(|_| arbitrary_validation_error);
602625
mock_dependencies.mock_stateless_transaction_validator = mock_stateless_transaction_validator;
626+
603627
let gateway = mock_dependencies.gateway();
604628
let result = gateway.add_tx(invoke_args().get_rpc_tx(), None).await;
605629

@@ -623,6 +647,18 @@ async fn add_tx_returns_error_when_instantiating_validator_fails(
623647
.return_once(|| Err(expected_error));
624648

625649
let tx_args = invoke_args();
650+
let input_tx = tx_args.get_rpc_tx();
651+
if let RpcTransaction::Invoke(RpcInvokeTransaction::V3(ref v3_tx)) = input_tx {
652+
if !v3_tx.proof_facts.is_empty() {
653+
let proof_facts_hash = v3_tx.proof_facts.hash();
654+
mock_dependencies
655+
.mock_proof_manager_client
656+
.expect_set_proof()
657+
.once()
658+
.with(eq(proof_facts_hash), eq(v3_tx.proof.clone()))
659+
.return_once(|_, _| Ok(()));
660+
}
661+
}
626662
setup_transaction_converter_mock(&mut mock_dependencies.mock_transaction_converter, &tx_args);
627663
let gateway = Gateway {
628664
config: Arc::new(mock_dependencies.config),
@@ -633,7 +669,7 @@ async fn add_tx_returns_error_when_instantiating_validator_fails(
633669
proof_manager_client: Arc::new(mock_dependencies.mock_proof_manager_client),
634670
};
635671

636-
let result = gateway.add_tx(tx_args.get_rpc_tx(), None).await;
672+
let result = gateway.add_tx(input_tx, None).await;
637673

638674
assert!(result.is_err());
639675
assert_eq!(result.unwrap_err().code, error_code);

0 commit comments

Comments
 (0)