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

feat: Snapshot Creator #498

Merged
merged 43 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
872985f
feat: Snapshot Creator
tomg10 Nov 15, 2023
f9344e9
fix: fmt and lint
tomg10 Nov 15, 2023
10e3a14
fix: remove slow ORDER BY
tomg10 Nov 15, 2023
48c8e92
fix: fix ambiguous column name
tomg10 Nov 15, 2023
6b9a107
fix: lint
tomg10 Nov 15, 2023
cd38cd1
fix: lint
tomg10 Nov 15, 2023
465b7c7
fix: ignore snapshots-creator integration test when running external …
tomg10 Nov 15, 2023
f82c13b
feat: better logs
tomg10 Nov 15, 2023
b8c2a19
feat: PR feedback vol. 1
tomg10 Nov 16, 2023
883e394
feat: PR feedback vol. 2
tomg10 Nov 16, 2023
f04ed5f
feat: PR feedback vol. 3
tomg10 Nov 16, 2023
2bd4a53
fix: lint
tomg10 Nov 16, 2023
cf17e93
feat: print lint version
tomg10 Nov 17, 2023
58206cb
fix: fmt
tomg10 Nov 17, 2023
96d8c30
feat: more info when running lint
tomg10 Nov 17, 2023
b0a4bf0
fix: another PR feedback (more to come)
tomg10 Nov 27, 2023
1540abf
fix: next round of PR feedback
tomg10 Nov 27, 2023
8faa706
fix: remove debug
tomg10 Nov 27, 2023
433af83
fix: format sql
tomg10 Nov 27, 2023
52037ba
fix: final round of PR feedback
tomg10 Nov 27, 2023
4bc7d96
fix: lint
tomg10 Nov 27, 2023
45751d4
fix: fmt
tomg10 Nov 27, 2023
72f6e87
feat: small refactor
tomg10 Nov 27, 2023
055fc84
fix: removed bytecode_hash from SnapshotFactoryDependency
tomg10 Nov 28, 2023
63d280c
feat: make queries parallel
tomg10 Dec 4, 2023
f051d6a
fix: zk fmt
tomg10 Dec 4, 2023
d9895f5
fix: PR feedback
tomg10 Dec 4, 2023
c4081a4
fix: PR feedback
tomg10 Dec 5, 2023
3f98233
fix: PR feedback
tomg10 Dec 5, 2023
aa75ef7
fix: PR feedback
tomg10 Dec 5, 2023
ed0f6ec
fix: remove import
tomg10 Dec 5, 2023
c202ec5
fix: invalid variable name fix
tomg10 Dec 5, 2023
c02223a
fix: remove unwrap()
tomg10 Dec 6, 2023
c822280
fix: PR feedback
tomg10 Dec 6, 2023
700018d
fix: PR feedback
tomg10 Dec 6, 2023
633951b
fix: PR feedback
tomg10 Dec 7, 2023
45f37a9
fix: PR feedback
tomg10 Dec 8, 2023
8df22d0
fix: zk fmt
tomg10 Dec 8, 2023
a827d72
fix: made SNAPSHOTS namespace disabled for EN
tomg10 Dec 8, 2023
a0f8974
fix: added snapshots namespace to ws as well
tomg10 Dec 8, 2023
d312888
fix: removed SNAPSHOTS and DEBUG groups of namespaces
tomg10 Dec 8, 2023
4be8699
fix: update sqlx-data.json
tomg10 Dec 8, 2023
81300dd
fix: bash -> sh
tomg10 Dec 11, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ jobs:

# TODO(PLA-653): Restore bridge tests for EN.
- name: Integration tests
run: ci_run zk test i server --testPathIgnorePatterns 'contract-verification|custom-erc20-bridge'
run: ci_run zk test i server --testPathIgnorePatterns 'contract-verification|custom-erc20-bridge|snapshots-creator'

- name: Run Cross EN Checker
run: ci_run zk run cross-en-checker
Expand Down
24 changes: 24 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 @@ -6,6 +6,7 @@ members = [
"core/bin/external_node",
"core/bin/merkle_tree_consistency_checker",
"core/bin/rocksdb_util",
"core/bin/snapshots_creator",
"core/bin/storage_logs_dedup_migration",
"core/bin/system-constants-generator",
"core/bin/verification_key_generator_and_server",
Expand Down
2 changes: 1 addition & 1 deletion core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl OptionalENConfig {
pub fn api_namespaces(&self) -> Vec<Namespace> {
self.api_namespaces
.clone()
.unwrap_or_else(|| Namespace::NON_DEBUG.to_vec())
.unwrap_or_else(|| Namespace::DEFAULT.to_vec())
}

pub fn max_response_body_size(&self) -> usize {
Expand Down
30 changes: 30 additions & 0 deletions core/bin/snapshots_creator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "snapshots_creator"
version = "0.1.0"
edition = "2021"
authors = ["The Matter Labs Team <[email protected]>"]
homepage = "https://zksync.io/"
repository = "https://github.com/matter-labs/zksync-era"
license = "MIT OR Apache-2.0"
keywords = ["blockchain", "zksync"]
categories = ["cryptography"]
publish = false # We don't want to publish our binaries.

[dependencies]
vise = { git = "https://github.com/matter-labs/vise.git", version = "0.1.0", rev = "dd05139b76ab0843443ab3ff730174942c825dae" }
prometheus_exporter = { path = "../../lib/prometheus_exporter" }
zksync_config = { path = "../../lib/config" }
zksync_dal = { path = "../../lib/dal" }
zksync_env_config = { path = "../../lib/env_config" }
zksync_utils = { path = "../../lib/utils" }
zksync_types = { path = "../../lib/types" }
zksync_core = { path = "../../lib/zksync_core" }
zksync_object_store = { path = "../../lib/object_store" }
vlog = { path = "../../lib/vlog" }

anyhow = "1.0"
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
futures = "0.3"
serde = { version = "1.0.189", features = ["derive"] }
serde_json = "1.0"
24 changes: 24 additions & 0 deletions core/bin/snapshots_creator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Snapshots Creator

Snapshot creator is small command line tool for creating a snapshot of zkSync node for EN node to be able to initialize
to a certain L1 Batch.

Snapshots do not contain full transactions history, but rather a minimal subset of information needed to bootstrap EN
node.

Usage (local development):\
First run `zk env dev` \
then the creator can be run using:
`zk run snapshots_creator`

Snapshot contents can be stored based on blob_store config either in local filesystem or GS.

## Snapshots format

Each snapshot consists of three types of objects (see
[snapshots.rs](https://github.com/matter-labs/zksync-era/blob/main/core/lib/types/src/snapshots.rs)) : header, storage
logs chunks and factory deps:

- Snapshot Header (currently returned by snapshots namespace of JSON-RPC API)
- Snapshot Storage logs chunks (most likely to be stored in gzipped protobuf files, but this part is still WIP) :
- Factory dependencies (most likely to be stored as protobufs in the very near future)
22 changes: 22 additions & 0 deletions core/bin/snapshots_creator/src/chunking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::ops;

use zksync_types::{H256, U256};
use zksync_utils::u256_to_h256;

pub fn get_chunk_hashed_keys_range(chunk_id: u64, chunks_count: u64) -> ops::RangeInclusive<H256> {
assert!(chunks_count > 0);
let mut stride = U256::MAX / chunks_count;
let stride_minus_one = if stride < U256::MAX {
stride += U256::one();
stride - 1
} else {
stride // `stride` is really 1 << 256 == U256::MAX + 1
};

let start = stride * chunk_id;
let (mut end, is_overflow) = stride_minus_one.overflowing_add(start);
if is_overflow {
end = U256::MAX;
}
u256_to_h256(start)..=u256_to_h256(end)
}
Loading