diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index c4adbc9804f..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,8 +828,7 @@ 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 + let state_keeper_pool = ConnectionPool::::singleton(postgres_config.master_url()?) .build() .await .context("failed to build state_keeper_pool")?; @@ -843,7 +842,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")?; @@ -854,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, @@ -876,7 +883,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")?; diff --git a/core/lib/zksync_core/src/state_keeper/mod.rs b/core/lib/zksync_core/src/state_keeper/mod.rs index bb77084bd5b..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; @@ -41,7 +38,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 +46,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 +66,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), ) }