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: ensure two connections for both executor and async catchup #1755

Merged
merged 4 commits into from
Apr 22, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions core/lib/zksync_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -828,8 +828,7 @@ async fn add_state_keeper_to_task_futures(
batch_fee_input_provider: Arc<dyn BatchFeeModelInputProvider>,
stop_receiver: watch::Receiver<bool>,
) -> anyhow::Result<()> {
let pool_builder = ConnectionPool::<Core>::singleton(postgres_config.master_url()?);
let state_keeper_pool = pool_builder
let state_keeper_pool = ConnectionPool::<Core>::singleton(postgres_config.master_url()?)
.build()
.await
.context("failed to build state_keeper_pool")?;
Expand All @@ -843,7 +842,7 @@ async fn add_state_keeper_to_task_futures(
mempool
};

let miniblock_sealer_pool = pool_builder
let miniblock_sealer_pool = ConnectionPool::<Core>::singleton(postgres_config.master_url()?)
.build()
.await
.context("failed to build miniblock_sealer_pool")?;
Expand All @@ -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::<Core>::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,
Expand All @@ -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::<Core>::singleton(postgres_config.master_url()?)
.build()
.await
.context("failed to build mempool_fetcher_pool")?;
Expand Down
33 changes: 13 additions & 20 deletions core/lib/zksync_core/src/state_keeper/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,19 +38,17 @@ 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<Core>,
mempool: MempoolGuard,
batch_fee_input_provider: Arc<dyn BatchFeeModelInputProvider>,
output_handler: OutputHandler,
stop_receiver: watch::Receiver<bool>,
) -> (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,
);
Expand All @@ -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),
)
}