Skip to content

Commit

Permalink
chore: update l2 block addresses (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeapoz authored Aug 1, 2024
1 parent db3b3c2 commit a347f4b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/processor/snapshot/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl SnapshotExporter {
.database
.get_latest_l1_batch_number()?
.ok_or_eyre("no latest l1 batch number in snapshot db")?;
let l2_block_number = self.database.get_latest_l2_block_number()?.unwrap_or({
let l2_block_number = self.database.get_latest_l2_block_number()?.unwrap_or_else(|| {
tracing::warn!("WARNING: the database contains no l2 block number entry and will not be compatible with the ZKSync External Node! To export a compatible snapshot, please let the prepare-snapshot command run until an l2 block number can be found.");
U64::from(0)
});
Expand Down
5 changes: 3 additions & 2 deletions src/processor/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use blake2::{Blake2s256, Digest};
use ethers::types::{Address, H256, U256, U64};
use eyre::Result;
use state_reconstruct_fetcher::{
constants::{ethereum, storage, zksync::L2_BLOCK_NUMBER_ADDRESS},
constants::{ethereum, storage, zksync::L2_BLOCK_NUMBER_ADDRESSES},
types::CommitBlock,
};
use state_reconstruct_storage::{
Expand Down Expand Up @@ -97,7 +97,8 @@ impl Processor for SnapshotBuilder {
.expect("failed to get key from database");

// We make sure to track writes to the L2 block number address.
if hex::encode(key) == L2_BLOCK_NUMBER_ADDRESS {
let hex_key = hex::encode(key);
if L2_BLOCK_NUMBER_ADDRESSES.contains(&hex_key.as_ref()) {
let (block_number, _timestamp) = unpack_block_info(h256_to_u256(value));
self.database
.set_latest_l2_block_number(block_number)
Expand Down
9 changes: 6 additions & 3 deletions state-reconstruct-fetcher/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ pub mod zksync {
/// The number of trailing bytes to ignore when using calldata post-blobs. Contains unused blob commitments.
pub const CALLDATA_SOURCE_TAIL_SIZE: usize = 32;

/// The storage address where the latest L2 block number is written to.
pub const L2_BLOCK_NUMBER_ADDRESS: &str =
"5e5a67d1b864c576f39bb2b77c6537744c0f03515abce63b473bb7c56ad07d8e";
/// NOTE: There could be more but this covers a good chunk.
/// The storage addresses where the latest L2 block number is written to.
pub const L2_BLOCK_NUMBER_ADDRESSES: [&str; 2] = [
"5e5a67d1b864c576f39bb2b77c6537744c0f03515abce63b473bb7c56ad07d8e",
"ecfc4e86b2e01c263feada4f8f53d2dab45c66b0f4d1d7ab0f2f8ec32f207c48",
];
}

0 comments on commit a347f4b

Please sign in to comment.