Skip to content

Commit

Permalink
Merge branch 'main' into aov-pla-1038-integrate-new-vm-into-api-serve…
Browse files Browse the repository at this point in the history
…r-no-tracers
  • Loading branch information
joonazan authored Oct 18, 2024
2 parents e226ec6 + 37f209f commit 3d82560
Show file tree
Hide file tree
Showing 36 changed files with 527 additions and 417 deletions.
63 changes: 32 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,18 @@ circuit_sequencer_api_1_3_3 = { package = "circuit_sequencer_api", version = "0.
circuit_sequencer_api_1_4_0 = { package = "circuit_sequencer_api", version = "0.140" }
circuit_sequencer_api_1_4_1 = { package = "circuit_sequencer_api", version = "0.141" }
circuit_sequencer_api_1_4_2 = { package = "circuit_sequencer_api", version = "0.142" }
circuit_sequencer_api_1_5_0 = { package = "circuit_sequencer_api", version = "=0.150.5" }
circuit_sequencer_api_1_5_0 = { package = "circuit_sequencer_api", version = "=0.150.6" }
crypto_codegen = { package = "zksync_solidity_vk_codegen", version = "=0.30.1" }
kzg = { package = "zksync_kzg", version = "=0.150.5" }
kzg = { package = "zksync_kzg", version = "=0.150.6" }
zk_evm = { version = "=0.133.0" }
zk_evm_1_3_1 = { package = "zk_evm", version = "0.131.0-rc.2" }
zk_evm_1_3_3 = { package = "zk_evm", version = "0.133" }
zk_evm_1_4_0 = { package = "zk_evm", version = "0.140" }
zk_evm_1_4_1 = { package = "zk_evm", version = "0.141" }
zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.5" }
zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.6" }

# New VM; pinned to a specific commit because of instability
zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "a233d44bbe61dc6a758a754c3b78fe4f83e56699" }
zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "df5bec3d04d64d434f9b0ccb285ba4681008f7b3" }

# Consensus dependencies.
zksync_concurrency = "=0.5.0"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions core/lib/dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,37 @@ impl BlocksDal<'_, '_> {
Ok(())
}

/// Deletes the unsealed L1 batch from the storage. Expects the caller to make sure there are no
/// associated L2 blocks.
///
/// Accepts `batch_to_keep` as a safety mechanism.
pub async fn delete_unsealed_l1_batch(
&mut self,
batch_to_keep: L1BatchNumber,
) -> DalResult<()> {
let deleted_row = sqlx::query!(
r#"
DELETE FROM l1_batches
WHERE
number > $1
AND NOT is_sealed
RETURNING number
"#,
i64::from(batch_to_keep.0)
)
.instrument("delete_unsealed_l1_batch")
.with_arg("batch_to_keep", &batch_to_keep)
.fetch_optional(self.storage)
.await?;
if let Some(deleted_row) = deleted_row {
tracing::info!(
l1_batch_number = %deleted_row.number,
"Deleted unsealed batch"
);
}
Ok(())
}

/// Deletes all L1 batches from the storage so that the specified batch number is the last one left.
pub async fn delete_l1_batches(&mut self, last_batch_to_keep: L1BatchNumber) -> DalResult<()> {
self.delete_l1_batches_inner(Some(last_batch_to_keep)).await
Expand Down Expand Up @@ -2184,6 +2215,20 @@ impl BlocksDal<'_, '_> {
Ok(Some((L2BlockNumber(min as u32), L2BlockNumber(max as u32))))
}

/// Returns `true` if there exists a non-sealed batch (i.e. there is one+ stored L2 block that isn't assigned
/// to any batch yet).
pub async fn pending_batch_exists(&mut self) -> DalResult<bool> {
let count = sqlx::query_scalar!(
"SELECT COUNT(miniblocks.number) FROM miniblocks WHERE l1_batch_number IS NULL"
)
.instrument("pending_batch_exists")
.fetch_one(self.storage)
.await?
.unwrap_or(0);

Ok(count != 0)
}

// methods used for measuring Eth tx stage transition latencies
// and emitting metrics base on these measured data
pub async fn oldest_uncommitted_batch_timestamp(&mut self) -> DalResult<Option<u64>> {
Expand Down
14 changes: 11 additions & 3 deletions core/lib/multivm/src/versions/testonly/bytecode_publishing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use zksync_test_account::{DeployContractsTx, TxType};
use zksync_test_account::TxType;

use super::{read_test_contract, tester::VmTesterBuilder, TestedVm};
use crate::{
Expand All @@ -20,8 +20,16 @@ pub(crate) fn test_bytecode_publishing<VM: TestedVm>() {

let compressed_bytecode = bytecode::compress(counter.clone()).unwrap().compressed;

let DeployContractsTx { tx, .. } = account.get_deploy_tx(&counter, None, TxType::L2);
vm.vm.push_transaction(tx);
let tx = account.get_deploy_tx(&counter, None, TxType::L2).tx;
assert_eq!(tx.execute.factory_deps.len(), 1); // The deployed bytecode is the only dependency
let push_result = vm.vm.push_transaction(tx);
assert_eq!(push_result.compressed_bytecodes.len(), 1);
assert_eq!(push_result.compressed_bytecodes[0].original, counter);
assert_eq!(
push_result.compressed_bytecodes[0].compressed,
compressed_bytecode
);

let result = vm.vm.execute(VmExecutionMode::OneTx);
assert!(!result.result.is_failed(), "Transaction wasn't successful");

Expand Down
23 changes: 14 additions & 9 deletions core/lib/multivm/src/versions/vm_1_3_2/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use crate::{
interface::{
storage::{StoragePtr, WriteStorage},
BytecodeCompressionError, BytecodeCompressionResult, FinishedL1Batch, L1BatchEnv,
L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode, VmExecutionResultAndLogs,
VmFactory, VmInterface, VmInterfaceHistoryEnabled, VmMemoryMetrics,
L2BlockEnv, PushTransactionResult, SystemEnv, TxExecutionMode, VmExecutionMode,
VmExecutionResultAndLogs, VmFactory, VmInterface, VmInterfaceHistoryEnabled,
VmMemoryMetrics,
},
tracers::old::TracerDispatcher,
utils::bytecode,
Expand Down Expand Up @@ -44,13 +45,17 @@ impl<S: WriteStorage, H: HistoryMode> Vm<S, H> {
impl<S: WriteStorage, H: HistoryMode> VmInterface for Vm<S, H> {
type TracerDispatcher = TracerDispatcher;

fn push_transaction(&mut self, tx: Transaction) {
crate::vm_1_3_2::vm_with_bootloader::push_transaction_to_bootloader_memory(
&mut self.vm,
&tx,
self.system_env.execution_mode.glue_into(),
None,
)
fn push_transaction(&mut self, tx: Transaction) -> PushTransactionResult<'_> {
let compressed_bytecodes =
crate::vm_1_3_2::vm_with_bootloader::push_transaction_to_bootloader_memory(
&mut self.vm,
&tx,
self.system_env.execution_mode.glue_into(),
None,
);
PushTransactionResult {
compressed_bytecodes: compressed_bytecodes.into(),
}
}

fn inspect(
Expand Down
Loading

0 comments on commit 3d82560

Please sign in to comment.