Skip to content

Commit

Permalink
remove SK gas criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Nov 22, 2024
1 parent 920eba1 commit bc81c00
Show file tree
Hide file tree
Showing 24 changed files with 90 additions and 671 deletions.

This file was deleted.

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

This file was deleted.

54 changes: 17 additions & 37 deletions core/lib/dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(),
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -3093,33 +3079,27 @@ 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)),
)
.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)),
)
.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();

Expand Down
47 changes: 0 additions & 47 deletions core/lib/types/src/block.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/node/api_server/src/tx_sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions core/node/genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 4 additions & 6 deletions core/node/state_keeper/src/executor/mod.rs
Original file line number Diff line number Diff line change
@@ -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<VmExecutionResultAndLogs>,
tx_metrics: Box<ExecutionMetricsForCriteria>,
tx_metrics: Box<VmExecutionMetrics>,
compressed_bytecodes: Vec<CompressedBytecodeInfo>,
call_tracer_result: Vec<Call>,
gas_remaining: u32,
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions core/node/state_keeper/src/io/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -508,7 +508,6 @@ mod tests {
tx,
tx_result,
vec![],
BlockGasCount::default(),
VmExecutionMetrics::default(),
vec![],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 0 additions & 1 deletion core/node/state_keeper/src/io/seal_logic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit bc81c00

Please sign in to comment.