Skip to content

Commit

Permalink
Merge branch 'main' into matias/refactor-chain-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
matias-gonz authored Nov 27, 2024
2 parents d6c3446 + 26f630c commit 9f9ab7d
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 40 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

1 change: 1 addition & 0 deletions core/lib/dal/src/models/storage_tee_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct StorageTeeProof {
pub signature: Option<Vec<u8>>,
pub proof: Option<Vec<u8>>,
pub updated_at: NaiveDateTime,
pub status: String,
pub attestation: Option<Vec<u8>>,
}

Expand Down
32 changes: 18 additions & 14 deletions core/lib/dal/src/tee_proof_generation_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use zksync_db_connection::{
connection::Connection,
error::DalResult,
instrument::{InstrumentExt, Instrumented},
interpolate_query, match_query_as,
utils::pg_interval_from_duration,
};
use zksync_types::{tee_types::TeeType, L1BatchNumber};
Expand Down Expand Up @@ -242,36 +243,39 @@ impl TeeProofGenerationDal<'_, '_> {
batch_number: L1BatchNumber,
tee_type: Option<TeeType>,
) -> DalResult<Vec<StorageTeeProof>> {
let query = format!(
let query = match_query_as!(
StorageTeeProof,
[
r#"
SELECT
tp.pubkey,
tp.signature,
tp.proof,
tp.updated_at,
tp.status,
ta.attestation
FROM
tee_proof_generation_details tp
LEFT JOIN
tee_attestations ta ON tp.pubkey = ta.pubkey
WHERE
tp.l1_batch_number = $1
AND tp.status = $2
{}
ORDER BY tp.l1_batch_number ASC, tp.tee_type ASC
"#,
tee_type.map_or_else(String::new, |_| "AND tp.tee_type = $3".to_string())
_,
"ORDER BY tp.l1_batch_number ASC, tp.tee_type ASC"
],
match(&tee_type) {
Some(tee_type) =>
("AND tp.tee_type = $2"; i64::from(batch_number.0), tee_type.to_string()),
None => (""; i64::from(batch_number.0)),
}
);

let mut query = sqlx::query_as(&query)
.bind(i64::from(batch_number.0))
.bind(TeeProofGenerationJobStatus::Generated.to_string());

if let Some(tee_type) = tee_type {
query = query.bind(tee_type.to_string());
}

let proofs: Vec<StorageTeeProof> = query.fetch_all(self.storage.conn()).await.unwrap();
let proofs = query
.instrument("get_tee_proofs")
.with_arg("l1_batch_number", &batch_number)
.fetch_all(self.storage)
.await?;

Ok(proofs)
}
Expand Down
1 change: 1 addition & 0 deletions core/lib/types/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ pub struct TeeProof {
#[serde_as(as = "Option<Hex>")]
pub proof: Option<Vec<u8>>,
pub proved_at: DateTime<Utc>,
pub status: String,
#[serde_as(as = "Option<Hex>")]
pub attestation: Option<Vec<u8>>,
}
Expand Down
7 changes: 5 additions & 2 deletions core/node/api_server/src/web3/namespaces/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl UnstableNamespace {
tee_type: Option<TeeType>,
) -> Result<Vec<TeeProof>, Web3Error> {
let mut storage = self.state.acquire_connection().await?;
Ok(storage
let proofs = storage
.tee_proof_generation_dal()
.get_tee_proofs(l1_batch_number, tee_type)
.await
Expand All @@ -55,8 +55,11 @@ impl UnstableNamespace {
signature: proof.signature,
proof: proof.proof,
proved_at: DateTime::<Utc>::from_naive_utc_and_offset(proof.updated_at, Utc),
status: proof.status,
attestation: proof.attestation,
})
.collect::<Vec<_>>())
.collect::<Vec<_>>();

Ok(proofs)
}
}
2 changes: 1 addition & 1 deletion core/node/proof_data_handler/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async fn submit_tee_proof() {
.await
.expect("Failed to save attestation");

// resend the same request; this time, it should be successful.
// resend the same request; this time, it should be successful

let response = send_submit_tee_proof_request(&app, &uri, &tee_proof_request).await;
assert_eq!(response.status(), StatusCode::OK);
Expand Down

0 comments on commit 9f9ab7d

Please sign in to comment.