Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
chore: save l2 l1 logs only if there are some (matter-labs#2139)
Browse files Browse the repository at this point in the history
## What ❔

save l2 l1 logs for miniblock only if there are some

## Why ❔

We save l2 l1 logs using `COPY` and it appears it has some constant
overhead of ~40ms regardless whether there is some data to copy or not.
By checking if l2_l1_logs.is_empty we can save this 40ms.

## Checklist

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

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
  • Loading branch information
perekopskiy authored Jun 4, 2024
1 parent 2b8d9a3 commit 0329ed6
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ impl L2BlockSealSubtask for InsertFactoryDepsSubtask {
.factory_deps_dal()
.insert_factory_deps(command.l2_block.number, &command.l2_block.new_factory_deps)
.await?;
progress.observe(command.l2_block.new_factory_deps.len());
}
progress.observe(command.l2_block.new_factory_deps.len());

Ok(())
}
Expand Down Expand Up @@ -250,12 +250,11 @@ impl L2BlockSealSubtask for InsertTokensSubtask {
extract_added_tokens(command.l2_shared_bridge_addr, &command.l2_block.events);
progress.observe(added_tokens.len());

let progress = L2_BLOCK_METRICS.start(L2BlockSealStage::InsertTokens, is_fictive);
if !added_tokens.is_empty() {
let progress = L2_BLOCK_METRICS.start(L2BlockSealStage::InsertTokens, is_fictive);
let added_tokens_len = added_tokens.len();
connection.tokens_dal().add_tokens(&added_tokens).await?;
progress.observe(added_tokens_len);
}
progress.observe(added_tokens.len());

Ok(())
}
Expand Down Expand Up @@ -342,10 +341,12 @@ impl L2BlockSealSubtask for InsertL2ToL1LogsSubtask {
progress.observe(user_l2_to_l1_log_count);

let progress = L2_BLOCK_METRICS.start(L2BlockSealStage::InsertL2ToL1Logs, is_fictive);
connection
.events_dal()
.save_user_l2_to_l1_logs(command.l2_block.number, &user_l2_to_l1_logs)
.await?;
if !user_l2_to_l1_logs.is_empty() {
connection
.events_dal()
.save_user_l2_to_l1_logs(command.l2_block.number, &user_l2_to_l1_logs)
.await?;
}
progress.observe(user_l2_to_l1_log_count);
Ok(())
}
Expand Down

0 comments on commit 0329ed6

Please sign in to comment.