Skip to content

Commit

Permalink
fix(metadata-calculator): Save commitment for pre-boojum (matter-labs…
Browse files Browse the repository at this point in the history
…#481)

## What ❔

Saves commitment for pre-boojum batches unconditionally

## Why ❔

They don't have `events_queue_commitment` but `commitment` should be
saved anyway

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [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`.
  • Loading branch information
perekopskiy authored Nov 13, 2023
1 parent c4a12b1 commit 664ce33
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion core/lib/dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ impl BlocksDal<'_, '_> {
number: L1BatchNumber,
metadata: &L1BatchMetadata,
previous_root_hash: H256,
protocol_version: ProtocolVersionId,
) -> anyhow::Result<()> {
let mut transaction = self.storage.start_transaction().await?;

Expand Down Expand Up @@ -614,7 +615,7 @@ impl BlocksDal<'_, '_> {
.execute(transaction.conn())
.await?;

if metadata.events_queue_commitment.is_some() {
if metadata.events_queue_commitment.is_some() || protocol_version.is_pre_boojum() {
// Save `commitment`, `aux_data_hash`, `events_queue_commitment`, `bootloader_initial_content_commitment`.
sqlx::query!(
"INSERT INTO commitments (l1_batch_number, events_queue_commitment, bootloader_initial_content_commitment) \
Expand Down
1 change: 1 addition & 0 deletions core/lib/zksync_core/src/eth_sender/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ async fn insert_l1_batch(tester: &EthSenderTester, number: L1BatchNumber) -> L1B
header.number,
&default_l1_batch_metadata(),
Default::default(),
Default::default(),
)
.await
.unwrap();
Expand Down
7 changes: 6 additions & 1 deletion core/lib/zksync_core/src/metadata_calculator/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ impl TreeUpdater {
let save_postgres_latency = METRICS.start_stage(TreeUpdateStage::SavePostgres);
storage
.blocks_dal()
.save_l1_batch_metadata(l1_batch_number, &metadata, previous_root_hash)
.save_l1_batch_metadata(
l1_batch_number,
&metadata,
previous_root_hash,
header.protocol_version.unwrap(),
)
.await
.unwrap();
// ^ Note that `save_l1_batch_metadata()` will not blindly overwrite changes if L1 batch
Expand Down
7 changes: 6 additions & 1 deletion core/lib/zksync_core/src/state_keeper/io/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,12 @@ async fn test_miniblock_and_l1_batch_processing(
// Save metadata for the genesis L1 batch so that we don't hang in `seal_l1_batch`.
let metadata = create_l1_batch_metadata(0);
conn.blocks_dal()
.save_l1_batch_metadata(L1BatchNumber(0), &metadata, H256::zero())
.save_l1_batch_metadata(
L1BatchNumber(0),
&metadata,
H256::zero(),
ProtocolVersionId::latest(),
)
.await
.unwrap();
drop(conn);
Expand Down
7 changes: 6 additions & 1 deletion core/lib/zksync_core/src/sync_layer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,12 @@ async fn mock_l1_batch_hash_computation(pool: ConnectionPool, number: u32) {
let metadata = create_l1_batch_metadata(number);
storage
.blocks_dal()
.save_l1_batch_metadata(L1BatchNumber(1), &metadata, H256::zero())
.save_l1_batch_metadata(
L1BatchNumber(1),
&metadata,
H256::zero(),
ProtocolVersionId::latest(),
)
.await
.unwrap();
break;
Expand Down

0 comments on commit 664ce33

Please sign in to comment.