Skip to content

Commit

Permalink
feat: Separate Prover and Server DAL (#1334)
Browse files Browse the repository at this point in the history
## What ❔

* New `db_connection` crate, which contains all the main logic for
managing `ConnectionPool` and `StorageProcessor`
* Prover parts of DAL are moved to `prover_dal` crate
* Now we have typed `ConnectionPool`s and `StorageProcessor`s, to use
appropriate `ConnectionPool` there are 2 options:
`ConnectionPool<Server>`, `ConnectionPool<Prover>` - which will return
appropriate `StorageProcessor` with corresponding methods accessible
*only* by this connection pool.
* `vm_version`, `prover_dal` and part of `protocol_version` types were
moved to `basic_types` crate

Further steps:
* Add migrations for dropping tables that are not needed in databases,
done [here](#1436).
* Rename Server to Core, StorageProcessor to Connection

## Why ❔

To separate logic of prover and server. To prevent accessing wrong
database with one `ConnectionPool`.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `zk spellcheck`.
- [x] Linkcheck has been run via `zk linkcheck`.

---------

Co-authored-by: EmilLuta <EmilLuta@users.noreply.github.com>
  • Loading branch information
Artemka374 and EmilLuta committed Mar 20, 2024
1 parent c36be65 commit 103a56b
Show file tree
Hide file tree
Showing 282 changed files with 2,227 additions and 1,804 deletions.
75 changes: 65 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
# Node services
"core/node/node_framework",
# Libraries
"core/lib/db_connection",
"core/lib/zksync_core",
"core/lib/basic_types",
"core/lib/config",
Expand Down
2 changes: 2 additions & 0 deletions checks-config/era.dic
Original file line number Diff line number Diff line change
Expand Up @@ -918,3 +918,5 @@ stateful
WIP
oneshot
p2p
StorageProcessor
StorageMarker
4 changes: 2 additions & 2 deletions core/bin/block_reverter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use zksync_config::{
use zksync_core::block_reverter::{
BlockReverter, BlockReverterEthConfig, BlockReverterFlags, L1ExecutedBatchesRevert, NodeRole,
};
use zksync_dal::ConnectionPool;
use zksync_dal::{ConnectionPool, Server};
use zksync_env_config::FromEnv;
use zksync_types::{L1BatchNumber, U256};

Expand Down Expand Up @@ -96,7 +96,7 @@ async fn main() -> anyhow::Result<()> {
let postgres_config = PostgresConfig::from_env().context("PostgresConfig::from_env()")?;
let config = BlockReverterEthConfig::new(eth_sender, contracts, eth_client.web3_url.clone());

let connection_pool = ConnectionPool::builder(
let connection_pool = ConnectionPool::<Server>::builder(
postgres_config.master_url()?,
postgres_config.max_connections()?,
)
Expand Down
6 changes: 3 additions & 3 deletions core/bin/contract-verifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use zksync_config::{
configs::{ObservabilityConfig, PrometheusConfig},
ApiConfig, ContractVerifierConfig, PostgresConfig,
};
use zksync_dal::ConnectionPool;
use zksync_dal::{ConnectionPool, Server, ServerDals};
use zksync_env_config::FromEnv;
use zksync_queued_job_processor::JobProcessor;
use zksync_utils::wait_for_tasks::wait_for_tasks;
Expand All @@ -20,7 +20,7 @@ pub mod verifier;
pub mod zksolc_utils;
pub mod zkvyper_utils;

async fn update_compiler_versions(connection_pool: &ConnectionPool) {
async fn update_compiler_versions(connection_pool: &ConnectionPool<Server>) {
let mut storage = connection_pool.access_storage().await.unwrap();
let mut transaction = storage.start_transaction().await.unwrap();

Expand Down Expand Up @@ -134,7 +134,7 @@ async fn main() -> anyhow::Result<()> {
..ApiConfig::from_env().context("ApiConfig")?.prometheus
};
let postgres_config = PostgresConfig::from_env().context("PostgresConfig")?;
let pool = ConnectionPool::singleton(
let pool = ConnectionPool::<Server>::singleton(
postgres_config
.master_url()
.context("Master DB URL is absent")?,
Expand Down
10 changes: 5 additions & 5 deletions core/bin/contract-verifier/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use lazy_static::lazy_static;
use regex::Regex;
use tokio::time;
use zksync_config::ContractVerifierConfig;
use zksync_dal::{ConnectionPool, StorageProcessor};
use zksync_dal::{ConnectionPool, Server, ServerDals, StorageProcessor};
use zksync_env_config::FromEnv;
use zksync_queued_job_processor::{async_trait, JobProcessor};
use zksync_types::{
Expand Down Expand Up @@ -42,19 +42,19 @@ enum ConstructorArgs {
#[derive(Debug)]
pub struct ContractVerifier {
config: ContractVerifierConfig,
connection_pool: ConnectionPool,
connection_pool: ConnectionPool<Server>,
}

impl ContractVerifier {
pub fn new(config: ContractVerifierConfig, connection_pool: ConnectionPool) -> Self {
pub fn new(config: ContractVerifierConfig, connection_pool: ConnectionPool<Server>) -> Self {
Self {
config,
connection_pool,
}
}

async fn verify(
storage: &mut StorageProcessor<'_>,
storage: &mut StorageProcessor<'_, Server>,
mut request: VerificationRequest,
config: ContractVerifierConfig,
) -> Result<VerificationInfo, ContractVerifierError> {
Expand Down Expand Up @@ -429,7 +429,7 @@ impl ContractVerifier {
}

async fn process_result(
storage: &mut StorageProcessor<'_>,
storage: &mut StorageProcessor<'_, Server>,
request_id: usize,
verification_result: Result<VerificationInfo, ContractVerifierError>,
) {
Expand Down
3 changes: 2 additions & 1 deletion core/bin/external_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ publish = false # We don't want to publish our binaries.
[dependencies]
zksync_core = { path = "../../lib/zksync_core" }
zksync_dal = { path = "../../lib/dal" }
zksync_db_connection = { path = "../../lib/db_connection" }
zksync_config = { path = "../../lib/config" }
zksync_storage = { path = "../../lib/storage" }
zksync_utils = { path = "../../lib/utils" }
Expand All @@ -21,7 +22,7 @@ zksync_basic_types = { path = "../../lib/basic_types" }
zksync_contracts = { path = "../../lib/contracts" }
zksync_l1_contract_interface = { path = "../../lib/l1_contract_interface" }
zksync_snapshots_applier = { path = "../../lib/snapshots_applier" }
zksync_object_store = { path="../../lib/object_store" }
zksync_object_store = { path = "../../lib/object_store" }
prometheus_exporter = { path = "../../lib/prometheus_exporter" }
zksync_health_check = { path = "../../lib/health_check" }
zksync_web3_decl = { path = "../../lib/web3_decl" }
Expand Down
4 changes: 2 additions & 2 deletions core/bin/external_node/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use anyhow::Context as _;
use zksync_basic_types::{L1BatchNumber, L2ChainId};
use zksync_core::sync_layer::genesis::perform_genesis_if_needed;
use zksync_dal::ConnectionPool;
use zksync_dal::{ConnectionPool, Server, ServerDals};
use zksync_health_check::AppHealthCheck;
use zksync_object_store::ObjectStoreFactory;
use zksync_snapshots_applier::SnapshotsApplierConfig;
Expand All @@ -20,7 +20,7 @@ enum InitDecision {
}

pub(crate) async fn ensure_storage_initialized(
pool: &ConnectionPool,
pool: &ConnectionPool<Server>,
main_node_client: &HttpClient,
app_health: &AppHealthCheck,
l2_chain_id: L2ChainId,
Expand Down

0 comments on commit 103a56b

Please sign in to comment.