From 1bcbf1751c6224619873373c7cf071cdebdf56ee Mon Sep 17 00:00:00 2001 From: Danil Date: Wed, 28 Feb 2024 13:04:23 +0100 Subject: [PATCH] fix(en): fail fast if we don't request correct number of txs from man node (#1269) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Only the last miniblock in batch can have 0 txs. Fail fast if the main node returned wrong value ## Why ❔ It allows to find discrepancy faster ## 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 fmt` and `zk lint`. - [ ] Spellcheck has been run via `zk spellcheck`. - [ ] Linkcheck has been run via `zk linkcheck`. Signed-off-by: Danil --- core/lib/zksync_core/src/sync_layer/fetcher.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/lib/zksync_core/src/sync_layer/fetcher.rs b/core/lib/zksync_core/src/sync_layer/fetcher.rs index a9f162f746b..eb22a87345f 100644 --- a/core/lib/zksync_core/src/sync_layer/fetcher.rs +++ b/core/lib/zksync_core/src/sync_layer/fetcher.rs @@ -54,6 +54,16 @@ impl TryFrom for FetchedBlock { type Error = anyhow::Error; fn try_from(block: SyncBlock) -> anyhow::Result { + let Some(transactions) = block.transactions else { + return Err(anyhow::anyhow!("Transactions are always requested")); + }; + + if transactions.is_empty() && !block.last_in_batch { + return Err(anyhow::anyhow!( + "Only last miniblock of the batch can be empty" + )); + } + Ok(Self { number: block.number, l1_batch_number: block.l1_batch_number, @@ -66,9 +76,7 @@ impl TryFrom for FetchedBlock { fair_pubdata_price: block.fair_pubdata_price, virtual_blocks: block.virtual_blocks.unwrap_or(0), operator_address: block.operator_address, - transactions: block - .transactions - .context("Transactions are always requested")?, + transactions, }) } }