Skip to content

Commit

Permalink
feat: remove TEE from tree
Browse files Browse the repository at this point in the history
TEE input producer jobs are now created by monitoring the db instead of hooking directly into the tree logic.
  • Loading branch information
thomasknauth committed Aug 8, 2024
1 parent 849c6a5 commit 19e0de8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
48 changes: 48 additions & 0 deletions core/lib/dal/src/tee_verifier_input_producer_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,57 @@ impl TeeVerifierInputProducerDal<'_, '_> {
Ok(())
}

// Returns inclusive range, i.e. [low,high]
pub async fn get_new_l1_batches(
&mut self,
) -> DalResult<Option<(L1BatchNumber, L1BatchNumber)>> {
// 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<Option<L1BatchNumber>> {
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
Expand Down
4 changes: 0 additions & 4 deletions core/node/metadata_calculator/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 19e0de8

Please sign in to comment.