This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
forked from matter-labs/zksync-era
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(en): Parallelize persistence and chunk processing during tree re…
…covery (matter-labs#2050) ## What ❔ Persists chunks during tree recovery in parallel to processing subsequent chunks. ## Why ❔ - Could speed up tree recovery ~2x on the mainnet (both persistence and processing of a single chunk of 200k entries take ~3s). - Significantly easier to implement and reason about than alternatives. - May be used together with alternatives. ## Checklist - [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`.
- Loading branch information
Showing
15 changed files
with
956 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use super::*; | ||
use crate::{hasher::HasherWithStats, types::LeafNode, MerkleTree}; | ||
|
||
#[test] | ||
fn recovery_for_initialized_tree() { | ||
let mut db = PatchSet::default(); | ||
MerkleTreeRecovery::new(&mut db, 123) | ||
.unwrap() | ||
.finalize() | ||
.unwrap(); | ||
let err = MerkleTreeRecovery::new(db, 123).unwrap_err().to_string(); | ||
assert!( | ||
err.contains("Tree is expected to be in the process of recovery"), | ||
"{err}" | ||
); | ||
} | ||
|
||
#[test] | ||
fn recovery_for_different_version() { | ||
let mut db = PatchSet::default(); | ||
MerkleTreeRecovery::new(&mut db, 123).unwrap(); | ||
let err = MerkleTreeRecovery::new(&mut db, 42) | ||
.unwrap_err() | ||
.to_string(); | ||
assert!( | ||
err.contains("Requested to recover tree version 42"), | ||
"{err}" | ||
); | ||
} | ||
|
||
#[test] | ||
fn recovering_empty_tree() { | ||
let db = MerkleTreeRecovery::new(PatchSet::default(), 42) | ||
.unwrap() | ||
.finalize() | ||
.unwrap(); | ||
let tree = MerkleTree::new(db).unwrap(); | ||
assert_eq!(tree.latest_version(), Some(42)); | ||
assert_eq!(tree.root(42), Some(Root::Empty)); | ||
} | ||
|
||
#[test] | ||
fn recovering_tree_with_single_node() { | ||
let mut recovery = MerkleTreeRecovery::new(PatchSet::default(), 42).unwrap(); | ||
let recovery_entry = TreeEntry::new(Key::from(123), 1, ValueHash::repeat_byte(1)); | ||
recovery.extend_linear(vec![recovery_entry]).unwrap(); | ||
let tree = MerkleTree::new(recovery.finalize().unwrap()).unwrap(); | ||
|
||
assert_eq!(tree.latest_version(), Some(42)); | ||
let mut hasher = HasherWithStats::new(&Blake2Hasher); | ||
assert_eq!( | ||
tree.latest_root_hash(), | ||
LeafNode::new(recovery_entry).hash(&mut hasher, 0) | ||
); | ||
tree.verify_consistency(42, true).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.