Skip to content
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"core/bin/zksync_server",
"core/bin/genesis_generator",
"core/bin/zksync_tee_prover",
"core/bin/local_blobs_dump",
# Node services
"core/node/node_framework",
"core/node/proof_data_handler",
Expand Down Expand Up @@ -76,6 +77,7 @@ members = [
"core/lib/crypto_primitives",
"core/lib/external_price_api",
"core/lib/test_contracts",
"core/node/l1_recovery",
# Test infrastructure
"core/tests/loadnext",
"core/tests/vm-benchmark",
Expand Down Expand Up @@ -120,6 +122,8 @@ ctrlc = "3.1"
dashmap = "5.5.3"
derive_more = "1.0.0"
envy = "0.4"
indexmap = { version = "2.0.2", features = ["serde"] }
zkevm_circuits = "=0.150.7"
ethabi = "18.0.0"
flate2 = "1.0.28"
fraction = "0.15.3"
Expand Down Expand Up @@ -177,7 +181,7 @@ structopt = "0.3.20"
strum = "0.26"
tempfile = "3.0.2"
test-casing = "0.1.2"
test-log = "0.2.15"
test-log = { version = "0.2.15", features = ["trace"] }
thiserror = "1"
thread_local = "1.1"
tikv-jemallocator = "0.5"
Expand Down Expand Up @@ -323,3 +327,4 @@ zksync_contract_verification_server = { version = "0.1.0", path = "core/node/con
zksync_node_api_server = { version = "0.1.0", path = "core/node/api_server" }
zksync_base_token_adjuster = { version = "0.1.0", path = "core/node/base_token_adjuster" }
zksync_logs_bloom_backfill = { version = "0.1.0", path = "core/node/logs_bloom_backfill" }
zksync_l1_recovery = { version = "0.1.0", path = "core/node/l1_recovery" }
2 changes: 1 addition & 1 deletion core/bin/block_reverter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ enum Command {
priority_fee_per_gas: Option<u64>,
/// Nonce used for reverting Ethereum transaction.
#[arg(long)]
nonce: u64,
nonce: Option<u64>,
},

/// Rolls back internal database state to a previous L1 batch.
Expand Down
9 changes: 9 additions & 0 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ pub(crate) struct OptionalENConfig {
/// This is an experimental and incomplete feature; do not use unless you know what you're doing.
#[serde(default)]
pub snapshots_recovery_enabled: bool,

/// Maximum concurrency factor for the concurrent parts of snapshot recovery for Postgres. It may be useful to
/// reduce this factor to about 5 if snapshot recovery overloads I/O capacity of the node. Conversely,
/// if I/O capacity of your infra is high, you may increase concurrency to speed up Postgres recovery.
Expand Down Expand Up @@ -1116,6 +1117,8 @@ pub(crate) struct ExperimentalENConfig {
// Snapshot recovery
/// L1 batch number of the snapshot to use during recovery. Specifying this parameter is mostly useful for testing.
pub snapshots_recovery_l1_batch: Option<L1BatchNumber>,
#[serde(default)]
pub snapshots_recovery_recover_from_l1: bool,
/// Enables dropping storage key preimages when recovering storage logs from a snapshot with version 0.
/// This is a temporary flag that will eventually be removed together with version 0 snapshot support.
#[serde(default)]
Expand Down Expand Up @@ -1160,6 +1163,7 @@ impl ExperimentalENConfig {
snapshots_recovery_tree_chunk_size: Self::default_snapshots_recovery_tree_chunk_size(),
snapshots_recovery_tree_parallel_persistence_buffer: None,
commitment_generator_max_parallelism: None,
snapshots_recovery_recover_from_l1: false,
}
}

Expand Down Expand Up @@ -1197,6 +1201,11 @@ impl ExperimentalENConfig {
.commitment_generator
.as_ref()
.map(|a| a.max_parallelism),
snapshots_recovery_recover_from_l1: general_config
.snapshot_recovery
.as_ref()
.map(|a| a.recover_from_l1)
.unwrap_or_default(),
})
}
}
Expand Down
14 changes: 14 additions & 0 deletions core/bin/external_node/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use zksync_node_api_server::web3::Namespace;
use zksync_node_framework::{
implementations::layers::{
batch_status_updater::BatchStatusUpdaterLayer,
blob_client::{BlobClientLayer, BlobClientMode},
block_reverter::BlockReverterLayer,
commitment_generator::CommitmentGeneratorLayer,
consensus::ExternalNodeConsensusLayer,
Expand Down Expand Up @@ -523,6 +524,15 @@ impl ExternalNodeBuilder {
Ok(self)
}

fn add_blob_client_layer(mut self) -> anyhow::Result<Self> {
let layer = BlobClientLayer {
mode: BlobClientMode::Blobscan,
blobscan_url: Some("https://api.sepolia.blobscan.com/blobs/".to_string()),
};
self.node.add_layer(layer);
Ok(self)
}

/// This layer will make sure that the database is initialized correctly,
/// e.g.:
/// - genesis or snapshot recovery will be performed if it's required.
Expand All @@ -543,11 +553,13 @@ impl ExternalNodeBuilder {
.optional
.snapshots_recovery_enabled
.then_some(SnapshotRecoveryConfig {
recover_from_l1: config.experimental.snapshots_recovery_recover_from_l1,
snapshot_l1_batch_override: config.experimental.snapshots_recovery_l1_batch,
drop_storage_key_preimages: config
.experimental
.snapshots_recovery_drop_storage_key_preimages,
object_store_config: config.optional.snapshots_recovery_object_store.clone(),
recover_main_node_components: false,
});
self.node.add_layer(ExternalNodeInitStrategyLayer {
l2_chain_id: self.config.required.l2_chain_id,
Expand All @@ -556,6 +568,7 @@ impl ExternalNodeBuilder {
.optional
.snapshots_recovery_postgres_max_concurrency,
snapshot_recovery_config,
diamond_proxy_addr: self.config.diamond_proxy_address(),
});
let mut layer = NodeStorageInitializerLayer::new();
if matches!(kind, LayerKind::Precondition) {
Expand All @@ -572,6 +585,7 @@ impl ExternalNodeBuilder {
.add_healthcheck_layer()?
.add_prometheus_exporter_layer()?
.add_pools_layer()?
.add_blob_client_layer()?
.add_main_node_client_layer()?
.add_query_eth_client_layer()?
.add_reorg_detector_layer()?;
Expand Down
26 changes: 26 additions & 0 deletions core/bin/local_blobs_dump/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "local_blobs_dump"
version = "0.1.0"
edition.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true
keywords.workspace = true
categories.workspace = true
publish = false

[dependencies]
tokio.workspace = true
anyhow.workspace = true
clap.workspace = true
tracing.workspace = true
hex.workspace = true
zksync_object_store.workspace = true

zksync_dal.workspace = true
zksync_core_leftovers.workspace = true
zksync_protobuf_config.workspace = true
zksync_types.workspace = true
zksync_config.workspace = true
zksync_l1_recovery.workspace = true
81 changes: 81 additions & 0 deletions core/bin/local_blobs_dump/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use std::path::PathBuf;

use anyhow::Context;
use clap::Parser;
use zksync_core_leftovers::temp_config_store::read_yaml_repr;
use zksync_dal::{ConnectionPool, Core, CoreDal};
use zksync_l1_recovery::{BlobKey, BlobWrapper};
use zksync_object_store::ObjectStoreFactory;
use zksync_types::eth_sender::EthTxBlobSidecar;

#[derive(Debug, Parser)]
#[command(author, version, about, long_about)]
struct Cli {
#[arg(long, global = true)]
secrets_path: PathBuf,

#[arg(long, global = true)]
config_path: PathBuf,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let opts = Cli::parse();
let secrets_config =
read_yaml_repr::<zksync_protobuf_config::proto::secrets::Secrets>(&opts.secrets_path)
.context("failed decoding secrets YAML config")?;
let database_secrets = secrets_config
.database
.clone()
.context("Failed to find database config")?;

let connection_pool = ConnectionPool::<Core>::singleton(database_secrets.master_url()?)
.build()
.await
.context("failed to build a connection pool")?;

let general_config =
read_yaml_repr::<zksync_protobuf_config::proto::general::GeneralConfig>(&opts.config_path)
.context("failed decoding general YAML config")?;
let object_store_config = general_config
.snapshot_recovery
.unwrap()
.object_store
.context("failed to find core object store config")?;
let object_store = ObjectStoreFactory::new(object_store_config)
.create_store()
.await?;

let mut id = 1;
loop {
let mut storage = connection_pool.connection().await.unwrap();
let tx = storage.eth_sender_dal().get_eth_tx(id).await.unwrap();
id += 1;
if tx.is_none() {
break;
}

if let Some(blob_sidecar) = tx.unwrap().blob_sidecar {
match blob_sidecar {
EthTxBlobSidecar::EthTxBlobSidecarV1(sidecar) => {
for blob in sidecar.blobs {
object_store
.put(
BlobKey {
kzg_commitment: blob
.commitment
.try_into()
.expect("unable to convert kzg_commitment to [u8; 48]"),
},
&BlobWrapper { blob: blob.blob },
)
.await?;
}
}
}
}
}

println!("Finished dumping blobs");
Ok(())
}
1 change: 1 addition & 0 deletions core/bin/zksync_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ zksync_types.workspace = true
zksync_core_leftovers.workspace = true
zksync_node_genesis.workspace = true
zksync_da_clients.workspace = true
zksync_block_reverter.workspace = true

# Consensus dependenices
zksync_consensus_crypto.workspace = true
Expand Down
8 changes: 8 additions & 0 deletions core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ struct Cli {
/// Generate genesis block for the first contract deployment using temporary DB.
#[arg(long)]
genesis: bool,
#[arg(long)]
l1_recovery: bool,
/// Comma-separated list of components to launch.
#[arg(
long,
Expand Down Expand Up @@ -150,6 +152,12 @@ fn main() -> anyhow::Result<()> {
return Ok(());
}

if opt.l1_recovery {
// If genesis is requested, we don't need to run the node.
node.only_l1_recovery()?.run(observability_guard)?;
return Ok(());
}

node.build(opt.components.0)?.run(observability_guard)?;
Ok(())
}
Expand Down
Loading