diff --git a/core/lib/dal/.sqlx/query-6069d168d5c4b5131b50500302cdde79388b62926ff83d954b4d93dedfe2503a.json b/core/lib/dal/.sqlx/query-6069d168d5c4b5131b50500302cdde79388b62926ff83d954b4d93dedfe2503a.json deleted file mode 100644 index 98d228726d48..000000000000 --- a/core/lib/dal/.sqlx/query-6069d168d5c4b5131b50500302cdde79388b62926ff83d954b4d93dedfe2503a.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE l1_batches\n SET\n l1_tx_count = $2,\n l2_tx_count = $3,\n l2_to_l1_messages = $4,\n bloom = $5,\n priority_ops_onchain_data = $6,\n predicted_commit_gas_cost = $7,\n predicted_prove_gas_cost = $8,\n predicted_execute_gas_cost = $9,\n initial_bootloader_heap_content = $10,\n used_contract_hashes = $11,\n bootloader_code_hash = $12,\n default_aa_code_hash = $13,\n evm_emulator_code_hash = $14,\n protocol_version = $15,\n system_logs = $16,\n storage_refunds = $17,\n pubdata_costs = $18,\n pubdata_input = $19,\n predicted_circuits_by_type = $20,\n updated_at = NOW(),\n sealed_at = NOW(),\n is_sealed = TRUE\n WHERE\n number = $1\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8", - "Int4", - "Int4", - "ByteaArray", - "Bytea", - "ByteaArray", - "Int8", - "Int8", - "Int8", - "Jsonb", - "Jsonb", - "Bytea", - "Bytea", - "Bytea", - "Int4", - "ByteaArray", - "Int8Array", - "Int8Array", - "Bytea", - "Jsonb" - ] - }, - "nullable": [] - }, - "hash": "6069d168d5c4b5131b50500302cdde79388b62926ff83d954b4d93dedfe2503a" -} diff --git a/core/lib/dal/.sqlx/query-a0ad14cd53afb6c360e70c47dbd79d66dd9fbd20941aec20e2e8c3874b15a953.json b/core/lib/dal/.sqlx/query-a0ad14cd53afb6c360e70c47dbd79d66dd9fbd20941aec20e2e8c3874b15a953.json new file mode 100644 index 000000000000..a64bdb403aef --- /dev/null +++ b/core/lib/dal/.sqlx/query-a0ad14cd53afb6c360e70c47dbd79d66dd9fbd20941aec20e2e8c3874b15a953.json @@ -0,0 +1,30 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE l1_batches\n SET\n l1_tx_count = $2,\n l2_tx_count = $3,\n l2_to_l1_messages = $4,\n bloom = $5,\n priority_ops_onchain_data = $6,\n initial_bootloader_heap_content = $7,\n used_contract_hashes = $8,\n bootloader_code_hash = $9,\n default_aa_code_hash = $10,\n evm_emulator_code_hash = $11,\n protocol_version = $12,\n system_logs = $13,\n storage_refunds = $14,\n pubdata_costs = $15,\n pubdata_input = $16,\n predicted_circuits_by_type = $17,\n updated_at = NOW(),\n sealed_at = NOW(),\n is_sealed = TRUE\n WHERE\n number = $1\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "Int4", + "Int4", + "ByteaArray", + "Bytea", + "ByteaArray", + "Jsonb", + "Jsonb", + "Bytea", + "Bytea", + "Bytea", + "Int4", + "ByteaArray", + "Int8Array", + "Int8Array", + "Bytea", + "Jsonb" + ] + }, + "nullable": [] + }, + "hash": "a0ad14cd53afb6c360e70c47dbd79d66dd9fbd20941aec20e2e8c3874b15a953" +} diff --git a/core/lib/dal/.sqlx/query-cf3c7b918a3f82476543841d4dc5393ec02458104c483a2023b24881ae0c6716.json b/core/lib/dal/.sqlx/query-cf3c7b918a3f82476543841d4dc5393ec02458104c483a2023b24881ae0c6716.json deleted file mode 100644 index 59bfa4858c02..000000000000 --- a/core/lib/dal/.sqlx/query-cf3c7b918a3f82476543841d4dc5393ec02458104c483a2023b24881ae0c6716.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT\n COUNT(*) AS \"count!\"\n FROM\n (\n SELECT\n *\n FROM\n storage_logs\n WHERE\n hashed_key = $1\n AND miniblock_number <= COALESCE(\n (\n SELECT\n MAX(number)\n FROM\n miniblocks\n ),\n (\n SELECT\n miniblock_number\n FROM\n snapshot_recovery\n )\n )\n ORDER BY\n miniblock_number DESC,\n operation_number DESC\n LIMIT\n 1\n ) sl\n WHERE\n sl.value != $2\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "count!", - "type_info": "Int8" - } - ], - "parameters": { - "Left": [ - "Bytea", - "Bytea" - ] - }, - "nullable": [ - null - ] - }, - "hash": "cf3c7b918a3f82476543841d4dc5393ec02458104c483a2023b24881ae0c6716" -} diff --git a/core/lib/dal/src/blocks_dal.rs b/core/lib/dal/src/blocks_dal.rs index 0cb607a304e2..2df73a3cf615 100644 --- a/core/lib/dal/src/blocks_dal.rs +++ b/core/lib/dal/src/blocks_dal.rs @@ -17,8 +17,8 @@ use zksync_db_connection::{ use zksync_types::{ aggregated_operations::AggregatedActionType, block::{ - BlockGasCount, L1BatchHeader, L1BatchStatistics, L1BatchTreeData, L2BlockHeader, - StorageOracleInfo, UnsealedL1BatchHeader, + L1BatchHeader, L1BatchStatistics, L1BatchTreeData, L2BlockHeader, StorageOracleInfo, + UnsealedL1BatchHeader, }, commitment::{L1BatchCommitmentArtifacts, L1BatchWithMetadata}, fee_model::BatchFeeInput, @@ -688,7 +688,6 @@ impl BlocksDal<'_, '_> { &mut self, header: &L1BatchHeader, initial_bootloader_contents: &[(usize, U256)], - predicted_block_gas: BlockGasCount, storage_refunds: &[u32], pubdata_costs: &[i32], predicted_circuits_by_type: CircuitStatistic, // predicted number of circuits for each circuit type @@ -728,20 +727,17 @@ impl BlocksDal<'_, '_> { l2_to_l1_messages = $4, bloom = $5, priority_ops_onchain_data = $6, - predicted_commit_gas_cost = $7, - predicted_prove_gas_cost = $8, - predicted_execute_gas_cost = $9, - initial_bootloader_heap_content = $10, - used_contract_hashes = $11, - bootloader_code_hash = $12, - default_aa_code_hash = $13, - evm_emulator_code_hash = $14, - protocol_version = $15, - system_logs = $16, - storage_refunds = $17, - pubdata_costs = $18, - pubdata_input = $19, - predicted_circuits_by_type = $20, + initial_bootloader_heap_content = $7, + used_contract_hashes = $8, + bootloader_code_hash = $9, + default_aa_code_hash = $10, + evm_emulator_code_hash = $11, + protocol_version = $12, + system_logs = $13, + storage_refunds = $14, + pubdata_costs = $15, + pubdata_input = $16, + predicted_circuits_by_type = $17, updated_at = NOW(), sealed_at = NOW(), is_sealed = TRUE @@ -754,9 +750,6 @@ impl BlocksDal<'_, '_> { &header.l2_to_l1_messages, header.bloom.as_bytes(), &priority_onchain_data, - i64::from(predicted_block_gas.commit), - i64::from(predicted_block_gas.prove), - i64::from(predicted_block_gas.execute), initial_bootloader_contents, used_contract_hashes, header.base_system_contracts_hashes.bootloader.as_bytes(), @@ -2788,15 +2781,8 @@ impl BlocksDal<'_, '_> { header.to_unsealed_header(BatchFeeInput::pubdata_independent(100, 100, 100)), ) .await?; - self.mark_l1_batch_as_sealed( - header, - &[], - Default::default(), - &[], - &[], - Default::default(), - ) - .await + self.mark_l1_batch_as_sealed(header, &[], &[], &[], Default::default()) + .await } /// Deletes all L2 blocks and L1 batches, including the genesis ones. Should only be used in tests. @@ -3093,11 +3079,6 @@ mod tests { BaseSystemContractsHashes::default(), ProtocolVersionId::default(), ); - let mut predicted_gas = BlockGasCount { - commit: 2, - prove: 3, - execute: 10, - }; conn.blocks_dal() .insert_l1_batch( header.to_unsealed_header(BatchFeeInput::pubdata_independent(100, 100, 100)), @@ -3105,13 +3086,12 @@ mod tests { .await .unwrap(); conn.blocks_dal() - .mark_l1_batch_as_sealed(&header, &[], predicted_gas, &[], &[], Default::default()) + .mark_l1_batch_as_sealed(&header, &[], &[], &[], Default::default()) .await .unwrap(); header.number = L1BatchNumber(2); header.timestamp += 100; - predicted_gas += predicted_gas; conn.blocks_dal() .insert_l1_batch( header.to_unsealed_header(BatchFeeInput::pubdata_independent(100, 100, 100)), @@ -3119,7 +3099,7 @@ mod tests { .await .unwrap(); conn.blocks_dal() - .mark_l1_batch_as_sealed(&header, &[], predicted_gas, &[], &[], Default::default()) + .mark_l1_batch_as_sealed(&header, &[], &[], &[], Default::default()) .await .unwrap(); diff --git a/core/lib/types/src/block.rs b/core/lib/types/src/block.rs index 804da61b7295..c4fd3306f2d5 100644 --- a/core/lib/types/src/block.rs +++ b/core/lib/types/src/block.rs @@ -1,5 +1,3 @@ -use std::{fmt, ops}; - use serde::{Deserialize, Serialize}; use zksync_basic_types::{commitment::PubdataParams, Address, Bloom, BloomInput, H256, U256}; use zksync_contracts::BaseSystemContractsHashes; @@ -177,51 +175,6 @@ impl L1BatchHeader { } } -#[derive(Clone, Copy, Eq, PartialEq, Default)] -pub struct BlockGasCount { - pub commit: u32, - pub prove: u32, - pub execute: u32, -} - -impl fmt::Debug for BlockGasCount { - fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - formatter, - "c:{}/p:{}/e:{}", - self.commit, self.prove, self.execute - ) - } -} - -impl BlockGasCount { - pub fn any_field_greater_than(&self, bound: u32) -> bool { - self.commit > bound || self.prove > bound || self.execute > bound - } -} - -impl ops::Add for BlockGasCount { - type Output = Self; - - fn add(self, rhs: Self) -> Self::Output { - Self { - commit: self.commit + rhs.commit, - prove: self.prove + rhs.prove, - execute: self.execute + rhs.execute, - } - } -} - -impl ops::AddAssign for BlockGasCount { - fn add_assign(&mut self, other: Self) { - *self = Self { - commit: self.commit + other.commit, - prove: self.prove + other.prove, - execute: self.execute + other.execute, - }; - } -} - /// Hasher of L2 block contents used by the VM. #[derive(Debug)] pub struct L2BlockHasher { diff --git a/core/node/api_server/src/tx_sender/mod.rs b/core/node/api_server/src/tx_sender/mod.rs index 91fb84ab8f17..76cfb83aec54 100644 --- a/core/node/api_server/src/tx_sender/mod.rs +++ b/core/node/api_server/src/tx_sender/mod.rs @@ -671,7 +671,7 @@ impl TxSender { // but the API assumes we are post boojum. In this situation we will determine a tx as being executable but the StateKeeper will // still reject them as it's not. let protocol_version = ProtocolVersionId::latest(); - let seal_data = SealData::for_transaction(transaction, tx_metrics, protocol_version); + let seal_data = SealData::for_transaction(transaction, tx_metrics); if let Some(reason) = self .0 .sealer diff --git a/core/node/genesis/src/lib.rs b/core/node/genesis/src/lib.rs index 0a0e77d97f95..38972389129e 100644 --- a/core/node/genesis/src/lib.rs +++ b/core/node/genesis/src/lib.rs @@ -16,7 +16,7 @@ use zksync_merkle_tree::{domain::ZkSyncTree, TreeInstruction}; use zksync_multivm::utils::get_max_gas_per_pubdata_byte; use zksync_system_constants::PRIORITY_EXPIRATION; use zksync_types::{ - block::{BlockGasCount, DeployedContract, L1BatchHeader, L2BlockHasher, L2BlockHeader}, + block::{DeployedContract, L1BatchHeader, L2BlockHasher, L2BlockHeader}, bytecode::BytecodeHash, commitment::{CommitmentInput, L1BatchCommitment}, fee_model::BatchFeeInput, @@ -425,14 +425,7 @@ pub async fn create_genesis_l1_batch( .await?; transaction .blocks_dal() - .mark_l1_batch_as_sealed( - &genesis_l1_batch_header, - &[], - BlockGasCount::default(), - &[], - &[], - Default::default(), - ) + .mark_l1_batch_as_sealed(&genesis_l1_batch_header, &[], &[], &[], Default::default()) .await?; transaction .blocks_dal() diff --git a/core/node/state_keeper/src/executor/mod.rs b/core/node/state_keeper/src/executor/mod.rs index 903dae2f1cad..a6c7b92fa249 100644 --- a/core/node/state_keeper/src/executor/mod.rs +++ b/core/node/state_keeper/src/executor/mod.rs @@ -1,25 +1,23 @@ use zksync_multivm::interface::{ BatchTransactionExecutionResult, Call, CompressedBytecodeInfo, ExecutionResult, Halt, - VmExecutionResultAndLogs, + VmExecutionMetrics, VmExecutionResultAndLogs, }; use zksync_types::Transaction; pub use zksync_vm_executor::batch::MainBatchExecutorFactory; -use crate::ExecutionMetricsForCriteria; - #[cfg(test)] mod tests; /// State keeper representation of a transaction executed in the virtual machine. /// /// A separate type allows to be more typesafe when dealing with halted transactions. It also simplifies testing seal criteria -/// (i.e., without picking transactions that actually produce appropriate `ExecutionMetricsForCriteria`). +/// (i.e., without picking transactions that actually produce appropriate `VmExecutionMetrics`). #[derive(Debug, Clone)] pub enum TxExecutionResult { /// Successful execution of the tx and the block tip dry run. Success { tx_result: Box, - tx_metrics: Box, + tx_metrics: Box, compressed_bytecodes: Vec, call_tracer_result: Vec, gas_remaining: u32, @@ -38,7 +36,7 @@ impl TxExecutionResult { } => Self::BootloaderOutOfGasForTx, ExecutionResult::Halt { reason } => Self::RejectedByVm { reason }, _ => Self::Success { - tx_metrics: Box::new(ExecutionMetricsForCriteria::new(Some(tx), &res.tx_result)), + tx_metrics: Box::new(res.tx_result.get_execution_metrics(Some(tx))), gas_remaining: res.tx_result.statistics.gas_remaining, tx_result: res.tx_result.clone(), compressed_bytecodes: res.compressed_bytecodes, diff --git a/core/node/state_keeper/src/io/persistence.rs b/core/node/state_keeper/src/io/persistence.rs index d8fd99bfc95d..8db7fe4120ed 100644 --- a/core/node/state_keeper/src/io/persistence.rs +++ b/core/node/state_keeper/src/io/persistence.rs @@ -386,8 +386,8 @@ mod tests { use zksync_multivm::interface::{FinishedL1Batch, VmExecutionMetrics}; use zksync_node_genesis::{insert_genesis_batch, GenesisParams}; use zksync_types::{ - api::TransactionStatus, block::BlockGasCount, h256_to_u256, writes::StateDiffRecord, - L1BatchNumber, L2BlockNumber, StorageLogKind, H256, U256, + api::TransactionStatus, h256_to_u256, writes::StateDiffRecord, L1BatchNumber, + L2BlockNumber, StorageLogKind, H256, U256, }; use super::*; @@ -508,7 +508,6 @@ mod tests { tx, tx_result, vec![], - BlockGasCount::default(), VmExecutionMetrics::default(), vec![], ); diff --git a/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs b/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs index a6356a838602..8c1730b88cf1 100644 --- a/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs +++ b/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs @@ -538,7 +538,6 @@ mod tests { user_l2_to_l1_logs, system_l2_to_l1_logs: Default::default(), new_factory_deps, - l1_gas_count: Default::default(), block_execution_metrics: Default::default(), txs_encoding_size: Default::default(), payload_encoding_size: Default::default(), diff --git a/core/node/state_keeper/src/io/seal_logic/mod.rs b/core/node/state_keeper/src/io/seal_logic/mod.rs index 419413e127d3..655bf182ba8f 100644 --- a/core/node/state_keeper/src/io/seal_logic/mod.rs +++ b/core/node/state_keeper/src/io/seal_logic/mod.rs @@ -145,7 +145,6 @@ impl UpdatesManager { .mark_l1_batch_as_sealed( &l1_batch, &final_bootloader_memory, - self.pending_l1_gas_count(), &finished_batch.final_execution_state.storage_refunds, &finished_batch.final_execution_state.pubdata_costs, self.pending_execution_metrics().circuit_statistic, diff --git a/core/node/state_keeper/src/io/tests/mod.rs b/core/node/state_keeper/src/io/tests/mod.rs index 5a44bf71ad39..15164328b7a0 100644 --- a/core/node/state_keeper/src/io/tests/mod.rs +++ b/core/node/state_keeper/src/io/tests/mod.rs @@ -13,7 +13,7 @@ use zksync_multivm::{ use zksync_node_test_utils::prepare_recovery_snapshot; use zksync_system_constants::KNOWN_CODES_STORAGE_ADDRESS; use zksync_types::{ - block::{BlockGasCount, L2BlockHasher}, + block::L2BlockHasher, bytecode::BytecodeHash, commitment::{L1BatchCommitmentMode, PubdataParams}, fee_model::{BatchFeeInput, PubdataIndependentBatchFeeModelInput}, @@ -279,7 +279,6 @@ async fn processing_storage_logs_when_sealing_l2_block() { l2_block.extend_from_executed_transaction( tx, execution_result, - BlockGasCount::default(), VmExecutionMetrics::default(), vec![], vec![], @@ -297,7 +296,6 @@ async fn processing_storage_logs_when_sealing_l2_block() { l2_block.extend_from_executed_transaction( tx, execution_result, - BlockGasCount::default(), VmExecutionMetrics::default(), vec![], vec![], @@ -371,7 +369,6 @@ async fn processing_events_when_sealing_l2_block() { l2_block.extend_from_executed_transaction( tx, execution_result, - BlockGasCount::default(), VmExecutionMetrics::default(), vec![], vec![], @@ -476,7 +473,6 @@ async fn processing_dynamic_factory_deps_when_sealing_l2_block() { l2_block.extend_from_executed_transaction( tx, execution_result, - BlockGasCount::default(), VmExecutionMetrics::default(), vec![], vec![], @@ -571,7 +567,6 @@ async fn l2_block_processing_after_snapshot_recovery(commitment_mode: L1BatchCom tx.into(), create_execution_result([]), vec![], - BlockGasCount::default(), VmExecutionMetrics::default(), vec![], ); diff --git a/core/node/state_keeper/src/keeper.rs b/core/node/state_keeper/src/keeper.rs index fe37ee8d8dd6..83b447936408 100644 --- a/core/node/state_keeper/src/keeper.rs +++ b/core/node/state_keeper/src/keeper.rs @@ -27,9 +27,7 @@ use crate::{ io::{IoCursor, L1BatchParams, L2BlockParams, OutputHandler, PendingBatchData, StateKeeperIO}, metrics::{AGGREGATION_METRICS, KEEPER_METRICS, L1_BATCH_METRICS}, seal_criteria::{ConditionalSealer, SealData, SealResolution, UnexecutableReason}, - types::ExecutionMetricsForCriteria, updates::UpdatesManager, - utils::gas_count_from_writes, }; /// Amount of time to block on waiting for some resource. The exact value is not really important, @@ -474,7 +472,7 @@ impl ZkSyncStateKeeper { let TxExecutionResult::Success { tx_result, - tx_metrics, + tx_metrics: tx_execution_metrics, compressed_bytecodes, call_tracer_result, .. @@ -491,11 +489,6 @@ impl ZkSyncStateKeeper { .into()); }; - let ExecutionMetricsForCriteria { - l1_gas: tx_l1_gas_this_tx, - execution_metrics: tx_execution_metrics, - } = *tx_metrics; - let tx_hash = tx.hash(); let is_l1 = tx.is_l1(); let exec_result_status = tx_result.result.clone(); @@ -505,20 +498,17 @@ impl ZkSyncStateKeeper { tx, *tx_result, compressed_bytecodes, - tx_l1_gas_this_tx, - tx_execution_metrics, + *tx_execution_metrics, call_tracer_result, ); tracing::debug!( "Finished re-executing tx {tx_hash} by {initiator_account} (is_l1: {is_l1}, \ #{idx_in_l1_batch} in L1 batch #{l1_batch_number}, #{idx_in_l2_block} in L2 block #{l2_block_number}); \ - status: {exec_result_status:?}. L1 gas spent: {tx_l1_gas_this_tx:?}, total in L1 batch: {pending_l1_gas:?}, \ - tx execution metrics: {tx_execution_metrics:?}, block execution metrics: {block_execution_metrics:?}", + status: {exec_result_status:?}. Tx execution metrics: {tx_execution_metrics:?}, block execution metrics: {block_execution_metrics:?}", idx_in_l1_batch = updates_manager.pending_executed_transactions_len(), l1_batch_number = updates_manager.l1_batch.number, idx_in_l2_block = updates_manager.l2_block.executed_transactions.len(), - pending_l1_gas = updates_manager.pending_l1_gas_count(), block_execution_metrics = updates_manager.pending_execution_metrics() ); } @@ -612,7 +602,7 @@ impl ZkSyncStateKeeper { SealResolution::NoSeal | SealResolution::IncludeAndSeal => { let TxExecutionResult::Success { tx_result, - tx_metrics, + tx_metrics: tx_execution_metrics, call_tracer_result, compressed_bytecodes, .. @@ -622,16 +612,11 @@ impl ZkSyncStateKeeper { "Tx inclusion seal resolution must be a result of a successful tx execution", ); }; - let ExecutionMetricsForCriteria { - l1_gas: tx_l1_gas_this_tx, - execution_metrics: tx_execution_metrics, - } = *tx_metrics; updates_manager.extend_from_executed_transaction( tx, *tx_result, compressed_bytecodes, - tx_l1_gas_this_tx, - tx_execution_metrics, + *tx_execution_metrics, call_tracer_result, ); } @@ -687,7 +672,7 @@ impl ZkSyncStateKeeper { SealResolution::NoSeal | SealResolution::IncludeAndSeal => { let TxExecutionResult::Success { tx_result, - tx_metrics, + tx_metrics: tx_execution_metrics, compressed_bytecodes, call_tracer_result, .. @@ -702,17 +687,11 @@ impl ZkSyncStateKeeper { anyhow::bail!("Failed upgrade tx {:?}", tx.hash()); } - let ExecutionMetricsForCriteria { - l1_gas: tx_l1_gas_this_tx, - execution_metrics: tx_execution_metrics, - .. - } = *tx_metrics; updates_manager.extend_from_executed_transaction( tx, *tx_result, compressed_bytecodes, - tx_l1_gas_this_tx, - tx_execution_metrics, + *tx_execution_metrics, call_tracer_result, ); Ok(()) @@ -796,20 +775,15 @@ impl ZkSyncStateKeeper { } TxExecutionResult::Success { tx_result, - tx_metrics, + tx_metrics: tx_execution_metrics, gas_remaining, .. } => { let tx_execution_status = &tx_result.result; - let ExecutionMetricsForCriteria { - l1_gas: tx_l1_gas_this_tx, - execution_metrics: tx_execution_metrics, - } = **tx_metrics; tracing::trace!( "finished tx {:?} by {:?} (is_l1: {}) (#{} in l1 batch {}) (#{} in L2 block {}) \ - status: {:?}. L1 gas spent: {:?}, total in l1 batch: {:?}, \ - tx execution metrics: {:?}, block execution metrics: {:?}", + status: {:?}. Tx execution metrics: {:?}, block execution metrics: {:?}", tx.hash(), tx.initiator_account(), tx.is_l1(), @@ -818,10 +792,8 @@ impl ZkSyncStateKeeper { updates_manager.l2_block.executed_transactions.len() + 1, updates_manager.l2_block.number, tx_execution_status, - tx_l1_gas_this_tx, - updates_manager.pending_l1_gas_count() + tx_l1_gas_this_tx, &tx_execution_metrics, - updates_manager.pending_execution_metrics() + tx_execution_metrics, + updates_manager.pending_execution_metrics() + **tx_execution_metrics, ); let encoding_len = tx.encoding_len(); @@ -831,20 +803,11 @@ impl ZkSyncStateKeeper { .storage_writes_deduplicator .apply_and_rollback(logs_to_apply_iter.clone()); - let block_writes_l1_gas = gas_count_from_writes( - &block_writes_metrics, - updates_manager.protocol_version(), - ); - let tx_writes_metrics = StorageWritesDeduplicator::apply_on_empty_state(logs_to_apply_iter); - let tx_writes_l1_gas = - gas_count_from_writes(&tx_writes_metrics, updates_manager.protocol_version()); - let tx_gas_excluding_writes = tx_l1_gas_this_tx; let tx_data = SealData { - execution_metrics: tx_execution_metrics, - gas_count: tx_gas_excluding_writes + tx_writes_l1_gas, + execution_metrics: **tx_execution_metrics, cumulative_size: encoding_len, writes_metrics: tx_writes_metrics, gas_remaining: *gas_remaining, @@ -852,9 +815,6 @@ impl ZkSyncStateKeeper { let block_data = SealData { execution_metrics: tx_data.execution_metrics + updates_manager.pending_execution_metrics(), - gas_count: tx_gas_excluding_writes - + block_writes_l1_gas - + updates_manager.pending_l1_gas_count(), cumulative_size: tx_data.cumulative_size + updates_manager.pending_txs_encoding_size(), writes_metrics: block_writes_metrics, diff --git a/core/node/state_keeper/src/lib.rs b/core/node/state_keeper/src/lib.rs index c12e4163fdd4..d838e6f66478 100644 --- a/core/node/state_keeper/src/lib.rs +++ b/core/node/state_keeper/src/lib.rs @@ -7,7 +7,7 @@ pub use self::{ mempool_actor::MempoolFetcher, seal_criteria::SequencerSealer, state_keeper_storage::AsyncRocksdbCache, - types::{ExecutionMetricsForCriteria, MempoolGuard}, + types::MempoolGuard, updates::UpdatesManager, }; diff --git a/core/node/state_keeper/src/seal_criteria/conditional_sealer.rs b/core/node/state_keeper/src/seal_criteria/conditional_sealer.rs index cd00d4f89360..bdb4a86cb794 100644 --- a/core/node/state_keeper/src/seal_criteria/conditional_sealer.rs +++ b/core/node/state_keeper/src/seal_criteria/conditional_sealer.rs @@ -132,7 +132,6 @@ impl SequencerSealer { fn default_sealers(config: &StateKeeperConfig) -> Vec> { vec![ Box::new(criteria::SlotsCriterion), - Box::new(criteria::GasCriterion), Box::new(criteria::PubDataBytesCriterion { max_pubdata_per_batch: config.max_pubdata_per_batch, }), diff --git a/core/node/state_keeper/src/seal_criteria/criteria/gas.rs b/core/node/state_keeper/src/seal_criteria/criteria/gas.rs deleted file mode 100644 index a97ac6ede353..000000000000 --- a/core/node/state_keeper/src/seal_criteria/criteria/gas.rs +++ /dev/null @@ -1,180 +0,0 @@ -use zksync_types::ProtocolVersionId; - -use crate::{ - seal_criteria::{ - SealCriterion, SealData, SealResolution, StateKeeperConfig, UnexecutableReason, - }, - utils::new_block_gas_count, -}; - -/// This is a temporary solution. -/// Instead of checking for gas it simply checks that the contracts' -/// bytecode is large enough. -/// Among all the data which will be published on-chain the contracts' -/// bytecode is by far the largest one and with high probability -/// the slots will run out before the other pubdata becomes too big -#[derive(Debug)] -pub(crate) struct GasCriterion; - -impl SealCriterion for GasCriterion { - fn should_seal( - &self, - config: &StateKeeperConfig, - _block_open_timestamp_ms: u128, - _tx_count: usize, - block_data: &SealData, - tx_data: &SealData, - _protocol_version_id: ProtocolVersionId, - ) -> SealResolution { - let tx_bound = - (config.max_single_tx_gas as f64 * config.reject_tx_at_gas_percentage).round() as u32; - let block_bound = - (config.max_single_tx_gas as f64 * config.close_block_at_gas_percentage).round() as u32; - - if (tx_data.gas_count + new_block_gas_count()).any_field_greater_than(tx_bound) { - UnexecutableReason::TooMuchGas.into() - } else if block_data - .gas_count - .any_field_greater_than(config.max_single_tx_gas) - { - SealResolution::ExcludeAndSeal - } else if block_data.gas_count.any_field_greater_than(block_bound) { - SealResolution::IncludeAndSeal - } else { - SealResolution::NoSeal - } - } - - fn prom_criterion_name(&self) -> &'static str { - "gas" - } -} - -#[cfg(test)] -mod tests { - use zksync_types::block::BlockGasCount; - - use super::*; - - #[test] - fn test_gas_seal_criterion() { - // Create an empty config and only setup fields relevant for the test. - let config = StateKeeperConfig { - max_single_tx_gas: 6000000, - reject_tx_at_gas_percentage: 0.95, - close_block_at_gas_percentage: 0.95, - ..Default::default() - }; - - let criterion = GasCriterion; - - // Empty block should fit into gas criterion. - let empty_block_gas = new_block_gas_count(); - let empty_block_resolution = criterion.should_seal( - &config, - 0, - 0, - &SealData { - gas_count: empty_block_gas, - ..SealData::default() - }, - &SealData::default(), - ProtocolVersionId::latest(), - ); - assert_eq!(empty_block_resolution, SealResolution::NoSeal); - - let tx_gas = BlockGasCount { - commit: config.max_single_tx_gas + 1, - prove: 0, - execute: 0, - }; - // Transaction that needs more gas than a block limit should be unexecutable. - let huge_transaction_resolution = criterion.should_seal( - &config, - 0, - 1, - &SealData { - gas_count: empty_block_gas + tx_gas, - ..SealData::default() - }, - &SealData { - gas_count: tx_gas, - ..SealData::default() - }, - ProtocolVersionId::latest(), - ); - assert_eq!( - huge_transaction_resolution, - UnexecutableReason::TooMuchGas.into() - ); - - // Check criterion workflow - let reject_tx_bound = - (config.max_single_tx_gas as f64 * config.reject_tx_at_gas_percentage).round() as u32; - let tx_gas = BlockGasCount { - commit: reject_tx_bound - empty_block_gas.commit, - prove: reject_tx_bound - empty_block_gas.prove, - execute: reject_tx_bound - empty_block_gas.execute, - }; - let resolution_after_first_tx = criterion.should_seal( - &config, - 0, - 1, - &SealData { - gas_count: empty_block_gas + tx_gas, - ..SealData::default() - }, - &SealData { - gas_count: tx_gas, - ..SealData::default() - }, - ProtocolVersionId::latest(), - ); - assert_eq!(resolution_after_first_tx, SealResolution::NoSeal); - - let resolution_after_second_tx = criterion.should_seal( - &config, - 0, - 2, - &SealData { - gas_count: empty_block_gas + tx_gas + tx_gas, - ..SealData::default() - }, - &SealData { - gas_count: tx_gas, - ..SealData::default() - }, - ProtocolVersionId::latest(), - ); - assert_eq!(resolution_after_second_tx, SealResolution::ExcludeAndSeal); - - // Check criterion workflow - let tx_gas = BlockGasCount { - commit: reject_tx_bound - empty_block_gas.commit - 1, - prove: reject_tx_bound - empty_block_gas.prove - 1, - execute: reject_tx_bound - empty_block_gas.execute - 1, - }; - let close_bound = - (config.max_single_tx_gas as f64 * config.close_block_at_gas_percentage).round() as u32; - let block_gas = BlockGasCount { - commit: close_bound + 1, - prove: close_bound + 1, - execute: close_bound + 1, - }; - let resolution_after_first_tx = criterion.should_seal( - &config, - 0, - 1, - &SealData { - gas_count: block_gas, - ..SealData::default() - }, - &SealData { - gas_count: tx_gas, - ..SealData::default() - }, - ProtocolVersionId::latest(), - ); - assert_eq!(resolution_after_first_tx, SealResolution::IncludeAndSeal); - } -} diff --git a/core/node/state_keeper/src/seal_criteria/criteria/mod.rs b/core/node/state_keeper/src/seal_criteria/criteria/mod.rs index 6732a8cd2717..662efa1485b6 100644 --- a/core/node/state_keeper/src/seal_criteria/criteria/mod.rs +++ b/core/node/state_keeper/src/seal_criteria/criteria/mod.rs @@ -1,4 +1,3 @@ -mod gas; mod gas_for_batch_tip; mod geometry_seal_criteria; mod pubdata_bytes; @@ -6,7 +5,7 @@ mod slots; mod tx_encoding_size; pub(crate) use self::{ - gas::GasCriterion, gas_for_batch_tip::GasForBatchTipCriterion, - geometry_seal_criteria::CircuitsCriterion, pubdata_bytes::PubDataBytesCriterion, - slots::SlotsCriterion, tx_encoding_size::TxEncodingSizeCriterion, + gas_for_batch_tip::GasForBatchTipCriterion, geometry_seal_criteria::CircuitsCriterion, + pubdata_bytes::PubDataBytesCriterion, slots::SlotsCriterion, + tx_encoding_size::TxEncodingSizeCriterion, }; diff --git a/core/node/state_keeper/src/seal_criteria/mod.rs b/core/node/state_keeper/src/seal_criteria/mod.rs index 4c6f56a6f5b7..85b805a98283 100644 --- a/core/node/state_keeper/src/seal_criteria/mod.rs +++ b/core/node/state_keeper/src/seal_criteria/mod.rs @@ -17,16 +17,10 @@ use zksync_multivm::{ interface::{DeduplicatedWritesMetrics, Halt, TransactionExecutionMetrics, VmExecutionMetrics}, vm_latest::TransactionVmExt, }; -use zksync_types::{ - block::BlockGasCount, utils::display_timestamp, ProtocolVersionId, Transaction, -}; +use zksync_types::{utils::display_timestamp, ProtocolVersionId, Transaction}; pub use self::conditional_sealer::{ConditionalSealer, NoopSealer, SequencerSealer}; -use crate::{ - metrics::AGGREGATION_METRICS, - updates::UpdatesManager, - utils::{gas_count_from_tx_and_metrics, gas_count_from_writes, millis_since}, -}; +use crate::{metrics::AGGREGATION_METRICS, updates::UpdatesManager, utils::millis_since}; mod conditional_sealer; pub(super) mod criteria; @@ -159,7 +153,6 @@ impl SealResolution { #[derive(Debug, Default)] pub struct SealData { pub(super) execution_metrics: VmExecutionMetrics, - pub(super) gas_count: BlockGasCount, pub(super) cumulative_size: usize, pub(super) writes_metrics: DeduplicatedWritesMetrics, pub(super) gas_remaining: u32, @@ -171,15 +164,11 @@ impl SealData { pub fn for_transaction( transaction: &Transaction, tx_metrics: &TransactionExecutionMetrics, - protocol_version: ProtocolVersionId, ) -> Self { let execution_metrics = VmExecutionMetrics::from_tx_metrics(tx_metrics); let writes_metrics = DeduplicatedWritesMetrics::from_tx_metrics(tx_metrics); - let gas_count = gas_count_from_tx_and_metrics(transaction, &execution_metrics) - + gas_count_from_writes(&writes_metrics, protocol_version); Self { execution_metrics, - gas_count, cumulative_size: transaction.bootloader_encoding_size(), writes_metrics, gas_remaining: tx_metrics.gas_remaining, @@ -287,7 +276,6 @@ mod tests { tx, create_execution_result([]), vec![], - BlockGasCount::default(), VmExecutionMetrics::default(), vec![], ); diff --git a/core/node/state_keeper/src/tests/mod.rs b/core/node/state_keeper/src/tests/mod.rs index ca078354c896..4911ae72a0ae 100644 --- a/core/node/state_keeper/src/tests/mod.rs +++ b/core/node/state_keeper/src/tests/mod.rs @@ -17,8 +17,7 @@ use zksync_multivm::{ }; use zksync_node_test_utils::create_l2_transaction; use zksync_types::{ - aggregated_operations::AggregatedActionType, - block::{BlockGasCount, L2BlockExecutionData, L2BlockHasher}, + block::{L2BlockExecutionData, L2BlockHasher}, fee_model::{BatchFeeInput, PubdataIndependentBatchFeeModelInput}, u256_to_h256, AccountTreeId, Address, L1BatchNumber, L2BlockNumber, L2ChainId, ProtocolVersionId, StorageKey, StorageLog, StorageLogKind, StorageLogWithPreviousValue, @@ -28,20 +27,16 @@ use zksync_types::{ use crate::{ io::PendingBatchData, keeper::POLL_WAIT_DURATION, - seal_criteria::{ - criteria::{GasCriterion, SlotsCriterion}, - SequencerSealer, UnexecutableReason, - }, + seal_criteria::{criteria::SlotsCriterion, SequencerSealer, UnexecutableReason}, testonly::{ successful_exec, test_batch_executor::{ - random_tx, random_upgrade_tx, rejected_exec, successful_exec_with_log, - MockReadStorageFactory, TestBatchExecutorBuilder, TestIO, TestScenario, FEE_ACCOUNT, + random_tx, random_upgrade_tx, rejected_exec, MockReadStorageFactory, + TestBatchExecutorBuilder, TestIO, TestScenario, FEE_ACCOUNT, }, BASE_SYSTEM_CONTRACTS, }, updates::UpdatesManager, - utils::{gas_count_from_tx_and_metrics, l1_batch_base_cost}, ZkSyncStateKeeper, }; @@ -188,86 +183,6 @@ async fn sealed_by_number_of_txs() { .await; } -#[tokio::test] -async fn sealed_by_gas() { - let first_tx = random_tx(1); - let execution_result = successful_exec_with_log(); - let exec_metrics = execution_result - .tx_result - .get_execution_metrics(Some(&first_tx)); - assert!(exec_metrics.size() > 0); - let l1_gas_per_tx = gas_count_from_tx_and_metrics(&first_tx, &exec_metrics); - assert!(l1_gas_per_tx.commit > 0); - - let config = StateKeeperConfig { - max_single_tx_gas: 62_000 + l1_gas_per_tx.commit * 2, - reject_tx_at_gas_percentage: 1.0, - close_block_at_gas_percentage: 0.5, - ..StateKeeperConfig::default() - }; - let sealer = SequencerSealer::with_sealers(config, vec![Box::new(GasCriterion)]); - - TestScenario::new() - .seal_l2_block_when(|updates| { - updates.l2_block.executed_transactions.len() == 1 - }) - .next_tx("First tx", first_tx, execution_result.clone()) - .l2_block_sealed_with("L2 block with a single tx", move |updates| { - assert_eq!( - updates.l2_block.l1_gas_count, - l1_gas_per_tx, - "L1 gas used by a L2 block should consist of the gas used by its txs" - ); - }) - .next_tx("Second tx", random_tx(1), execution_result) - .l2_block_sealed("L2 block 2") - .batch_sealed_with("Batch sealed with both txs", move |updates| { - assert_eq!( - updates.l1_batch.l1_gas_count, - BlockGasCount { - commit: l1_batch_base_cost(AggregatedActionType::Commit) + l1_gas_per_tx.commit * 2, - prove: l1_batch_base_cost(AggregatedActionType::PublishProofOnchain), - execute: l1_batch_base_cost(AggregatedActionType::Execute), - }, - "L1 gas used by a batch should consist of gas used by its txs + basic block gas cost" - ); - }) - .run(sealer).await; -} - -#[tokio::test] -async fn sealed_by_gas_then_by_num_tx() { - let config = StateKeeperConfig { - max_single_tx_gas: 62_000, - reject_tx_at_gas_percentage: 1.0, - close_block_at_gas_percentage: 0.5, - transaction_slots: 3, - ..StateKeeperConfig::default() - }; - let sealer = SequencerSealer::with_sealers( - config, - vec![Box::new(GasCriterion), Box::new(SlotsCriterion)], - ); - - let execution_result = successful_exec_with_log(); - - // 1st tx is sealed by gas sealer; 2nd, 3rd, & 4th are sealed by slots sealer. - TestScenario::new() - .seal_l2_block_when(|updates| updates.l2_block.executed_transactions.len() == 1) - .next_tx("First tx", random_tx(1), execution_result) - .l2_block_sealed("L2 block 1") - .batch_sealed("Batch 1") - .next_tx("Second tx", random_tx(2), successful_exec()) - .l2_block_sealed("L2 block 2") - .next_tx("Third tx", random_tx(3), successful_exec()) - .l2_block_sealed("L2 block 3") - .next_tx("Fourth tx", random_tx(4), successful_exec()) - .l2_block_sealed("L2 block 4") - .batch_sealed("Batch 2") - .run(sealer) - .await; -} - #[tokio::test] async fn batch_sealed_before_l2_block_does() { let config = StateKeeperConfig { diff --git a/core/node/state_keeper/src/types.rs b/core/node/state_keeper/src/types.rs index db18e32e0963..4861916fc227 100644 --- a/core/node/state_keeper/src/types.rs +++ b/core/node/state_keeper/src/types.rs @@ -5,15 +5,9 @@ use std::{ use zksync_dal::{Connection, Core, CoreDal}; use zksync_mempool::{L2TxFilter, MempoolInfo, MempoolStore}; -use zksync_multivm::interface::{VmExecutionMetrics, VmExecutionResultAndLogs}; -use zksync_types::{ - block::BlockGasCount, Address, Nonce, PriorityOpId, Transaction, TransactionTimeRangeConstraint, -}; +use zksync_types::{Address, Nonce, PriorityOpId, Transaction, TransactionTimeRangeConstraint}; -use super::{ - metrics::StateKeeperGauges, - utils::{gas_count_from_metrics, gas_count_from_tx_and_metrics}, -}; +use super::metrics::StateKeeperGauges; #[derive(Debug, Clone)] pub struct MempoolGuard(Arc>); @@ -101,27 +95,3 @@ impl MempoolGuard { StateKeeperGauges::register(Arc::downgrade(&self.0)); } } - -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct ExecutionMetricsForCriteria { - pub l1_gas: BlockGasCount, - pub execution_metrics: VmExecutionMetrics, -} - -impl ExecutionMetricsForCriteria { - pub fn new( - tx: Option<&Transaction>, - execution_result: &VmExecutionResultAndLogs, - ) -> ExecutionMetricsForCriteria { - let execution_metrics = execution_result.get_execution_metrics(tx); - let l1_gas = match tx { - Some(tx) => gas_count_from_tx_and_metrics(tx, &execution_metrics), - None => gas_count_from_metrics(&execution_metrics), - }; - - ExecutionMetricsForCriteria { - l1_gas, - execution_metrics, - } - } -} diff --git a/core/node/state_keeper/src/updates/l1_batch_updates.rs b/core/node/state_keeper/src/updates/l1_batch_updates.rs index aa2e22cac483..fc0aa555934a 100644 --- a/core/node/state_keeper/src/updates/l1_batch_updates.rs +++ b/core/node/state_keeper/src/updates/l1_batch_updates.rs @@ -1,10 +1,9 @@ use zksync_multivm::interface::{FinishedL1Batch, TransactionExecutionResult, VmExecutionMetrics}; use zksync_types::{ - block::BlockGasCount, priority_op_onchain_data::PriorityOpOnchainData, - ExecuteTransactionCommon, L1BatchNumber, + priority_op_onchain_data::PriorityOpOnchainData, ExecuteTransactionCommon, L1BatchNumber, }; -use crate::{updates::l2_block_updates::L2BlockUpdates, utils::new_block_gas_count}; +use crate::updates::l2_block_updates::L2BlockUpdates; #[derive(Debug)] pub struct L1BatchUpdates { @@ -12,8 +11,6 @@ pub struct L1BatchUpdates { pub executed_transactions: Vec, pub priority_ops_onchain_data: Vec, pub block_execution_metrics: VmExecutionMetrics, - // how much L1 gas will it take to submit this block? - pub l1_gas_count: BlockGasCount, pub txs_encoding_size: usize, pub finished: Option, } @@ -25,7 +22,6 @@ impl L1BatchUpdates { executed_transactions: Default::default(), priority_ops_onchain_data: Default::default(), block_execution_metrics: Default::default(), - l1_gas_count: new_block_gas_count(), txs_encoding_size: 0, finished: None, } @@ -41,7 +37,6 @@ impl L1BatchUpdates { self.executed_transactions .extend(l2_block_updates.executed_transactions); - self.l1_gas_count += l2_block_updates.l1_gas_count; self.block_execution_metrics += l2_block_updates.block_execution_metrics; self.txs_encoding_size += l2_block_updates.txs_encoding_size; } @@ -53,10 +48,7 @@ mod tests { use zksync_types::{L2BlockNumber, ProtocolVersionId, H256}; use super::*; - use crate::{ - tests::{create_execution_result, create_transaction}, - utils::new_block_gas_count, - }; + use crate::tests::{create_execution_result, create_transaction}; #[test] fn apply_l2_block_with_empty_tx() { @@ -73,7 +65,6 @@ mod tests { l2_block_accumulator.extend_from_executed_transaction( tx, create_execution_result([]), - BlockGasCount::default(), VmExecutionMetrics::default(), vec![], vec![], @@ -83,7 +74,6 @@ mod tests { l1_batch_accumulator.extend_from_sealed_l2_block(l2_block_accumulator); assert_eq!(l1_batch_accumulator.executed_transactions.len(), 1); - assert_eq!(l1_batch_accumulator.l1_gas_count, new_block_gas_count()); assert_eq!(l1_batch_accumulator.priority_ops_onchain_data.len(), 0); assert_eq!( l1_batch_accumulator.block_execution_metrics.l2_to_l1_logs, diff --git a/core/node/state_keeper/src/updates/l2_block_updates.rs b/core/node/state_keeper/src/updates/l2_block_updates.rs index d258f8eeac0b..4130e9e1ea5e 100644 --- a/core/node/state_keeper/src/updates/l2_block_updates.rs +++ b/core/node/state_keeper/src/updates/l2_block_updates.rs @@ -8,7 +8,7 @@ use zksync_multivm::{ vm_latest::TransactionVmExt, }; use zksync_types::{ - block::{BlockGasCount, L2BlockHasher}, + block::L2BlockHasher, bytecode::BytecodeHash, l2_to_l1_log::{SystemL2ToL1Log, UserL2ToL1Log}, L2BlockNumber, ProtocolVersionId, StorageLogWithPreviousValue, Transaction, H256, @@ -24,8 +24,6 @@ pub struct L2BlockUpdates { pub user_l2_to_l1_logs: Vec, pub system_l2_to_l1_logs: Vec, pub new_factory_deps: HashMap>, - /// How much L1 gas will it take to submit this block? - pub l1_gas_count: BlockGasCount, pub block_execution_metrics: VmExecutionMetrics, pub txs_encoding_size: usize, pub payload_encoding_size: usize, @@ -51,7 +49,6 @@ impl L2BlockUpdates { user_l2_to_l1_logs: vec![], system_l2_to_l1_logs: vec![], new_factory_deps: HashMap::new(), - l1_gas_count: BlockGasCount::default(), block_execution_metrics: VmExecutionMetrics::default(), txs_encoding_size: 0, payload_encoding_size: 0, @@ -66,7 +63,6 @@ impl L2BlockUpdates { pub(crate) fn extend_from_fictive_transaction( &mut self, result: VmExecutionResultAndLogs, - l1_gas_count: BlockGasCount, execution_metrics: VmExecutionMetrics, ) { self.events.extend(result.logs.events); @@ -76,7 +72,6 @@ impl L2BlockUpdates { self.system_l2_to_l1_logs .extend(result.logs.system_l2_to_l1_logs); - self.l1_gas_count += l1_gas_count; self.block_execution_metrics += execution_metrics; } @@ -85,7 +80,6 @@ impl L2BlockUpdates { &mut self, tx: Transaction, tx_execution_result: VmExecutionResultAndLogs, - tx_l1_gas_this_tx: BlockGasCount, execution_metrics: VmExecutionMetrics, compressed_bytecodes: Vec, call_traces: Vec, @@ -143,7 +137,6 @@ impl L2BlockUpdates { }); self.new_factory_deps.extend(known_bytecodes); - self.l1_gas_count += tx_l1_gas_this_tx; self.block_execution_metrics += execution_metrics; self.txs_encoding_size += tx.bootloader_encoding_size(); self.payload_encoding_size += @@ -212,7 +205,6 @@ mod tests { accumulator.extend_from_executed_transaction( tx, create_execution_result([]), - BlockGasCount::default(), VmExecutionMetrics::default(), vec![], vec![], @@ -223,7 +215,6 @@ mod tests { assert_eq!(accumulator.storage_logs.len(), 0); assert_eq!(accumulator.user_l2_to_l1_logs.len(), 0); assert_eq!(accumulator.system_l2_to_l1_logs.len(), 0); - assert_eq!(accumulator.l1_gas_count, Default::default()); assert_eq!(accumulator.new_factory_deps.len(), 0); assert_eq!(accumulator.block_execution_metrics.l2_to_l1_logs, 0); assert_eq!(accumulator.txs_encoding_size, bootloader_encoding_size); diff --git a/core/node/state_keeper/src/updates/mod.rs b/core/node/state_keeper/src/updates/mod.rs index 752963580e37..32e23b73229a 100644 --- a/core/node/state_keeper/src/updates/mod.rs +++ b/core/node/state_keeper/src/updates/mod.rs @@ -7,8 +7,8 @@ use zksync_multivm::{ utils::{get_batch_base_fee, StorageWritesDeduplicator}, }; use zksync_types::{ - block::BlockGasCount, commitment::PubdataParams, fee_model::BatchFeeInput, Address, - L1BatchNumber, L2BlockNumber, ProtocolVersionId, Transaction, + commitment::PubdataParams, fee_model::BatchFeeInput, Address, L1BatchNumber, L2BlockNumber, + ProtocolVersionId, Transaction, }; pub(crate) use self::{l1_batch_updates::L1BatchUpdates, l2_block_updates::L2BlockUpdates}; @@ -16,7 +16,6 @@ use super::{ io::{IoCursor, L2BlockParams}, metrics::{BATCH_TIP_METRICS, UPDATES_MANAGER_METRICS}, }; -use crate::types::ExecutionMetricsForCriteria; pub mod l1_batch_updates; pub mod l2_block_updates; @@ -117,7 +116,6 @@ impl UpdatesManager { tx: Transaction, tx_execution_result: VmExecutionResultAndLogs, compressed_bytecodes: Vec, - tx_l1_gas_this_tx: BlockGasCount, execution_metrics: VmExecutionMetrics, call_traces: Vec, ) { @@ -129,7 +127,6 @@ impl UpdatesManager { self.l2_block.extend_from_executed_transaction( tx, tx_execution_result, - tx_l1_gas_this_tx, execution_metrics, compressed_bytecodes, call_traces, @@ -145,7 +142,7 @@ impl UpdatesManager { ); let result = &finished_batch.block_tip_execution_result; - let batch_tip_metrics = ExecutionMetricsForCriteria::new(None, result); + let batch_tip_execution_metrics = result.get_execution_metrics(None); let before = self.storage_writes_deduplicator.metrics(); self.storage_writes_deduplicator @@ -153,11 +150,8 @@ impl UpdatesManager { let after = self.storage_writes_deduplicator.metrics(); BATCH_TIP_METRICS.observe_writes_metrics(&before, &after, self.protocol_version()); - self.l2_block.extend_from_fictive_transaction( - result.clone(), - batch_tip_metrics.l1_gas, - batch_tip_metrics.execution_metrics, - ); + self.l2_block + .extend_from_fictive_transaction(result.clone(), batch_tip_execution_metrics); self.l1_batch.finished = Some(finished_batch); latency.observe(); @@ -190,10 +184,6 @@ impl UpdatesManager { self.l1_batch.executed_transactions.len() + self.l2_block.executed_transactions.len() } - pub(crate) fn pending_l1_gas_count(&self) -> BlockGasCount { - self.l1_batch.l1_gas_count + self.l2_block.l1_gas_count - } - pub(crate) fn pending_execution_metrics(&self) -> VmExecutionMetrics { self.l1_batch.block_execution_metrics + self.l2_block.block_execution_metrics } @@ -225,10 +215,7 @@ pub struct L2BlockSealCommand { #[cfg(test)] mod tests { use super::*; - use crate::{ - tests::{create_execution_result, create_transaction, create_updates_manager}, - utils::new_block_gas_count, - }; + use crate::tests::{create_execution_result, create_transaction, create_updates_manager}; #[test] fn apply_l2_block() { @@ -242,7 +229,6 @@ mod tests { tx, create_execution_result([]), vec![], - new_block_gas_count(), VmExecutionMetrics::default(), vec![], ); diff --git a/core/node/state_keeper/src/utils.rs b/core/node/state_keeper/src/utils.rs index 320dd49583ed..5407711ae3c4 100644 --- a/core/node/state_keeper/src/utils.rs +++ b/core/node/state_keeper/src/utils.rs @@ -1,94 +1,5 @@ use std::time::{SystemTime, UNIX_EPOCH}; -use zksync_multivm::interface::{DeduplicatedWritesMetrics, VmExecutionMetrics}; -use zksync_types::{ - aggregated_operations::AggregatedActionType, block::BlockGasCount, ExecuteTransactionCommon, - ProtocolVersionId, Transaction, -}; - -// TODO(QIT-32): Remove constants(except `L1_OPERATION_EXECUTE_COST`) and logic that use them -const L1_BATCH_COMMIT_BASE_COST: u32 = 31_000; -const L1_BATCH_PROVE_BASE_COST: u32 = 7_000; -const L1_BATCH_EXECUTE_BASE_COST: u32 = 30_000; - -const EXECUTE_COMMIT_COST: u32 = 0; -const EXECUTE_EXECUTE_COST: u32 = 0; - -const L1_OPERATION_EXECUTE_COST: u32 = 12_500; - -const GAS_PER_BYTE: u32 = 18; - -pub(super) fn l1_batch_base_cost(op: AggregatedActionType) -> u32 { - match op { - AggregatedActionType::Commit => L1_BATCH_COMMIT_BASE_COST, - AggregatedActionType::PublishProofOnchain => L1_BATCH_PROVE_BASE_COST, - AggregatedActionType::Execute => L1_BATCH_EXECUTE_BASE_COST, - } -} - -fn base_tx_cost(tx: &Transaction, op: AggregatedActionType) -> u32 { - match op { - AggregatedActionType::Commit => EXECUTE_COMMIT_COST, - AggregatedActionType::PublishProofOnchain => 0, - AggregatedActionType::Execute => match tx.common_data { - ExecuteTransactionCommon::L1(_) => L1_OPERATION_EXECUTE_COST, - ExecuteTransactionCommon::L2(_) => EXECUTE_EXECUTE_COST, - ExecuteTransactionCommon::ProtocolUpgrade(_) => EXECUTE_EXECUTE_COST, - }, - } -} - -fn additional_pubdata_commit_cost(execution_metrics: &VmExecutionMetrics) -> u32 { - (execution_metrics.size() as u32) * GAS_PER_BYTE -} - -fn additional_writes_commit_cost( - writes_metrics: &DeduplicatedWritesMetrics, - protocol_version: ProtocolVersionId, -) -> u32 { - (writes_metrics.size(protocol_version) as u32) * GAS_PER_BYTE -} - -pub(super) fn new_block_gas_count() -> BlockGasCount { - BlockGasCount { - commit: l1_batch_base_cost(AggregatedActionType::Commit), - prove: l1_batch_base_cost(AggregatedActionType::PublishProofOnchain), - execute: l1_batch_base_cost(AggregatedActionType::Execute), - } -} - -pub(super) fn gas_count_from_tx_and_metrics( - tx: &Transaction, - execution_metrics: &VmExecutionMetrics, -) -> BlockGasCount { - let commit = base_tx_cost(tx, AggregatedActionType::Commit) - + additional_pubdata_commit_cost(execution_metrics); - BlockGasCount { - commit, - prove: base_tx_cost(tx, AggregatedActionType::PublishProofOnchain), - execute: base_tx_cost(tx, AggregatedActionType::Execute), - } -} - -pub(super) fn gas_count_from_metrics(execution_metrics: &VmExecutionMetrics) -> BlockGasCount { - BlockGasCount { - commit: additional_pubdata_commit_cost(execution_metrics), - prove: 0, - execute: 0, - } -} - -pub(super) fn gas_count_from_writes( - writes_metrics: &DeduplicatedWritesMetrics, - protocol_version: ProtocolVersionId, -) -> BlockGasCount { - BlockGasCount { - commit: additional_writes_commit_cost(writes_metrics, protocol_version), - prove: 0, - execute: 0, - } -} - // TODO (SMA-1206): use seconds instead of milliseconds. pub(super) fn millis_since_epoch() -> u128 { SystemTime::now()