From c6c92f2dcc923ff26028bad9e45f8199b5d1950a Mon Sep 17 00:00:00 2001 From: Patrick Beza Date: Fri, 22 Nov 2024 12:18:10 +0100 Subject: [PATCH] feat(tee): add error handling for unstable_getTeeProofs API endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the TEE verifier – the tool for continuous SGX attestation and batch signature verification – is stuck on batches that failed to be proven and are marked as `permanently_ignored`. The tool should be able to distinguish between batches that are permanently ignored (and should be skipped) and batches that have failed but will be retried. This PR enables that distinction. [1]: https://github.com/matter-labs/teepot/blob/main/bin/verify-era-proof-attestation/src/main.rs --- ...5393ec02458104c483a2023b24881ae0c6716.json | 23 ------------------- core/lib/dal/src/models/storage_tee_proof.rs | 1 + core/lib/dal/src/tee_proof_generation_dal.rs | 8 +++---- core/lib/types/src/api/mod.rs | 1 + .../src/web3/namespaces/unstable.rs | 11 +++++++-- 5 files changed, 14 insertions(+), 30 deletions(-) delete mode 100644 core/lib/dal/.sqlx/query-cf3c7b918a3f82476543841d4dc5393ec02458104c483a2023b24881ae0c6716.json diff --git a/core/lib/dal/.sqlx/query-cf3c7b918a3f82476543841d4dc5393ec02458104c483a2023b24881ae0c6716.json b/core/lib/dal/.sqlx/query-cf3c7b918a3f82476543841d4dc5393ec02458104c483a2023b24881ae0c6716.json deleted file mode 100644 index 59bfa4858c02..000000000000 --- a/core/lib/dal/.sqlx/query-cf3c7b918a3f82476543841d4dc5393ec02458104c483a2023b24881ae0c6716.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n COUNT(*) AS \"count!\"\n FROM\n (\n SELECT\n *\n FROM\n storage_logs\n WHERE\n hashed_key = $1\n AND miniblock_number <= COALESCE(\n (\n SELECT\n MAX(number)\n FROM\n miniblocks\n ),\n (\n SELECT\n miniblock_number\n FROM\n snapshot_recovery\n )\n )\n ORDER BY\n miniblock_number DESC,\n operation_number DESC\n LIMIT\n 1\n ) sl\n WHERE\n sl.value != $2\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "count!", - "type_info": "Int8" - } - ], - "parameters": { - "Left": [ - "Bytea", - "Bytea" - ] - }, - "nullable": [ - null - ] - }, - "hash": "cf3c7b918a3f82476543841d4dc5393ec02458104c483a2023b24881ae0c6716" -} diff --git a/core/lib/dal/src/models/storage_tee_proof.rs b/core/lib/dal/src/models/storage_tee_proof.rs index 6f80c59511f9..6e031674b585 100644 --- a/core/lib/dal/src/models/storage_tee_proof.rs +++ b/core/lib/dal/src/models/storage_tee_proof.rs @@ -9,6 +9,7 @@ pub struct StorageTeeProof { pub signature: Option>, pub proof: Option>, pub updated_at: NaiveDateTime, + pub status: String, pub attestation: Option>, } diff --git a/core/lib/dal/src/tee_proof_generation_dal.rs b/core/lib/dal/src/tee_proof_generation_dal.rs index 4d19c3ff0c8b..a2948aa80325 100644 --- a/core/lib/dal/src/tee_proof_generation_dal.rs +++ b/core/lib/dal/src/tee_proof_generation_dal.rs @@ -249,6 +249,7 @@ impl TeeProofGenerationDal<'_, '_> { tp.signature, tp.proof, tp.updated_at, + tp.status, ta.attestation FROM tee_proof_generation_details tp @@ -256,16 +257,13 @@ impl TeeProofGenerationDal<'_, '_> { 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()) + tee_type.map_or_else(String::new, |_| "AND tp.tee_type = $2".to_string()) ); - let mut query = sqlx::query_as(&query) - .bind(i64::from(batch_number.0)) - .bind(TeeProofGenerationJobStatus::Generated.to_string()); + let mut query = sqlx::query_as(&query).bind(i64::from(batch_number.0)); if let Some(tee_type) = tee_type { query = query.bind(tee_type.to_string()); diff --git a/core/lib/types/src/api/mod.rs b/core/lib/types/src/api/mod.rs index b5d2b3276527..509dd8065281 100644 --- a/core/lib/types/src/api/mod.rs +++ b/core/lib/types/src/api/mod.rs @@ -878,6 +878,7 @@ pub struct TeeProof { #[serde_as(as = "Option")] pub proof: Option>, pub proved_at: DateTime, + pub status: String, #[serde_as(as = "Option")] pub attestation: Option>, } diff --git a/core/node/api_server/src/web3/namespaces/unstable.rs b/core/node/api_server/src/web3/namespaces/unstable.rs index 783088cdc36a..dcc06ed75951 100644 --- a/core/node/api_server/src/web3/namespaces/unstable.rs +++ b/core/node/api_server/src/web3/namespaces/unstable.rs @@ -42,7 +42,7 @@ impl UnstableNamespace { tee_type: Option, ) -> Result, 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 @@ -55,8 +55,15 @@ impl UnstableNamespace { signature: proof.signature, proof: proof.proof, proved_at: DateTime::::from_naive_utc_and_offset(proof.updated_at, Utc), + status: proof.status, attestation: proof.attestation, }) - .collect::>()) + .collect::>(); + + if proofs.is_empty() { + return Err(Web3Error::NoBlock); + } + + Ok(proofs) } }