Skip to content

Commit

Permalink
fix: Fix database connections in house keeper (matter-labs#610)
Browse files Browse the repository at this point in the history
## What ❔

Use correct connections for databases in house keeper.

## Why ❔

Databases are divided in 2 on mainnet and testnet

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `cargo spellcheck
--cfg=./spellcheck/era.cfg --code 1`.
  • Loading branch information
Artemka374 authored Dec 5, 2023
1 parent f6a69e0 commit aeaaecb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ use zksync_prover_utils::periodic_job::PeriodicJob;
pub struct FriProverStatsReporter {
reporting_interval_ms: u64,
prover_connection_pool: ConnectionPool,
db_connection_pool: ConnectionPool,
config: FriProverGroupConfig,
}

impl FriProverStatsReporter {
pub fn new(
reporting_interval_ms: u64,
prover_connection_pool: ConnectionPool,
db_connection_pool: ConnectionPool,
config: FriProverGroupConfig,
) -> Self {
Self {
reporting_interval_ms,
prover_connection_pool,
db_connection_pool,
config,
}
}
Expand Down Expand Up @@ -85,7 +88,9 @@ impl PeriodicJob for FriProverStatsReporter {

// FIXME: refactor metrics here

if let Some(l1_batch_number) = conn
let mut db_conn = self.db_connection_pool.access_storage().await.unwrap();

if let Some(l1_batch_number) = db_conn
.proof_generation_dal()
.get_oldest_unprocessed_batch()
.await
Expand All @@ -96,7 +101,7 @@ impl PeriodicJob for FriProverStatsReporter {
)
}

if let Some(l1_batch_number) = conn
if let Some(l1_batch_number) = db_conn
.proof_generation_dal()
.get_oldest_not_generated_batch()
.await
Expand Down
14 changes: 9 additions & 5 deletions core/lib/zksync_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,13 +1088,16 @@ async fn add_house_keeper_to_task_futures(
.clone()
.context("house_keeper_config")?;
let postgres_config = configs.postgres_config.clone().context("postgres_config")?;
let connection_pool = ConnectionPool::singleton(postgres_config.replica_url()?)
.build()
.await
.context("failed to build a connection pool")?;
let connection_pool = ConnectionPool::builder(
postgres_config.replica_url()?,
postgres_config.max_connections()?,
)
.build()
.await
.context("failed to build a connection pool")?;
let l1_batch_metrics_reporter = L1BatchMetricsReporter::new(
house_keeper_config.l1_batch_metrics_reporting_interval_ms,
connection_pool,
connection_pool.clone(),
);

let prover_connection_pool = ConnectionPool::builder(
Expand Down Expand Up @@ -1192,6 +1195,7 @@ async fn add_house_keeper_to_task_futures(
let fri_prover_stats_reporter = FriProverStatsReporter::new(
house_keeper_config.fri_prover_stats_reporting_interval_ms,
prover_connection_pool.clone(),
connection_pool.clone(),
fri_prover_group_config,
);
task_futures.push(tokio::spawn(fri_prover_stats_reporter.run()));
Expand Down

0 comments on commit aeaaecb

Please sign in to comment.