Skip to content

Commit

Permalink
passing all integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomg10 committed Nov 17, 2024
1 parent 437a1ac commit fc5dc6a
Show file tree
Hide file tree
Showing 129 changed files with 856 additions and 3,632 deletions.
19 changes: 19 additions & 0 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 = [
"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
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
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
85 changes: 85 additions & 0 deletions core/bin/local_blobs_dump/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use std::path::PathBuf;

use anyhow::Context;
use clap::Parser;
use zksync_config::{
configs::{object_store::ObjectStoreMode, GeneralConfig},
ObjectStoreConfig,
};
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::{serialize_using_bincode, Bucket, ObjectStoreFactory, StoredObject};
use zksync_types::{eth_sender::EthTxBlobSidecar, H512};

#[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(())
}
12 changes: 12 additions & 0 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use zksync_node_framework::{
base_token_ratio_persister::BaseTokenRatioPersisterLayer,
base_token_ratio_provider::BaseTokenRatioProviderLayer, ExternalPriceApiLayer,
},
blob_client::BlobClientLayer,
circuit_breaker_checker::CircuitBreakerCheckerLayer,
commitment_generator::CommitmentGeneratorLayer,
consensus::MainNodeConsensusLayer,
Expand Down Expand Up @@ -203,6 +204,11 @@ impl MainNodeBuilder {
Ok(self)
}

fn add_blob_client_layer(mut self) -> anyhow::Result<Self> {
self.node.add_layer(BlobClientLayer::new());
Ok(self)
}

fn add_l1_batch_commitment_mode_validation_layer(mut self) -> anyhow::Result<Self> {
let layer = L1BatchCommitmentModeValidationLayer::new(
self.contracts_config.diamond_proxy_addr,
Expand Down Expand Up @@ -644,7 +650,10 @@ impl MainNodeBuilder {
pub fn only_genesis(mut self) -> anyhow::Result<ZkStackService> {
self = self
.add_pools_layer()?
.add_object_store_layer()?
.add_blob_client_layer()?
.add_query_eth_client_layer()?
.add_healthcheck_layer()?
.add_storage_initialization_layer(LayerKind::Task, false)?;

Ok(self.node.build())
Expand All @@ -653,6 +662,8 @@ impl MainNodeBuilder {
pub fn only_l1_recovery(mut self) -> anyhow::Result<ZkStackService> {
self = self
.add_pools_layer()?
.add_object_store_layer()?
.add_blob_client_layer()?
.add_query_eth_client_layer()?
.add_healthcheck_layer()?
.add_storage_initialization_layer(LayerKind::Task, true)?;
Expand All @@ -667,6 +678,7 @@ impl MainNodeBuilder {
.add_sigint_handler_layer()?
.add_pools_layer()?
.add_object_store_layer()?
.add_blob_client_layer()?
.add_circuit_breaker_checker_layer()?
.add_healthcheck_layer()?
.add_prometheus_exporter_layer()?
Expand Down

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

5 changes: 3 additions & 2 deletions core/lib/dal/src/eth_sender_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use zksync_db_connection::{connection::Connection, interpolate_query, match_quer
use zksync_types::{
aggregated_operations::AggregatedActionType,
eth_sender::{EthTx, EthTxBlobSidecar, TxHistory, TxHistoryToSend},
Address, L1BatchNumber, H256, U256,
Address, L1BatchNumber, H160, H256, U256,
};

use crate::{
Expand Down Expand Up @@ -490,8 +490,9 @@ impl EthSenderDal<'_, '_> {
// Insert general tx descriptor.
let eth_tx_id = sqlx::query_scalar!(
"INSERT INTO eth_txs (raw_tx, nonce, tx_type, contract_address, predicted_gas_cost, created_at, updated_at) \
VALUES ('\\x00', 0, $1, '', 0, now(), now()) \
VALUES ('\\x00', 0, $1, $2, 0, now(), now()) \
RETURNING id",
format!("{:#x}", H160::zero()),
tx_type.to_string()
)
.fetch_one(transaction.conn())
Expand Down
22 changes: 1 addition & 21 deletions core/lib/mempool/src/mempool_store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
cmp::min,
collections::{hash_map, BTreeSet, HashMap},
};
use std::collections::{hash_map, BTreeSet, HashMap};

use zksync_types::{
l1::L1Tx, l2::L2Tx, Address, ExecuteTransactionCommon, Nonce, PriorityOpId, Transaction,
Expand Down Expand Up @@ -60,7 +57,6 @@ impl MempoolStore {
transactions: Vec<Transaction>,
initial_nonces: HashMap<Address, Nonce>,
) {
let mut min_next_priority_id = None;
for transaction in transactions {
let Transaction {
common_data,
Expand All @@ -70,17 +66,6 @@ impl MempoolStore {
} = transaction;
match common_data {
ExecuteTransactionCommon::L1(data) => {
tracing::info!(
"inserting L1 transaction {}, current next_priority_id is {}",
data.serial_id,
self.next_priority_id
);
if min_next_priority_id.is_none() {
min_next_priority_id = Some(data.serial_id);
} else {
min_next_priority_id =
Some(min(min_next_priority_id.unwrap(), data.serial_id));
}
self.l1_transactions.insert(
data.serial_id,
L1Tx {
Expand All @@ -107,11 +92,6 @@ impl MempoolStore {
}
}
}
if let Some(min_next_priority_id) = min_next_priority_id {
if self.next_priority_id == PriorityOpId(0) {
self.next_priority_id = min_next_priority_id;
}
}
}

fn insert_l2_transaction(
Expand Down
2 changes: 2 additions & 0 deletions core/lib/object_store/src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub enum Bucket {
StorageSnapshot,
DataAvailability,
VmDumps,
LocalBlobs,
}

impl Bucket {
Expand All @@ -39,6 +40,7 @@ impl Bucket {
Self::StorageSnapshot => "storage_logs_snapshots",
Self::DataAvailability => "data_availability",
Self::VmDumps => "vm_dumps",
Self::LocalBlobs => "local_blobs",
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions core/lib/vm_executor/src/oneshot/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,6 @@ async fn load_l2_block_info(
prev_block_hash = snapshot_recovery.and_then(|recovery| {
(recovery.l2_block_number == prev_block_number).then_some(recovery.l2_block_hash)
});
if prev_block_hash.is_none() {
prev_block_hash = Some(
H256::from_str(
&"0x3259078d280da94b303592f6640e70c723c24018ab6d592a45931477e6645ab5",
)
.unwrap(),
);
}
}

current_block = Some(prev_l2_block);
Expand Down
2 changes: 1 addition & 1 deletion core/lib/vm_interface/src/types/outputs/l2_block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use zksync_types::H256;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct L2Block {
pub number: u32,
pub timestamp: u64,
Expand Down
12 changes: 11 additions & 1 deletion core/node/block_reverter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,18 @@ impl BlockReverter {
eth_client: &dyn BoundEthInterface,
eth_config: &BlockReverterEthConfig,
last_l1_batch_to_keep: L1BatchNumber,
nonce: u64,
nonce: Option<u64>,
) -> anyhow::Result<()> {
let nonce = if let Some(nonce) = nonce {
nonce
} else {
eth_client
.nonce_at(BlockNumber::Latest)
.await
.context("cannot get nonce")?
.as_u64()
};

tracing::info!(
"Sending Ethereum revert transaction for L1 batch #{last_l1_batch_to_keep} with config {eth_config:?}, \
nonce: {nonce}"
Expand Down
96 changes: 48 additions & 48 deletions core/node/l1_recovery/InitialStateV25.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions core/node/l1_recovery/prepare_initial_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import psycopg2
import csv

chain_name = "Local"
chain_name = "V25"
# Connect to PostgreSQL
conn = psycopg2.connect(
dbname="zksync_server_localhost_era",
Expand Down Expand Up @@ -32,7 +32,8 @@ def format_binary_data(value):
factory_deps_query = """
SELECT bytecode_hash, bytecode
FROM factory_deps
WHERE miniblock_number = 0;
WHERE miniblock_number = 0
ORDER BY bytecode_hash;
"""


Expand Down
8 changes: 8 additions & 0 deletions core/node/l1_recovery/recover_main_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
clear
cd ../../..
cargo run --bin local_blobs_dump --release -- \
--config-path chains/era/configs/general.yaml \
--secrets-path chains/era/configs/secrets.yaml
zkstack dev db reset
rm -rf chains/era/db/main
zkstack server --l1-recovery --verbose
Loading

0 comments on commit fc5dc6a

Please sign in to comment.