Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tee): correct previous fix for race condition in batch locking #3358

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

16 changes: 10 additions & 6 deletions core/lib/dal/src/tee_proof_generation_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ impl TeeProofGenerationDal<'_, '_> {
let min_batch_number = i64::from(min_batch_number.0);
let mut transaction = self.storage.start_transaction().await?;

// Lock rows in the proof_generation_details table to prevent race conditions. The
// tee_proof_generation_details table does not have corresponding entries yet if this is the
// first time the query is invoked for a batch. Locking rows in proof_generation_details
// ensures that two different TEE prover instances will not try to prove the same batch.
// Lock the entire tee_proof_generation_details table in EXCLUSIVE mode to prevent race
// conditions. Locking the table ensures that two different TEE prover instances will not
// try to prove the same batch.
sqlx::query("LOCK TABLE tee_proof_generation_details IN EXCLUSIVE MODE")
.instrument("lock_batch_for_proving#lock_table")
.execute(&mut transaction)
.await?;

// The tee_proof_generation_details table does not have corresponding entries yet if this is
// the first time the query is invoked for a batch.
let batch_number = sqlx::query!(
r#"
SELECT
Expand All @@ -95,8 +101,6 @@ impl TeeProofGenerationDal<'_, '_> {
)
)
LIMIT 1
FOR UPDATE OF p
SKIP LOCKED
"#,
tee_type.to_string(),
TeeProofGenerationJobStatus::PickedByProver.to_string(),
Expand Down
Loading