Skip to content

Commit

Permalink
refactor(vm): move vm types to interface level (#251)
Browse files Browse the repository at this point in the history
# What ❔

Use common types for vm_latest and vm_with_virtual blocks

## Why ❔

We are slightly moving forward to interface unification and now these
types allows us to make less transformation

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.

---------

Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo authored Oct 18, 2023
1 parent 650124c commit 885ced6
Show file tree
Hide file tree
Showing 160 changed files with 477 additions and 1,812 deletions.
8 changes: 4 additions & 4 deletions core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use multivm::vm_latest::constants::{BLOCK_GAS_LIMIT, BOOTLOADER_HEAP_PAGE};
use multivm::interface::{L1BatchEnv, L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode};
use multivm::vm_latest::{
BootloaderState, BoxedTracer, DynTracer, HistoryEnabled, HistoryMode, L1BatchEnv, L2BlockEnv,
SystemEnv, TxExecutionMode, Vm, VmExecutionMode, VmExecutionStopReason, VmTracer,
ZkSyncVmState,
constants::{BLOCK_GAS_LIMIT, BOOTLOADER_HEAP_PAGE},
BootloaderState, BoxedTracer, DynTracer, HistoryEnabled, HistoryMode, Vm,
VmExecutionStopReason, VmTracer, ZkSyncVmState,
};
use once_cell::sync::Lazy;
use std::cell::RefCell;
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/glue/init_vm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::GlueInto;
use crate::glue::history_mode::HistoryMode;
use crate::interface::{L1BatchEnv, SystemEnv};
use crate::vm_instance::VmInstanceVersion;
use crate::vm_latest::{L1BatchEnv, SystemEnv};
use crate::VmInstance;
use zksync_state::{ReadStorage, StoragePtr, StorageView};
use zksync_types::VmVersion;
Expand Down
12 changes: 6 additions & 6 deletions core/lib/multivm/src/glue/types/vm/block_context_mode.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::glue::GlueFrom;
use zksync_utils::h256_to_u256;

impl GlueFrom<crate::vm_latest::L1BatchEnv> for crate::vm_m5::vm_with_bootloader::BlockContextMode {
fn glue_from(value: crate::vm_latest::L1BatchEnv) -> Self {
impl GlueFrom<crate::interface::L1BatchEnv> for crate::vm_m5::vm_with_bootloader::BlockContextMode {
fn glue_from(value: crate::interface::L1BatchEnv) -> Self {
let derived = crate::vm_m5::vm_with_bootloader::DerivedBlockContext {
context: crate::vm_m5::vm_with_bootloader::BlockContext {
block_number: value.number.0,
Expand All @@ -20,8 +20,8 @@ impl GlueFrom<crate::vm_latest::L1BatchEnv> for crate::vm_m5::vm_with_bootloader
}
}

impl GlueFrom<crate::vm_latest::L1BatchEnv> for crate::vm_m6::vm_with_bootloader::BlockContextMode {
fn glue_from(value: crate::vm_latest::L1BatchEnv) -> Self {
impl GlueFrom<crate::interface::L1BatchEnv> for crate::vm_m6::vm_with_bootloader::BlockContextMode {
fn glue_from(value: crate::interface::L1BatchEnv) -> Self {
let derived = crate::vm_m6::vm_with_bootloader::DerivedBlockContext {
context: crate::vm_m6::vm_with_bootloader::BlockContext {
block_number: value.number.0,
Expand All @@ -39,10 +39,10 @@ impl GlueFrom<crate::vm_latest::L1BatchEnv> for crate::vm_m6::vm_with_bootloader
}
}

impl GlueFrom<crate::vm_latest::L1BatchEnv>
impl GlueFrom<crate::interface::L1BatchEnv>
for crate::vm_1_3_2::vm_with_bootloader::BlockContextMode
{
fn glue_from(value: crate::vm_latest::L1BatchEnv) -> Self {
fn glue_from(value: crate::interface::L1BatchEnv) -> Self {
let derived = crate::vm_1_3_2::vm_with_bootloader::DerivedBlockContext {
context: crate::vm_1_3_2::vm_with_bootloader::BlockContext {
block_number: value.number.0,
Expand Down
33 changes: 0 additions & 33 deletions core/lib/multivm/src/glue/types/vm/bytecompression_result.rs

This file was deleted.

15 changes: 0 additions & 15 deletions core/lib/multivm/src/glue/types/vm/current_execution_state.rs

This file was deleted.

20 changes: 0 additions & 20 deletions core/lib/multivm/src/glue/types/vm/execution_result.rs

This file was deleted.

46 changes: 0 additions & 46 deletions core/lib/multivm/src/glue/types/vm/halt.rs

This file was deleted.

16 changes: 0 additions & 16 deletions core/lib/multivm/src/glue/types/vm/l1_batch.rs

This file was deleted.

12 changes: 0 additions & 12 deletions core/lib/multivm/src/glue/types/vm/l2_block.rs

This file was deleted.

13 changes: 0 additions & 13 deletions core/lib/multivm/src/glue/types/vm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
mod block_context_mode;
mod bytecompression_result;
mod current_execution_state;
mod execution_result;
mod halt;
mod l1_batch;
mod l2_block;
mod refunds;
mod system_env;
mod tx_execution_mode;
mod tx_revert_reason;
mod vm_block_result;
mod vm_execution_mode;
mod vm_execution_result;
mod vm_execution_result_and_logs;
mod vm_execution_statistics;
mod vm_memory_metrics;
mod vm_partial_execution_result;
mod vm_revert_reason;
mod vm_tx_execution_result;
11 changes: 0 additions & 11 deletions core/lib/multivm/src/glue/types/vm/refunds.rs

This file was deleted.

16 changes: 0 additions & 16 deletions core/lib/multivm/src/glue/types/vm/system_env.rs

This file was deleted.

40 changes: 15 additions & 25 deletions core/lib/multivm/src/glue/types/vm/tx_execution_mode.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
use crate::glue::GlueFrom;

impl GlueFrom<crate::vm_latest::TxExecutionMode>
impl GlueFrom<crate::interface::TxExecutionMode>
for crate::vm_m5::vm_with_bootloader::TxExecutionMode
{
fn glue_from(value: crate::vm_latest::TxExecutionMode) -> Self {
fn glue_from(value: crate::interface::TxExecutionMode) -> Self {
match value {
crate::vm_latest::TxExecutionMode::VerifyExecute => Self::VerifyExecute,
crate::vm_latest::TxExecutionMode::EstimateFee => Self::EstimateFee,
crate::vm_latest::TxExecutionMode::EthCall => Self::EthCall,
crate::interface::TxExecutionMode::VerifyExecute => Self::VerifyExecute,
crate::interface::TxExecutionMode::EstimateFee => Self::EstimateFee,
crate::interface::TxExecutionMode::EthCall => Self::EthCall,
}
}
}

impl GlueFrom<crate::vm_latest::TxExecutionMode>
impl GlueFrom<crate::interface::TxExecutionMode>
for crate::vm_m6::vm_with_bootloader::TxExecutionMode
{
fn glue_from(value: crate::vm_latest::TxExecutionMode) -> Self {
fn glue_from(value: crate::interface::TxExecutionMode) -> Self {
match value {
crate::vm_latest::TxExecutionMode::VerifyExecute => Self::VerifyExecute,
crate::vm_latest::TxExecutionMode::EstimateFee => Self::EstimateFee {
crate::interface::TxExecutionMode::VerifyExecute => Self::VerifyExecute,
crate::interface::TxExecutionMode::EstimateFee => Self::EstimateFee {
// We used it only for api services we don't have limit for storage invocation inside statekeeper
// It's impossible to recover this value for the vm integration after virtual blocks
missed_storage_invocation_limit: usize::MAX,
},
crate::vm_latest::TxExecutionMode::EthCall => Self::EthCall {
crate::interface::TxExecutionMode::EthCall => Self::EthCall {
// We used it only for api services we don't have limit for storage invocation inside statekeeper
// It's impossible to recover this value for the vm integration after virtual blocks
missed_storage_invocation_limit: usize::MAX,
Expand All @@ -32,32 +32,22 @@ impl GlueFrom<crate::vm_latest::TxExecutionMode>
}
}

impl GlueFrom<crate::vm_latest::TxExecutionMode>
impl GlueFrom<crate::interface::TxExecutionMode>
for crate::vm_1_3_2::vm_with_bootloader::TxExecutionMode
{
fn glue_from(value: crate::vm_latest::TxExecutionMode) -> Self {
fn glue_from(value: crate::interface::TxExecutionMode) -> Self {
match value {
crate::vm_latest::TxExecutionMode::VerifyExecute => Self::VerifyExecute,
crate::vm_latest::TxExecutionMode::EstimateFee => Self::EstimateFee {
crate::interface::TxExecutionMode::VerifyExecute => Self::VerifyExecute,
crate::interface::TxExecutionMode::EstimateFee => Self::EstimateFee {
// We used it only for api services we don't have limit for storage invocation inside statekeeper
// It's impossible to recover this value for the vm integration after virtual blocks
missed_storage_invocation_limit: usize::MAX,
},
crate::vm_latest::TxExecutionMode::EthCall => Self::EthCall {
crate::interface::TxExecutionMode::EthCall => Self::EthCall {
// We used it only for api services we don't have limit for storage invocation inside statekeeper
// It's impossible to recover this value for the vm integration after virtual blocks
missed_storage_invocation_limit: usize::MAX,
},
}
}
}

impl GlueFrom<crate::vm_latest::TxExecutionMode> for crate::vm_virtual_blocks::TxExecutionMode {
fn glue_from(value: crate::vm_latest::TxExecutionMode) -> Self {
match value {
crate::vm_latest::TxExecutionMode::VerifyExecute => Self::VerifyExecute,
crate::vm_latest::TxExecutionMode::EstimateFee => Self::EstimateFee,
crate::vm_latest::TxExecutionMode::EthCall => Self::EthCall,
}
}
}
Loading

0 comments on commit 885ced6

Please sign in to comment.