From cb4a17bc83d66c3ecdd501ebb61c1cc61468bd68 Mon Sep 17 00:00:00 2001 From: Daniyar Itegulov Date: Mon, 22 Apr 2024 16:15:48 +0500 Subject: [PATCH 1/3] ensure both executor and async catchup have a dedicated connection in the pool --- core/lib/zksync_core/src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index c4adbc9804f..696018d4a05 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -828,8 +828,11 @@ async fn add_state_keeper_to_task_futures( batch_fee_input_provider: Arc, stop_receiver: watch::Receiver, ) -> anyhow::Result<()> { - let pool_builder = ConnectionPool::::singleton(postgres_config.master_url()?); - let state_keeper_pool = pool_builder + // One (potentially held long-term) connection for async catch up task and another connection for + // batch executor. + let state_keeper_pool_builder = + ConnectionPool::::builder(postgres_config.master_url()?, 2); + let state_keeper_pool = state_keeper_pool_builder .build() .await .context("failed to build state_keeper_pool")?; @@ -843,7 +846,7 @@ async fn add_state_keeper_to_task_futures( mempool }; - let miniblock_sealer_pool = pool_builder + let miniblock_sealer_pool = ConnectionPool::::singleton(postgres_config.master_url()?) .build() .await .context("failed to build miniblock_sealer_pool")?; @@ -876,7 +879,7 @@ async fn add_state_keeper_to_task_futures( })); task_futures.push(tokio::spawn(state_keeper.run())); - let mempool_fetcher_pool = pool_builder + let mempool_fetcher_pool = ConnectionPool::::singleton(postgres_config.master_url()?) .build() .await .context("failed to build mempool_fetcher_pool")?; From a46f94d9c7dda3222a94591641b40cda49d8bcdb Mon Sep 17 00:00:00 2001 From: Daniyar Itegulov Date: Mon, 22 Apr 2024 16:43:24 +0500 Subject: [PATCH 2/3] dedicated pool for `AsyncRocksdbCache` --- core/lib/zksync_core/src/lib.rs | 22 ++++++++++-------- core/lib/zksync_core/src/state_keeper/mod.rs | 24 ++++++++------------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 696018d4a05..0f6f69f96bf 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -89,8 +89,8 @@ use crate::{ }, metadata_calculator::{MetadataCalculator, MetadataCalculatorConfig}, state_keeper::{ - create_state_keeper, MempoolFetcher, MempoolGuard, OutputHandler, SequencerSealer, - StateKeeperPersistence, + create_state_keeper, AsyncRocksdbCache, MempoolFetcher, MempoolGuard, OutputHandler, + SequencerSealer, StateKeeperPersistence, }, utils::ensure_l1_batch_commit_data_generation_mode, }; @@ -828,11 +828,7 @@ async fn add_state_keeper_to_task_futures( batch_fee_input_provider: Arc, stop_receiver: watch::Receiver, ) -> anyhow::Result<()> { - // One (potentially held long-term) connection for async catch up task and another connection for - // batch executor. - let state_keeper_pool_builder = - ConnectionPool::::builder(postgres_config.master_url()?, 2); - let state_keeper_pool = state_keeper_pool_builder + let state_keeper_pool = ConnectionPool::::singleton(postgres_config.master_url()?) .build() .await .context("failed to build state_keeper_pool")?; @@ -857,10 +853,18 @@ async fn add_state_keeper_to_task_futures( ); task_futures.push(tokio::spawn(miniblock_sealer.run())); - let (state_keeper, async_catchup_task) = create_state_keeper( + // One (potentially held long-term) connection for `AsyncCatchupTask` and another connection + // to access `AsyncRocksdbCache` as a storage. + let async_cache_pool = ConnectionPool::::builder(postgres_config.master_url()?, 2) + .build() + .await + .context("failed to build async_cache_pool")?; + let (async_cache, async_catchup_task) = + AsyncRocksdbCache::new(async_cache_pool, db_config.state_keeper_db_path.clone()); + let state_keeper = create_state_keeper( state_keeper_config, state_keeper_wallets, - db_config, + async_cache, l2chain_id, mempool_config, state_keeper_pool, diff --git a/core/lib/zksync_core/src/state_keeper/mod.rs b/core/lib/zksync_core/src/state_keeper/mod.rs index bb77084bd5b..280fa22c06f 100644 --- a/core/lib/zksync_core/src/state_keeper/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/mod.rs @@ -41,7 +41,7 @@ pub(crate) mod updates; pub(crate) async fn create_state_keeper( state_keeper_config: StateKeeperConfig, wallets: wallets::StateKeeper, - db_config: &DBConfig, + async_cache: AsyncRocksdbCache, l2chain_id: L2ChainId, mempool_config: &MempoolConfig, pool: ConnectionPool, @@ -49,11 +49,9 @@ pub(crate) async fn create_state_keeper( batch_fee_input_provider: Arc, output_handler: OutputHandler, stop_receiver: watch::Receiver, -) -> (ZkSyncStateKeeper, AsyncCatchupTask) { - let (storage_factory, task) = - AsyncRocksdbCache::new(pool.clone(), db_config.state_keeper_db_path.clone()); +) -> ZkSyncStateKeeper { let batch_executor_base = MainBatchExecutor::new( - Arc::new(storage_factory), + Arc::new(async_cache), state_keeper_config.save_call_traces, false, ); @@ -71,14 +69,12 @@ pub(crate) async fn create_state_keeper( .expect("Failed initializing main node I/O for state keeper"); let sealer = SequencerSealer::new(state_keeper_config); - ( - ZkSyncStateKeeper::new( - stop_receiver, - Box::new(io), - Box::new(batch_executor_base), - output_handler, - Arc::new(sealer), - ), - task, + + ZkSyncStateKeeper::new( + stop_receiver, + Box::new(io), + Box::new(batch_executor_base), + output_handler, + Arc::new(sealer), ) } From 97024a69aaed342143c21a2cf771e29f9edefb5b Mon Sep 17 00:00:00 2001 From: Daniyar Itegulov Date: Mon, 22 Apr 2024 16:46:44 +0500 Subject: [PATCH 3/3] fmt --- core/lib/zksync_core/src/state_keeper/mod.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/core/lib/zksync_core/src/state_keeper/mod.rs b/core/lib/zksync_core/src/state_keeper/mod.rs index 280fa22c06f..399b9ee39aa 100644 --- a/core/lib/zksync_core/src/state_keeper/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/mod.rs @@ -1,12 +1,9 @@ use std::sync::Arc; use tokio::sync::watch; -use zksync_config::{ - configs::{ - chain::{MempoolConfig, StateKeeperConfig}, - wallets, - }, - DBConfig, +use zksync_config::configs::{ + chain::{MempoolConfig, StateKeeperConfig}, + wallets, }; use zksync_dal::{ConnectionPool, Core}; use zksync_types::L2ChainId;