Skip to content

Commit

Permalink
refactor: Rename miniblock to l2 block – base + state keeper (#1696)
Browse files Browse the repository at this point in the history
## What ❔

Renames "miniblock" to "L2 block" in types, DAL and state keeper.

## Why ❔

- "Miniblock" is an internal term that is somewhat difficult to
understand; "L2 block" is better in this regard.
- It makes sense for renaming to be complete (i.e., not only concern
logs, but also the codebase), so that naming is reasonably consistent.

## 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`.
- [x] Linkcheck has been run via `zk linkcheck`.
  • Loading branch information
slowli authored Apr 18, 2024
1 parent 13bfecc commit 178a018
Show file tree
Hide file tree
Showing 140 changed files with 2,318 additions and 2,409 deletions.
12 changes: 6 additions & 6 deletions core/bin/external_node/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use test_casing::test_casing;
use zksync_basic_types::protocol_version::ProtocolVersionId;
use zksync_core::genesis::{insert_genesis_batch, GenesisParams};
use zksync_eth_client::clients::MockEthereum;
use zksync_types::{api, ethabi, fee_model::FeeParams, L1BatchNumber, MiniblockNumber, H256};
use zksync_types::{api, ethabi, fee_model::FeeParams, L1BatchNumber, L2BlockNumber, H256};
use zksync_web3_decl::client::{BoxedL2Client, MockL2Client};

use super::*;
Expand Down Expand Up @@ -101,20 +101,20 @@ async fn external_node_basics(components_str: &'static str) {
let _guard = vlog::ObservabilityBuilder::new().build(); // Enable logging to simplify debugging
let temp_dir = tempfile::TempDir::new().unwrap();

// Simplest case to mock: the EN already has a genesis L1 batch / miniblock, and it's the only L1 batch / miniblock
// Simplest case to mock: the EN already has a genesis L1 batch / L2 block, and it's the only L1 batch / L2 block
// in the network.
let connection_pool = ConnectionPool::test_pool().await;
let singleton_pool_builder = ConnectionPool::singleton(connection_pool.database_url());
let mut storage = connection_pool.connection().await.unwrap();
let genesis_params = insert_genesis_batch(&mut storage, &GenesisParams::mock())
.await
.unwrap();
let genesis_miniblock = storage
let genesis_l2_block = storage
.blocks_dal()
.get_miniblock_header(MiniblockNumber(0))
.get_l2_block_header(L2BlockNumber(0))
.await
.unwrap()
.expect("No genesis miniblock");
.expect("No genesis L2 block");
drop(storage);

let components: ComponentsToRun = components_str.parse().unwrap();
Expand Down Expand Up @@ -149,7 +149,7 @@ async fn external_node_basics(components_str: &'static str) {
assert_eq!(number, api::BlockNumber::Number(0.into()));
Ok(serde_json::to_value(
api::Block::<api::TransactionVariant> {
hash: genesis_miniblock.hash,
hash: genesis_l2_block.hash,
..api::Block::default()
},
)?)
Expand Down
12 changes: 6 additions & 6 deletions core/bin/external_node/src/version_sync_task.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::cmp::Ordering;

use anyhow::Context;
use zksync_basic_types::{L1BatchNumber, MiniblockNumber};
use zksync_basic_types::{L1BatchNumber, L2BlockNumber};
use zksync_dal::{ConnectionPool, Core, CoreDal};
use zksync_types::ProtocolVersionId;
use zksync_web3_decl::{
Expand All @@ -20,7 +20,7 @@ pub async fn get_l1_batch_remote_protocol_version(
return Ok(None);
};
let sync_block = main_node_client
.sync_l2_block(MiniblockNumber(miniblock.as_u32()), false)
.sync_l2_block(L2BlockNumber(miniblock.as_u32()), false)
.await?;
Ok(sync_block.map(|b| b.protocol_version))
}
Expand Down Expand Up @@ -66,7 +66,7 @@ pub async fn sync_versions(
let mid_batch = L1BatchNumber((left_bound.0 + right_bound.0) / 2);
let (mid_miniblock, _) = connection
.blocks_dal()
.get_miniblock_range_of_l1_batch(mid_batch)
.get_l2_block_range_of_l1_batch(mid_batch)
.await?
.with_context(|| {
format!("Postgres is inconsistent: missing miniblocks for L1 batch #{mid_batch}")
Expand All @@ -93,7 +93,7 @@ pub async fn sync_versions(
let remote_first_v22_l1_batch = left_bound;
let (remote_first_v22_miniblock, _) = connection
.blocks_dal()
.get_miniblock_range_of_l1_batch(remote_first_v22_l1_batch)
.get_l2_block_range_of_l1_batch(remote_first_v22_l1_batch)
.await?
.with_context(|| {
format!("Postgres is inconsistent: missing miniblocks for L1 batch #{remote_first_v22_l1_batch}")
Expand All @@ -114,7 +114,7 @@ pub async fn sync_versions(

let (local_first_v22_miniblock, _) = transaction
.blocks_dal()
.get_miniblock_range_of_l1_batch(local_first_v22_l1_batch)
.get_l2_block_range_of_l1_batch(local_first_v22_l1_batch)
.await?
.with_context(|| {
format!("Postgres is inconsistent: missing miniblocks for L1 batch #{local_first_v22_l1_batch}")
Expand All @@ -123,7 +123,7 @@ pub async fn sync_versions(
tracing::info!("Setting version 22 for miniblocks {remote_first_v22_miniblock}..={local_first_v22_miniblock}");
transaction
.blocks_dal()
.reset_protocol_version_for_miniblocks(
.reset_protocol_version_for_l2_blocks(
remote_first_v22_miniblock..=local_first_v22_miniblock,
ProtocolVersionId::Version22,
)
Expand Down
22 changes: 11 additions & 11 deletions core/bin/snapshots_creator/src/creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use zksync_types::{
uniform_hashed_keys_chunk, SnapshotFactoryDependencies, SnapshotFactoryDependency,
SnapshotMetadata, SnapshotStorageLogsChunk, SnapshotStorageLogsStorageKey, SnapshotVersion,
},
L1BatchNumber, MiniblockNumber,
L1BatchNumber, L2BlockNumber,
};

use crate::metrics::{FactoryDepsStage, StorageChunkStage, METRICS};
Expand Down Expand Up @@ -76,7 +76,7 @@ impl SnapshotCreator {
async fn process_storage_logs_single_chunk(
&self,
semaphore: &Semaphore,
miniblock_number: MiniblockNumber,
l2_block_number: L2BlockNumber,
l1_batch_number: L1BatchNumber,
chunk_id: u64,
chunk_count: u64,
Expand All @@ -94,7 +94,7 @@ impl SnapshotCreator {
METRICS.storage_logs_processing_duration[&StorageChunkStage::LoadFromPostgres].start();
let logs = conn
.snapshots_creator_dal()
.get_storage_logs_chunk(miniblock_number, l1_batch_number, hashed_keys_range)
.get_storage_logs_chunk(l2_block_number, l1_batch_number, hashed_keys_range)
.await
.context("Error fetching storage logs count")?;
drop(conn);
Expand Down Expand Up @@ -143,7 +143,7 @@ impl SnapshotCreator {

async fn process_factory_deps(
&self,
miniblock_number: MiniblockNumber,
l2_block_number: L2BlockNumber,
l1_batch_number: L1BatchNumber,
) -> anyhow::Result<String> {
let mut conn = self.connect_to_replica().await?;
Expand All @@ -153,7 +153,7 @@ impl SnapshotCreator {
METRICS.factory_deps_processing_duration[&FactoryDepsStage::LoadFromPostgres].start();
let factory_deps = conn
.snapshots_creator_dal()
.get_all_factory_deps(miniblock_number)
.get_all_factory_deps(l2_block_number)
.await?;
drop(conn);
let latency = latency.observe();
Expand Down Expand Up @@ -293,23 +293,23 @@ impl SnapshotCreator {
};

let mut conn = self.connect_to_replica().await?;
let (_, last_miniblock_number_in_batch) = conn
let (_, last_l2_block_number_in_batch) = conn
.blocks_dal()
.get_miniblock_range_of_l1_batch(progress.l1_batch_number)
.get_l2_block_range_of_l1_batch(progress.l1_batch_number)
.await?
.context("Error fetching last miniblock number")?;
.context("No L2 blocks for L1 batch")?;
drop(conn);

METRICS.storage_logs_chunks_count.set(progress.chunk_count);
tracing::info!(
"Creating snapshot for storage logs up to miniblock {last_miniblock_number_in_batch}, \
"Creating snapshot for storage logs up to L2 block {last_l2_block_number_in_batch}, \
L1 batch {}",
progress.l1_batch_number
);

if progress.is_new_snapshot {
let factory_deps_output_file = self
.process_factory_deps(last_miniblock_number_in_batch, progress.l1_batch_number)
.process_factory_deps(last_l2_block_number_in_batch, progress.l1_batch_number)
.await?;

let mut master_conn = self
Expand All @@ -334,7 +334,7 @@ impl SnapshotCreator {
let tasks = progress.remaining_chunk_ids.into_iter().map(|chunk_id| {
self.process_storage_logs_single_chunk(
&semaphore,
last_miniblock_number_in_batch,
last_l2_block_number_in_batch,
progress.l1_batch_number,
chunk_id,
progress.chunk_count,
Expand Down
26 changes: 13 additions & 13 deletions core/bin/snapshots_creator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use rand::{thread_rng, Rng};
use zksync_dal::{Connection, CoreDal};
use zksync_object_store::ObjectStore;
use zksync_types::{
block::{L1BatchHeader, L1BatchTreeData, MiniblockHeader},
block::{L1BatchHeader, L1BatchTreeData, L2BlockHeader},
snapshots::{
SnapshotFactoryDependencies, SnapshotFactoryDependency, SnapshotStorageLog,
SnapshotStorageLogsChunk, SnapshotStorageLogsStorageKey,
},
AccountTreeId, Address, L1BatchNumber, MiniblockNumber, ProtocolVersion, StorageKey,
StorageLog, H256,
AccountTreeId, Address, L1BatchNumber, L2BlockNumber, ProtocolVersion, StorageKey, StorageLog,
H256,
};

use super::*;
Expand Down Expand Up @@ -133,15 +133,15 @@ struct ExpectedOutputs {
storage_logs: HashSet<SnapshotStorageLog>,
}

async fn create_miniblock(
async fn create_l2_block(
conn: &mut Connection<'_, Core>,
miniblock_number: MiniblockNumber,
l2_block_number: L2BlockNumber,
block_logs: Vec<StorageLog>,
) {
let miniblock_header = MiniblockHeader {
number: miniblock_number,
let l2_block_header = L2BlockHeader {
number: l2_block_number,
timestamp: 0,
hash: H256::from_low_u64_be(u64::from(miniblock_number.0)),
hash: H256::from_low_u64_be(u64::from(l2_block_number.0)),
l1_tx_count: 0,
l2_tx_count: 0,
fee_account_address: Address::repeat_byte(1),
Expand All @@ -155,11 +155,11 @@ async fn create_miniblock(
};

conn.blocks_dal()
.insert_miniblock(&miniblock_header)
.insert_l2_block(&l2_block_header)
.await
.unwrap();
conn.storage_logs_dal()
.insert_storage_logs(miniblock_number, &[(H256::zero(), block_logs)])
.insert_storage_logs(l2_block_number, &[(H256::zero(), block_logs)])
.await
.unwrap();
}
Expand All @@ -175,7 +175,7 @@ async fn create_l1_batch(
.await
.unwrap();
conn.blocks_dal()
.mark_miniblocks_as_executed_in_l1_batch(l1_batch_number)
.mark_l2_blocks_as_executed_in_l1_batch(l1_batch_number)
.await
.unwrap();

Expand Down Expand Up @@ -210,11 +210,11 @@ async fn prepare_postgres(
let mut outputs = ExpectedOutputs::default();
for block_number in 0..block_count {
let logs = gen_storage_logs(rng, 100);
create_miniblock(conn, MiniblockNumber(block_number), logs.clone()).await;
create_l2_block(conn, L2BlockNumber(block_number), logs.clone()).await;

let factory_deps = gen_factory_deps(rng, 10);
conn.factory_deps_dal()
.insert_factory_deps(MiniblockNumber(block_number), &factory_deps)
.insert_factory_deps(L2BlockNumber(block_number), &factory_deps)
.await
.unwrap();

Expand Down
6 changes: 3 additions & 3 deletions core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use zksync_contracts::{
};
use zksync_state::{InMemoryStorage, StorageView, WriteStorage};
use zksync_types::{
block::MiniblockHasher, ethabi::Token, fee::Fee, fee_model::BatchFeeInput, l1::L1Tx, l2::L2Tx,
block::L2BlockHasher, ethabi::Token, fee::Fee, fee_model::BatchFeeInput, l1::L1Tx, l2::L2Tx,
utils::storage_key_for_eth_balance, AccountTreeId, Address, Execute, L1BatchNumber,
L1TxCommonData, L2ChainId, MiniblockNumber, Nonce, ProtocolVersionId, StorageKey, Transaction,
L1TxCommonData, L2BlockNumber, L2ChainId, Nonce, ProtocolVersionId, StorageKey, Transaction,
BOOTLOADER_ADDRESS, H256, SYSTEM_CONTEXT_ADDRESS, SYSTEM_CONTEXT_GAS_PRICE_POSITION,
SYSTEM_CONTEXT_TX_ORIGIN_POSITION, U256, ZKPORTER_IS_AVAILABLE,
};
Expand Down Expand Up @@ -183,7 +183,7 @@ fn default_l1_batch() -> L1BatchEnv {
first_l2_block: L2BlockEnv {
number: 1,
timestamp: 100,
prev_block_hash: MiniblockHasher::legacy_hash(MiniblockNumber(0)),
prev_block_hash: L2BlockHasher::legacy_hash(L2BlockNumber(0)),
max_virtual_blocks_to_create: 100,
},
}
Expand Down
4 changes: 2 additions & 2 deletions core/lib/basic_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl From<u32> for L2ChainId {

basic_type!(
/// zkSync network block sequential index.
MiniblockNumber,
L2BlockNumber,
u32
);

Expand Down Expand Up @@ -209,7 +209,7 @@ basic_type!(
);

#[allow(clippy::derivable_impls)]
impl Default for MiniblockNumber {
impl Default for L2BlockNumber {
fn default() -> Self {
Self(0)
}
Expand Down
Loading

0 comments on commit 178a018

Please sign in to comment.