Skip to content

Commit

Permalink
fix(prover): Reduce database connection overhead for BWG (#2543)
Browse files Browse the repository at this point in the history
BWG uses connection as part of it's save/update_database cycle. This
means that every execute call is sent to the database. Transaction can
be used to "batch" those and be sent only during commit.

This will get rid of 10 minutes on mainnet (on worst batches).
  • Loading branch information
EmilLuta authored Jul 31, 2024
1 parent be238cc commit c2439e9
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions prover/crates/bin/witness_generator/src/basic_circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,19 @@ async fn update_database(
block_number: L1BatchNumber,
blob_urls: BlobUrls,
) {
let mut prover_connection = prover_connection_pool.connection().await.unwrap();
let protocol_version_id = prover_connection
let mut connection = prover_connection_pool
.connection()
.await
.expect("failed to get database connection");
let mut transaction = connection
.start_transaction()
.await
.expect("failed to get database transaction");
let protocol_version_id = transaction
.fri_witness_generator_dal()
.protocol_version_for_l1_batch(block_number)
.await;
prover_connection
transaction
.fri_prover_jobs_dal()
.insert_prover_jobs(
block_number,
Expand All @@ -306,7 +313,7 @@ async fn update_database(
protocol_version_id,
)
.await;
prover_connection
transaction
.fri_witness_generator_dal()
.create_aggregation_jobs(
block_number,
Expand All @@ -316,10 +323,14 @@ async fn update_database(
protocol_version_id,
)
.await;
prover_connection
transaction
.fri_witness_generator_dal()
.mark_witness_job_as_successful(block_number, started_at.elapsed())
.await;
transaction
.commit()
.await
.expect("failed to commit database transaction");
}

#[tracing::instrument(skip_all, fields(l1_batch = %block_number))]
Expand Down

0 comments on commit c2439e9

Please sign in to comment.