Skip to content

Commit

Permalink
Code review fix: idempotent SQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
pbeza committed Aug 8, 2024
1 parent 3caf0f1 commit 3aa30b2
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions core/lib/dal/src/tee_proof_generation_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,19 @@ impl TeeProofGenerationDal<'_, '_> {
tee_proof_generation_details (l1_batch_number, tee_type, status, created_at, updated_at)
VALUES
($1, $2, 'ready_to_be_proven', NOW(), NOW())
ON CONFLICT (l1_batch_number, tee_type) DO NOTHING
"#,
batch_number,
tee_type.to_string(),
);
let instrumentation = Instrumented::new("insert_tee_proof_generation_job")
.with_arg("l1_batch_number", &batch_number)
.with_arg("tee_type", &tee_type);
let result = instrumentation
instrumentation
.clone()
.with(query)
.execute(self.storage)
.await?;
if result.rows_affected() == 0 {
let err = instrumentation.constraint_error(anyhow::anyhow!(
"Unable to insert TEE proof for batch number {}, TEE type {}",
batch_number,
tee_type
));
return Err(err);
}

Ok(())
}
Expand All @@ -172,18 +165,11 @@ impl TeeProofGenerationDal<'_, '_> {
let instrumentation = Instrumented::new("save_attestation")
.with_arg("pubkey", &pubkey)
.with_arg("attestation", &attestation);
let result = instrumentation
instrumentation
.clone()
.with(query)
.execute(self.storage)
.await?;
if result.rows_affected() == 0 {
let err = instrumentation.constraint_error(anyhow::anyhow!(
"Unable to insert TEE attestation: pubkey {:?} already has an attestation assigned",
pubkey
));
return Err(err);
}

Ok(())
}
Expand Down

0 comments on commit 3aa30b2

Please sign in to comment.