From 19e0de86dac7e8ccfb7b212a56702a4835c73f33 Mon Sep 17 00:00:00 2001 From: Thomas Knauth Date: Thu, 8 Aug 2024 20:15:07 +0000 Subject: [PATCH] feat: remove TEE from tree TEE input producer jobs are now created by monitoring the db instead of hooking directly into the tree logic. --- .../src/tee_verifier_input_producer_dal.rs | 48 +++++++++++++++++++ core/node/metadata_calculator/src/updater.rs | 4 -- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/core/lib/dal/src/tee_verifier_input_producer_dal.rs b/core/lib/dal/src/tee_verifier_input_producer_dal.rs index 4adee62e7aa6..86ef6cd0f50f 100644 --- a/core/lib/dal/src/tee_verifier_input_producer_dal.rs +++ b/core/lib/dal/src/tee_verifier_input_producer_dal.rs @@ -72,9 +72,57 @@ impl TeeVerifierInputProducerDal<'_, '_> { Ok(()) } + // Returns inclusive range, i.e. [low,high] + pub async fn get_new_l1_batches( + &mut self, + ) -> DalResult> { + // COALESCE(1, ...) covers the case where the table is initially empty. NB: We start from batch 1, since genesis batch 0 has no proof. + let row_low = sqlx::query!( + r#" + SELECT + COALESCE(1, MAX(l1_batch_number) + 1) AS "number" + FROM + tee_verifier_input_producer_jobs + "# + ) + .instrument("get_latest_tee_job_l1_batch_number") + .report_latency() + .fetch_one(self.storage) + .await?; + + // Since we depend on Merkle paths, we use the proof_generation_details table to inform us of newly available to-be-proven batches. + let row_high = sqlx::query!( + r#" + SELECT + MAX(l1_batch_number) AS "number" + FROM + proof_generation_details + "# + ) + .instrument("get_sealed_l1_batch_number") + .report_latency() + .fetch_one(self.storage) + .await?; + + match (row_low.number, row_high.number) { + (Some(low), Some(high)) => Ok(Some(( + L1BatchNumber(low as u32), + L1BatchNumber(high as u32), + ))), + _ => Ok(None), + } + } + pub async fn get_next_tee_verifier_input_producer_job( &mut self, ) -> DalResult> { + if let Some((low, high)) = self.get_new_l1_batches().await? { + for i in low.0..=high.0 { + self.create_tee_verifier_input_producer_job(L1BatchNumber(i)) + .await? + } + } + let l1_batch_number = sqlx::query!( r#" UPDATE tee_verifier_input_producer_jobs diff --git a/core/node/metadata_calculator/src/updater.rs b/core/node/metadata_calculator/src/updater.rs index e2acf62dea8a..17fd5d900eab 100644 --- a/core/node/metadata_calculator/src/updater.rs +++ b/core/node/metadata_calculator/src/updater.rs @@ -152,10 +152,6 @@ impl TreeUpdater { // right away without having to implement dedicated code. if let Some(object_key) = &object_key { - storage - .tee_verifier_input_producer_dal() - .create_tee_verifier_input_producer_job(l1_batch_number) - .await?; // Save the proof generation details to Postgres storage .proof_generation_dal()