Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gateway): refine l2 l1 logs proofs #3078

Merged
merged 17 commits into from
Oct 31, 2024

Conversation

perekopskiy
Copy link
Contributor

@perekopskiy perekopskiy commented Oct 11, 2024

What ❔

Reworks how node generates proofs for l2-l1 logs. Adds new eth-watch processor that listens to AppendedChainBatchRoot events, updates batch tree and saves proof to DB. API reads those proofs on requests

Why ❔

  • optimize for performance -- no need to rebuild batch tree each time, now eth watch holds only one tree
  • brush up code

Checklist

  • 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_supervisor fmt and zk_supervisor lint.

@perekopskiy perekopskiy marked this pull request as ready for review October 14, 2024 09:20
Copy link
Contributor

@StanislavBreadless StanislavBreadless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, we also discussed in private that a bit more long-term approach is that each chain calculates chain root on its own. However, it is not needed in this release, but we need to plan to be able to change it.

Also, using sleep in tests is not recommended since I already worked on removing those by creating waitForBlockToBeFinalizedOnL1

&mut self,
sl_chain_id: SLChainId,
) -> DalResult<Vec<(L1BatchNumber, H256)>> {
let result = sqlx::query!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case on an emergency if the execute transaction happen outside the eth sender, how hard will it be make this function work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be simple: insert corresponding rows to eth_txs_history and eth_tx tables. However, if it happens and server restarts before we insert these rows it potentially can lead to incorrect batch_chain_merkle_path being saved. I guess I will add a sanity check to events processor: batch root calculated on eth watcher side should be the same as on SL

.get_executed_batch_roots_on_sl(sl_chain_id)
.await?;

let next_expected_batch_number = batch_hashes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it work fine when we migrate from L1 to Gateway? It just seems like if the returned array is 0, then it will be strictly expected to see batch 0, which is not correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will work. Variable name is misleading, it's not next expected but "lower bound for the next batch number". I will try to come up with better name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up with next_batch_number_lower_bound

.last()
.map(|(n, _)| *n + 1)
.unwrap_or(L1BatchNumber(0));
let tree_leaves = batch_hashes.into_iter().map(|(batch_number, batch_root)| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just in case, the message root aggregation will only work on gateway (not L1)

async fn logs_extended(
&self,
filter: &web3::Filter,
) -> EnrichedClientResult<Vec<zksync_types::api::Log>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally agree that this is the easiest choice, but I recall I had to refactor my types with some pain to ensure that certain methods are available only for types that do support it (e.g. I added L2-like base fee history only for ForWeb3Network<Net = L2>).

But if you decide to keep it this way, it may make sense to add a comment on what will happen if someone tries to use the method with l1 provider

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reworked eth watcher client

@perekopskiy perekopskiy merged commit 4897a6e into sync-layer-stable Oct 31, 2024
32 checks passed
@perekopskiy perekopskiy deleted the gateway-refine-l2-l1-logs-proof branch October 31, 2024 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants