Skip to content

Commit b833391

Browse files
apollo_transaction_converter: use proof manager to convert between transactions
1 parent 690c3dc commit b833391

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

crates/apollo_gateway/src/errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ pub fn transaction_converter_err_to_deprecated_gw_err(
362362
TransactionConverterError::ClassNotFound { .. } => {
363363
StarknetError::internal_with_signature_logging("Class not found", tx_signature, err)
364364
}
365+
TransactionConverterError::ProofNotFound { .. } => {
366+
StarknetError::internal_with_signature_logging("Proof not found", tx_signature, err)
367+
}
365368
TransactionConverterError::StarknetApiError(err) => convert_sn_api_error(err),
366369
}
367370
}

crates/apollo_transaction_converter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ apollo_class_manager_types.workspace = true
1717
apollo_proof_manager_types.workspace = true
1818
async-trait.workspace = true
1919
mockall = { workspace = true, optional = true }
20+
starknet-types-core.workspace = true
2021
starknet_api.workspace = true
2122
thiserror.workspace = true
2223
tokio.workspace = true

crates/apollo_transaction_converter/src/transaction_converter.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use starknet_api::state::SierraContractClass;
2929
use starknet_api::transaction::fields::{Fee, Proof, ProofFacts};
3030
use starknet_api::transaction::CalculateContractAddress;
3131
use starknet_api::{executable_transaction, transaction, StarknetApiError};
32+
use starknet_types_core::felt::Felt;
3233
use thiserror::Error;
3334
use tracing::info;
3435

@@ -42,6 +43,8 @@ pub enum TransactionConverterError {
4243
ClassManagerClientError(#[from] ClassManagerClientError),
4344
#[error("Class of hash: {class_hash} not found")]
4445
ClassNotFound { class_hash: ClassHash },
46+
#[error("Proof for proof facts hash: {facts_hash} not found.")]
47+
ProofNotFound { facts_hash: Felt },
4548
#[error(transparent)]
4649
ProofManagerClientError(#[from] ProofManagerClientError),
4750
#[error(transparent)]
@@ -114,6 +117,12 @@ impl TransactionConverter {
114117
.ok_or(TransactionConverterError::ClassNotFound { class_hash })
115118
}
116119

120+
async fn get_proof(&self, proof_facts: &ProofFacts) -> TransactionConverterResult<Proof> {
121+
self.proof_manager_client
122+
.get_proof(proof_facts.clone())
123+
.await?
124+
.ok_or(TransactionConverterError::ProofNotFound { facts_hash: proof_facts.hash() })
125+
}
117126
async fn get_executable(
118127
&self,
119128
class_hash: ClassHash,
@@ -164,6 +173,14 @@ impl TransactionConverterTrait for TransactionConverter {
164173
) -> TransactionConverterResult<RpcTransaction> {
165174
match tx.tx {
166175
InternalRpcTransactionWithoutTxHash::Invoke(tx) => {
176+
// We expect the proof to be available here because it has already been verified
177+
// and stored by the proof manager in the gateway.
178+
let proof = if tx.proof_facts.is_empty() {
179+
Proof::default()
180+
} else {
181+
self.get_proof(&tx.proof_facts).await?
182+
};
183+
167184
Ok(RpcTransaction::Invoke(RpcInvokeTransaction::V3(RpcInvokeTransactionV3 {
168185
resource_bounds: tx.resource_bounds,
169186
signature: tx.signature,
@@ -176,8 +193,7 @@ impl TransactionConverterTrait for TransactionConverter {
176193
calldata: tx.calldata,
177194
account_deployment_data: tx.account_deployment_data,
178195
proof_facts: tx.proof_facts,
179-
// TODO(AvivG): get proof from proof manager once implemented.
180-
proof: Proof::default(),
196+
proof,
181197
})))
182198
}
183199
InternalRpcTransactionWithoutTxHash::Declare(tx) => {
@@ -186,6 +202,8 @@ impl TransactionConverterTrait for TransactionConverter {
186202
compiled_class_hash: tx.compiled_class_hash,
187203
signature: tx.signature,
188204
nonce: tx.nonce,
205+
// We expect the sierra to be available here because it has already been added
206+
// to the class manager in the gateway.
189207
contract_class: self.get_sierra(tx.class_hash).await?,
190208
resource_bounds: tx.resource_bounds,
191209
tip: tx.tip,

0 commit comments

Comments
 (0)