Skip to content

Commit

Permalink
feat(en): Make consistency checker work with pruned data (matter-labs…
Browse files Browse the repository at this point in the history
…#742)

## What ❔

Modifies consistency checker so that it works with pruned node data
during snapshot recovery. Adds tests for the checker.

## Why ❔

Part of preparations of EN code to support snapshot recovery.

## Checklist

- [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`.
- [x] Spellcheck has been run via `cargo spellcheck
--cfg=./spellcheck/era.cfg --code 1`.
  • Loading branch information
slowli authored Jan 5, 2024
1 parent e5fbcb5 commit ae6e18e
Show file tree
Hide file tree
Showing 20 changed files with 1,042 additions and 341 deletions.
8 changes: 4 additions & 4 deletions core/lib/eth_client/src/clients/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ impl<C: BoundEthInterface + ?Sized> BoundEthInterface for Arc<C> {
self.as_ref().nonce_at(block, component).await
}

async fn current_nonce(&self, _: &'static str) -> Result<U256, Error> {
self.as_ref().current_nonce("").await
async fn current_nonce(&self, component: &'static str) -> Result<U256, Error> {
self.as_ref().current_nonce(component).await
}

async fn pending_nonce(&self, _: &'static str) -> Result<U256, Error> {
self.as_ref().pending_nonce("").await
async fn pending_nonce(&self, component: &'static str) -> Result<U256, Error> {
self.as_ref().pending_nonce(component).await
}
}
21 changes: 2 additions & 19 deletions core/lib/zksync_core/src/api_server/web3/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ use zksync_config::configs::{
chain::{NetworkConfig, StateKeeperConfig},
ContractsConfig,
};
use zksync_contracts::BaseSystemContractsHashes;
use zksync_dal::{transactions_dal::L2TxSubmissionResult, ConnectionPool};
use zksync_health_check::CheckHealth;
use zksync_state::PostgresStorageCaches;
use zksync_types::{
block::MiniblockHeader, fee::TransactionExecutionMetrics, tx::IncludedTxLocation, Address,
L1BatchNumber, ProtocolVersionId, VmEvent, H256, U64,
L1BatchNumber, VmEvent, H256, U64,
};
use zksync_web3_decl::{
jsonrpsee::{core::ClientError as RpcError, http_client::HttpClient, types::error::ErrorCode},
Expand All @@ -27,7 +26,7 @@ use crate::{
api_server::tx_sender::TxSenderConfig,
genesis::{ensure_genesis_state, GenesisParams},
l1_gas_price::L1GasPriceProvider,
state_keeper::tests::create_l2_transaction,
utils::testonly::{create_l2_transaction, create_miniblock},
};

mod snapshots;
Expand Down Expand Up @@ -209,22 +208,6 @@ fn assert_logs_match(actual_logs: &[api::Log], expected_logs: &[&VmEvent]) {
}
}

fn create_miniblock(number: u32) -> MiniblockHeader {
MiniblockHeader {
number: MiniblockNumber(number),
timestamp: number.into(),
hash: H256::from_low_u64_be(number.into()),
l1_tx_count: 0,
l2_tx_count: 0,
base_fee_per_gas: 100,
l1_gas_price: 100,
l2_fair_gas_price: 100,
base_system_contracts_hashes: BaseSystemContractsHashes::default(),
protocol_version: Some(ProtocolVersionId::latest()),
virtual_blocks: 1,
}
}

async fn store_miniblock(
storage: &mut StorageProcessor<'_>,
) -> anyhow::Result<(MiniblockHeader, H256)> {
Expand Down
12 changes: 3 additions & 9 deletions core/lib/zksync_core/src/api_server/web3/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@
use std::collections::HashSet;

use zksync_types::block::{BlockGasCount, L1BatchHeader};
use zksync_types::block::BlockGasCount;
use zksync_web3_decl::namespaces::SnapshotsNamespaceClient;

use super::*;
use crate::state_keeper::tests::create_l1_batch_metadata;
use crate::utils::testonly::{create_l1_batch, create_l1_batch_metadata};

async fn seal_l1_batch(
storage: &mut StorageProcessor<'_>,
number: L1BatchNumber,
) -> anyhow::Result<()> {
let header = L1BatchHeader::new(
number,
number.0.into(),
Address::repeat_byte(1),
BaseSystemContractsHashes::default(),
ProtocolVersionId::latest(),
);
let header = create_l1_batch(number.0);
storage
.blocks_dal()
.insert_l1_batch(&header, &[], BlockGasCount::default(), &[], &[])
Expand Down
6 changes: 3 additions & 3 deletions core/lib/zksync_core/src/consensus/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use zksync_types::{
use crate::{
genesis::{ensure_genesis_state, GenesisParams},
state_keeper::{
seal_criteria::NoopSealer,
tests::{create_l1_batch_metadata, create_l2_transaction, MockBatchExecutorBuilder},
MiniblockSealer, ZkSyncStateKeeper,
seal_criteria::NoopSealer, tests::MockBatchExecutorBuilder, MiniblockSealer,
ZkSyncStateKeeper,
},
sync_layer::{
sync_action::{ActionQueue, ActionQueueSender, SyncAction},
ExternalIO, MainNodeClient, SyncState,
},
utils::testonly::{create_l1_batch_metadata, create_l2_transaction},
};

#[derive(Debug, Default)]
Expand Down
Loading

0 comments on commit ae6e18e

Please sign in to comment.