Skip to content

Commit

Permalink
fix(en): fail fast if we don't request correct number of txs from man…
Browse files Browse the repository at this point in the history
… node (#1269)

## 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

<!-- 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`.
- [ ] Linkcheck has been run via `zk linkcheck`.

Signed-off-by: Danil <deniallugo@gmail.com>
  • Loading branch information
Deniallugo committed Feb 28, 2024
1 parent f3a5cf9 commit 1bcbf17
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/lib/zksync_core/src/sync_layer/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ impl TryFrom<SyncBlock> for FetchedBlock {
type Error = anyhow::Error;

fn try_from(block: SyncBlock) -> anyhow::Result<Self> {
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,
Expand All @@ -66,9 +76,7 @@ impl TryFrom<SyncBlock> 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,
})
}
}
Expand Down

0 comments on commit 1bcbf17

Please sign in to comment.