Skip to content

Commit

Permalink
Revert batch VM traits
Browse files Browse the repository at this point in the history
  • Loading branch information
slowli committed Jul 30, 2024
1 parent 5073f0e commit b51e26d
Show file tree
Hide file tree
Showing 26 changed files with 518 additions and 627 deletions.
5 changes: 3 additions & 2 deletions core/bin/external_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use zksync_reorg_detector::ReorgDetector;
use zksync_shared_metrics::rustc::RUST_METRICS;
use zksync_state::{PostgresStorageCaches, RocksdbStorageOptions};
use zksync_state_keeper::{
seal_criteria::NoopSealer, AsyncRocksdbCache, BatchExecutor, OutputHandler,
seal_criteria::NoopSealer, AsyncRocksdbCache, BatchExecutor, MainBatchExecutor, OutputHandler,
StateKeeperPersistence, TreeWritesPersistence, ZkSyncStateKeeper,
};
use zksync_storage::RocksDB;
Expand Down Expand Up @@ -94,7 +94,8 @@ async fn build_state_keeper(
stop_receiver_clone.changed().await?;
result
}));
let batch_executor_base = BatchExecutor::new(save_call_traces, true);
let batch_executor_base: Box<dyn BatchExecutor> =
Box::new(MainBatchExecutor::new(save_call_traces, true));

let io = ExternalIO::new(
connection_pool,
Expand Down
4 changes: 2 additions & 2 deletions core/bin/external_node/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use zksync_node_framework::{
reorg_detector::ReorgDetectorLayer,
sigint::SigintHandlerLayer,
state_keeper::{
batch_executor::BatchExecutorLayer, external_io::ExternalIOLayer,
external_io::ExternalIOLayer, main_batch_executor::MainBatchExecutorLayer,
output_handler::OutputHandlerLayer, StateKeeperLayer,
},
sync_state_updater::SyncStateUpdaterLayer,
Expand Down Expand Up @@ -201,7 +201,7 @@ impl ExternalNodeBuilder {
.api_namespaces()
.contains(&Namespace::Debug);
let main_node_batch_executor_builder_layer =
BatchExecutorLayer::new(save_call_traces, OPTIONAL_BYTECODE_COMPRESSION);
MainBatchExecutorLayer::new(save_call_traces, OPTIONAL_BYTECODE_COMPRESSION);

let rocksdb_options = RocksdbStorageOptions {
block_cache_capacity: self
Expand Down
4 changes: 2 additions & 2 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use zksync_node_framework::{
query_eth_client::QueryEthClientLayer,
sigint::SigintHandlerLayer,
state_keeper::{
batch_executor::BatchExecutorLayer, mempool_io::MempoolIOLayer,
main_batch_executor::MainBatchExecutorLayer, mempool_io::MempoolIOLayer,
output_handler::OutputHandlerLayer, RocksdbStorageOptions, StateKeeperLayer,
},
tee_verifier_input_producer::TeeVerifierInputProducerLayer,
Expand Down Expand Up @@ -232,7 +232,7 @@ impl MainNodeBuilder {
);
let db_config = try_load_config!(self.configs.db_config);
let main_node_batch_executor_builder_layer =
BatchExecutorLayer::new(sk_config.save_call_traces, OPTIONAL_BYTECODE_COMPRESSION);
MainBatchExecutorLayer::new(sk_config.save_call_traces, OPTIONAL_BYTECODE_COMPRESSION);

let rocksdb_options = RocksdbStorageOptions {
block_cache_capacity: db_config
Expand Down
6 changes: 0 additions & 6 deletions core/lib/state/src/rocksdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,6 @@ impl RocksdbStorageBuilder {
) -> anyhow::Result<()> {
self.0.revert(storage, last_l1_batch_to_keep).await
}

/// Returns the underlying storage without synchronizing it or checking that it's up-to-date.
/// Should not be used other than for tests.
pub fn build_unchecked(self) -> RocksdbStorage {
self.0
}
}

impl RocksdbStorage {
Expand Down
14 changes: 7 additions & 7 deletions core/node/consensus/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ use zksync_state_keeper::{
io::{IoCursor, L1BatchParams, L2BlockParams},
seal_criteria::NoopSealer,
testonly::{
fund, l1_transaction, l2_transaction, test_batch_vm::MockReadStorageFactory, MockBatchVm,
fund, l1_transaction, l2_transaction, test_batch_executor::MockReadStorageFactory,
MockBatchExecutor,
},
AsyncRocksdbCache, BatchExecutor, OutputHandler, StateKeeperPersistence, TreeWritesPersistence,
ZkSyncStateKeeper,
AsyncRocksdbCache, MainBatchExecutor, OutputHandler, StateKeeperPersistence,
TreeWritesPersistence, ZkSyncStateKeeper,
};
use zksync_test_account::Account;
use zksync_types::{
Expand Down Expand Up @@ -546,7 +547,7 @@ impl StateKeeperRunner {
ZkSyncStateKeeper::new(
stop_recv,
Box::new(io),
BatchExecutor::new(false, false),
Box::new(MainBatchExecutor::new(false, false)),
OutputHandler::new(Box::new(persistence.with_tx_insertion()))
.with_handler(Box::new(self.sync_state.clone())),
Arc::new(NoopSealer),
Expand Down Expand Up @@ -627,13 +628,12 @@ impl StateKeeperRunner {
ZkSyncStateKeeper::new(
stop_recv,
Box::new(io),
BatchExecutor::new(false, false)
.with_vm_factory(Arc::<MockBatchVm>::default()),
Box::new(MockBatchExecutor),
OutputHandler::new(Box::new(persistence.with_tx_insertion()))
.with_handler(Box::new(tree_writes_persistence))
.with_handler(Box::new(self.sync_state.clone())),
Arc::new(NoopSealer),
Arc::<MockReadStorageFactory>::default(),
Arc::new(MockReadStorageFactory),
)
.run()
.await
Expand Down
4 changes: 2 additions & 2 deletions core/node/node_framework/examples/main_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use zksync_node_framework::{
query_eth_client::QueryEthClientLayer,
sigint::SigintHandlerLayer,
state_keeper::{
batch_executor::BatchExecutorLayer, mempool_io::MempoolIOLayer,
main_batch_executor::MainBatchExecutorLayer, mempool_io::MempoolIOLayer,
output_handler::OutputHandlerLayer, StateKeeperLayer,
},
web3_api::{
Expand Down Expand Up @@ -161,7 +161,7 @@ impl MainNodeBuilder {
wallets.state_keeper.context("State keeper wallets")?,
);
let main_node_batch_executor_builder_layer =
BatchExecutorLayer::new(StateKeeperConfig::from_env()?.save_call_traces, true);
MainBatchExecutorLayer::new(StateKeeperConfig::from_env()?.save_call_traces, true);
let db_config = DBConfig::from_env()?;

let rocksdb_options = RocksdbStorageOptions {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use zksync_state_keeper::MainBatchExecutor;

use crate::{
implementations::resources::state_keeper::BatchExecutorResource,
wiring_layer::{WiringError, WiringLayer},
IntoContext,
};

/// Wiring layer for `MainBatchExecutor`, part of the state keeper responsible for running the VM.
#[derive(Debug)]
pub struct MainBatchExecutorLayer {
save_call_traces: bool,
optional_bytecode_compression: bool,
}

#[derive(Debug, IntoContext)]
#[context(crate = crate)]
pub struct Output {
pub batch_executor: BatchExecutorResource,
}

impl MainBatchExecutorLayer {
pub fn new(save_call_traces: bool, optional_bytecode_compression: bool) -> Self {
Self {
save_call_traces,
optional_bytecode_compression,
}
}
}

#[async_trait::async_trait]
impl WiringLayer for MainBatchExecutorLayer {
type Input = ();
type Output = Output;

fn layer_name(&self) -> &'static str {
"main_batch_executor_layer"
}

async fn wire(self, _input: Self::Input) -> Result<Self::Output, WiringError> {
let builder =
MainBatchExecutor::new(self.save_call_traces, self.optional_bytecode_compression);

Ok(Output {
batch_executor: builder.into(),
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use zksync_state_keeper::{
};
use zksync_storage::RocksDB;

pub mod batch_executor;
pub mod external_io;
pub mod main_batch_executor;
pub mod mempool_io;
pub mod output_handler;

Expand Down Expand Up @@ -85,7 +85,7 @@ impl WiringLayer for StateKeeperLayer {
.batch_executor
.0
.take()
.context("BatchExecutor was provided but taken by some other task")?;
.context("L1BatchExecutorBuilder was provided but taken by some other task")?;
let output_handler = input
.output_handler
.0
Expand Down Expand Up @@ -125,7 +125,7 @@ impl WiringLayer for StateKeeperLayer {
#[derive(Debug)]
pub struct StateKeeperTask {
io: Box<dyn StateKeeperIO>,
batch_executor_base: BatchExecutor,
batch_executor_base: Box<dyn BatchExecutor>,
output_handler: OutputHandler,
sealer: Arc<dyn ConditionalSealer>,
storage_factory: Arc<dyn ReadStorageFactory>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ impl<T: StateKeeperIO> From<T> for StateKeeperIOResource {
/// A resource that provides [`BatchExecutor`] implementation to the service.
/// This resource is unique, e.g. it's expected to be consumed by a single service.
#[derive(Debug, Clone)]
pub struct BatchExecutorResource(pub Unique<BatchExecutor>);
pub struct BatchExecutorResource(pub Unique<Box<dyn BatchExecutor>>);

impl Resource for BatchExecutorResource {
fn name() -> String {
"state_keeper/batch_executor".into()
}
}

impl From<BatchExecutor> for BatchExecutorResource {
fn from(executor: BatchExecutor) -> Self {
Self(Unique::new(executor))
impl<T: BatchExecutor> From<T> for BatchExecutorResource {
fn from(executor: T) -> Self {
Self(Unique::new(Box::new(executor)))
}
}

Expand Down
13 changes: 6 additions & 7 deletions core/node/node_sync/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use zksync_node_test_utils::{
use zksync_state_keeper::{
io::{L1BatchParams, L2BlockParams},
seal_criteria::NoopSealer,
testonly::test_batch_vm::{MockReadStorageFactory, TestBatchVmFactory},
BatchExecutor, OutputHandler, StateKeeperPersistence, TreeWritesPersistence, ZkSyncStateKeeper,
testonly::test_batch_executor::{MockReadStorageFactory, TestBatchExecutorBuilder},
OutputHandler, StateKeeperPersistence, TreeWritesPersistence, ZkSyncStateKeeper,
};
use zksync_types::{
api,
Expand Down Expand Up @@ -121,19 +121,18 @@ impl StateKeeperHandles {
.unwrap();

let (stop_sender, stop_receiver) = watch::channel(false);
let mut vm_factory = TestBatchVmFactory::default();
let mut batch_executor_base = TestBatchExecutorBuilder::default();
for &tx_hashes_in_l1_batch in tx_hashes {
vm_factory.push_successful_transactions(tx_hashes_in_l1_batch);
batch_executor_base.push_successful_transactions(tx_hashes_in_l1_batch);
}
let batch_executor = BatchExecutor::new(false, false).with_vm_factory(Arc::new(vm_factory));

let state_keeper = ZkSyncStateKeeper::new(
stop_receiver,
Box::new(io),
batch_executor,
Box::new(batch_executor_base),
output_handler,
Arc::new(NoopSealer),
Arc::<MockReadStorageFactory>::default(),
Arc::new(MockReadStorageFactory),
);

Self {
Expand Down
2 changes: 1 addition & 1 deletion core/node/state_keeper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ zksync_base_token_adjuster.workspace = true

anyhow.workspace = true
async-trait.workspace = true
tempfile.workspace = true # used in `testonly` module
tokio = { workspace = true, features = ["time"] }
thiserror.workspace = true
tracing.workspace = true
Expand All @@ -46,6 +45,7 @@ hex.workspace = true
assert_matches.workspace = true
test-casing.workspace = true
futures.workspace = true
tempfile.workspace = true

zksync_eth_client.workspace = true
zksync_system_constants.workspace = true
Loading

0 comments on commit b51e26d

Please sign in to comment.