Skip to content

Commit

Permalink
Merge branch 'main' into miniblock_max_payload_size
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/lib/protobuf_config/src/proto/chain.proto
  • Loading branch information
moshababo committed Apr 9, 2024
2 parents b28a2a6 + a805907 commit a22ce74
Show file tree
Hide file tree
Showing 22 changed files with 559 additions and 109 deletions.
20 changes: 16 additions & 4 deletions core/bin/block_reverter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use zksync_core::block_reverter::{
};
use zksync_dal::{ConnectionPool, Core};
use zksync_env_config::FromEnv;
use zksync_types::{L1BatchNumber, U256};
use zksync_types::{Address, L1BatchNumber, U256};

#[derive(Debug, Parser)]
#[command(author = "Matter Labs", version, about = "Block revert utility", long_about = None)]
Expand All @@ -26,6 +26,9 @@ enum Command {
/// Displays the values as a JSON object, so that they are machine-readable.
#[arg(long)]
json: bool,
/// Operator address.
#[arg(long = "operator-address")]
operator_address: Address,
},
/// Sends revert transaction to L1.
#[command(name = "send-eth-transaction")]
Expand Down Expand Up @@ -70,6 +73,7 @@ enum Command {

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let command = Cli::parse().command;
let observability_config =
ObservabilityConfig::from_env().context("ObservabilityConfig::from_env()")?;
let log_format: vlog::LogFormat = observability_config
Expand All @@ -96,7 +100,15 @@ async fn main() -> anyhow::Result<()> {
);
let contracts = ContractsConfig::from_env().context("ContractsConfig::from_env()")?;
let postgres_config = PostgresConfig::from_env().context("PostgresConfig::from_env()")?;
let config = BlockReverterEthConfig::new(eth_sender, contracts);
let operator_address = if let Command::Display {
operator_address, ..
} = &command
{
Some(operator_address)
} else {
None
};
let config = BlockReverterEthConfig::new(eth_sender, contracts, operator_address.copied());

let connection_pool = ConnectionPool::<Core>::builder(
postgres_config.master_url()?,
Expand All @@ -114,8 +126,8 @@ async fn main() -> anyhow::Result<()> {
L1ExecutedBatchesRevert::Disallowed,
);

match Cli::parse().command {
Command::Display { json } => {
match command {
Command::Display { json, .. } => {
let suggested_values = block_reverter.suggested_values().await;
if json {
println!("{}", serde_json::to_string(&suggested_values).unwrap());
Expand Down
5 changes: 0 additions & 5 deletions core/lib/config/src/configs/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ pub struct StateKeeperConfig {
pub validation_computational_gas_limit: u32,
pub save_call_traces: bool,

pub virtual_blocks_interval: u32,
pub virtual_blocks_per_miniblock: u32,

/// Number of keys that is processed by enum_index migration in State Keeper each L1 batch.
pub enum_index_migration_chunk_size: Option<usize>,

Expand Down Expand Up @@ -204,8 +201,6 @@ impl StateKeeperConfig {
fee_model_version: FeeModelVersion::V2,
validation_computational_gas_limit: 300000,
save_call_traces: true,
virtual_blocks_interval: 1,
virtual_blocks_per_miniblock: 1,
enum_index_migration_chunk_size: None,
max_circuits_per_batch: 24100,
bootloader_hash: None,
Expand Down
2 changes: 0 additions & 2 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ impl Distribution<configs::chain::StateKeeperConfig> for EncodeDist {
fee_model_version: self.sample(rng),
validation_computational_gas_limit: self.sample(rng),
save_call_traces: self.sample(rng),
virtual_blocks_interval: self.sample(rng),
virtual_blocks_per_miniblock: self.sample(rng),
enum_index_migration_chunk_size: self.sample(rng),
max_circuits_per_batch: self.sample(rng),
// These values are not involved into files serialization skip them
Expand Down
4 changes: 0 additions & 4 deletions core/lib/env_config/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ mod tests {
fee_model_version: FeeModelVersion::V2,
validation_computational_gas_limit: 10_000_000,
save_call_traces: false,
virtual_blocks_interval: 1,
virtual_blocks_per_miniblock: 1,
enum_index_migration_chunk_size: Some(2_000),
bootloader_hash: Some(hash(
"0x010007ede999d096c84553fb514d3d6ca76fbf39789dda76bfeda9f3ae06236e",
Expand Down Expand Up @@ -137,8 +135,6 @@ mod tests {
CHAIN_STATE_KEEPER_VALIDATION_COMPUTATIONAL_GAS_LIMIT="10000000"
CHAIN_STATE_KEEPER_SAVE_CALL_TRACES="false"
CHAIN_STATE_KEEPER_ENUM_INDEX_MIGRATION_CHUNK_SIZE="2000"
CHAIN_STATE_KEEPER_VIRTUAL_BLOCKS_PER_MINIBLOCK="1"
CHAIN_STATE_KEEPER_VIRTUAL_BLOCKS_INTERVAL="1"
CHAIN_STATE_KEEPER_BOOTLOADER_HASH=0x010007ede999d096c84553fb514d3d6ca76fbf39789dda76bfeda9f3ae06236e
CHAIN_STATE_KEEPER_DEFAULT_AA_HASH=0x0100055b041eb28aff6e3a6e0f37c31fd053fc9ef142683b05e5f0aee6934066
CHAIN_STATE_KEEPER_L1_BATCH_COMMIT_DATA_GENERATOR_MODE="{l1_batch_commit_data_generator_mode}"
Expand Down
6 changes: 0 additions & 6 deletions core/lib/protobuf_config/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ impl ProtoRepr for proto::StateKeeper {
validation_computational_gas_limit: *required(&self.validation_computational_gas_limit)
.context("validation_computational_gas_limit")?,
save_call_traces: *required(&self.save_call_traces).context("save_call_traces")?,
virtual_blocks_interval: *required(&self.virtual_blocks_interval)
.context("virtual_blocks_interval")?,
virtual_blocks_per_miniblock: *required(&self.virtual_blocks_per_miniblock)
.context("virtual_blocks_per_miniblock")?,
enum_index_migration_chunk_size: self
.enum_index_migration_chunk_size
.map(|x| x.try_into())
Expand Down Expand Up @@ -123,8 +119,6 @@ impl ProtoRepr for proto::StateKeeper {
fee_model_version: Some(proto::FeeModelVersion::new(&this.fee_model_version).into()),
validation_computational_gas_limit: Some(this.validation_computational_gas_limit),
save_call_traces: Some(this.save_call_traces),
virtual_blocks_interval: Some(this.virtual_blocks_interval),
virtual_blocks_per_miniblock: Some(this.virtual_blocks_per_miniblock),
enum_index_migration_chunk_size: this
.enum_index_migration_chunk_size
.as_ref()
Expand Down
4 changes: 2 additions & 2 deletions core/lib/protobuf_config/src/proto/chain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ message StateKeeper {
optional FeeModelVersion fee_model_version = 20; // required
optional uint32 validation_computational_gas_limit = 21; // required; wei?
optional bool save_call_traces = 22; // required
optional uint32 virtual_blocks_interval = 23; // required
optional uint32 virtual_blocks_per_miniblock = 24; // required
optional uint64 enum_index_migration_chunk_size = 26; // optional
optional uint64 max_circuits_per_batch = 27; // required
optional uint64 miniblock_max_payload_size = 28; // required
reserved 23; reserved "virtual_blocks_interval";
reserved 24; reserved "virtual_blocks_per_miniblock";
}

message OperationsManager {
Expand Down
35 changes: 21 additions & 14 deletions core/lib/zksync_core/src/block_reverter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use zksync_types::{
types::{BlockId, BlockNumber},
Web3,
},
L1BatchNumber, PackedEthSignature, H160, H256, U256,
Address, L1BatchNumber, H160, H256, U256,
};

bitflags! {
Expand All @@ -45,29 +45,27 @@ pub enum L1ExecutedBatchesRevert {
#[derive(Debug)]
pub struct BlockReverterEthConfig {
eth_client_url: String,
reverter_private_key: H256,
reverter_address: H160,
reverter_private_key: Option<H256>,
reverter_address: Option<Address>,
diamond_proxy_addr: H160,
validator_timelock_addr: H160,
default_priority_fee_per_gas: u64,
}

impl BlockReverterEthConfig {
pub fn new(eth_config: ETHConfig, contract: ContractsConfig) -> Self {
pub fn new(
eth_config: ETHConfig,
contract: ContractsConfig,
reverter_address: Option<Address>,
) -> Self {
#[allow(deprecated)]
// `BlockReverter` doesn't support non env configs yet
let pk = eth_config
.sender
.expect("eth_sender_config")
.private_key()
.expect("Private key is required for block reversion");
let operator_address = PackedEthSignature::address_from_private_key(&pk)
.expect("Failed to get address from private key");
let pk = eth_config.sender.expect("eth_sender_config").private_key();

Self {
eth_client_url: eth_config.web3_url,
reverter_private_key: pk,
reverter_address: operator_address,
reverter_address,
diamond_proxy_addr: contract.diamond_proxy_addr,
validator_timelock_addr: contract.validator_timelock_addr,
default_priority_fee_per_gas: eth_config
Expand Down Expand Up @@ -342,7 +340,11 @@ impl BlockReverter {

let web3 = Web3::new(Http::new(&eth_config.eth_client_url).unwrap());
let contract = zksync_contract();
let signer = PrivateKeySigner::new(eth_config.reverter_private_key);
let signer = PrivateKeySigner::new(
eth_config
.reverter_private_key
.expect("Private key is required to send revert transaction"),
);
let chain_id = web3.eth().chain_id().await.unwrap().as_u64();

let revert_function = contract
Expand Down Expand Up @@ -456,7 +458,12 @@ impl BlockReverter {
let web3 = Web3::new(Http::new(&eth_config.eth_client_url).unwrap());
let nonce = web3
.eth()
.transaction_count(eth_config.reverter_address, Some(BlockNumber::Pending))
.transaction_count(
eth_config
.reverter_address
.expect("Need to provide operator address to suggest revertion values"),
Some(BlockNumber::Pending),
)
.await
.unwrap()
.as_u64();
Expand Down
38 changes: 4 additions & 34 deletions core/lib/zksync_core/src/state_keeper/io/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ pub struct MempoolIO {
// Used to keep track of gas prices to set accepted price per pubdata byte in blocks.
batch_fee_input_provider: Arc<dyn BatchFeeModelInputProvider>,
chain_id: L2ChainId,

virtual_blocks_interval: u32,
virtual_blocks_per_miniblock: u32,
}

impl IoSealCriteria for MempoolIO {
Expand Down Expand Up @@ -196,7 +193,8 @@ impl StateKeeperIO for MempoolIO {
fee_input: self.filter.fee_input,
first_miniblock: MiniblockParams {
timestamp,
virtual_blocks: self.get_virtual_blocks_count(true, cursor.next_miniblock),
// This value is effectively ignored by the protocol.
virtual_blocks: 1,
},
}));
}
Expand All @@ -219,10 +217,10 @@ impl StateKeeperIO for MempoolIO {
return Ok(None);
};

let virtual_blocks = self.get_virtual_blocks_count(false, cursor.next_miniblock);
Ok(Some(MiniblockParams {
timestamp,
virtual_blocks,
// This value is effectively ignored by the protocol.
virtual_blocks: 1,
}))
}

Expand Down Expand Up @@ -409,15 +407,6 @@ impl MempoolIO {
delay_interval: Duration,
chain_id: L2ChainId,
) -> anyhow::Result<Self> {
anyhow::ensure!(
config.virtual_blocks_interval > 0,
"Virtual blocks interval must be positive"
);
anyhow::ensure!(
config.virtual_blocks_per_miniblock > 0,
"Virtual blocks per miniblock must be positive"
);

let mut storage = pool.connection_tagged("state_keeper").await?;
let l1_batch_params_provider = L1BatchParamsProvider::new(&mut storage)
.await
Expand All @@ -439,27 +428,8 @@ impl MempoolIO {
delay_interval,
batch_fee_input_provider,
chain_id,
virtual_blocks_interval: config.virtual_blocks_interval,
virtual_blocks_per_miniblock: config.virtual_blocks_per_miniblock,
})
}

/// "virtual_blocks_per_miniblock" will be created either if the miniblock_number % virtual_blocks_interval == 0 or
/// the miniblock is the first one in the batch.
/// For instance:
/// 1) If we want to have virtual block speed the same as the batch speed, virtual_block_interval = 10^9 and virtual_blocks_per_miniblock = 1
/// 2) If we want to have roughly 1 virtual block per 2 miniblocks, we need to have virtual_block_interval = 2, and virtual_blocks_per_miniblock = 1
/// 3) If we want to have 4 virtual blocks per miniblock, we need to have virtual_block_interval = 1, and virtual_blocks_per_miniblock = 4.
fn get_virtual_blocks_count(
&self,
first_in_batch: bool,
miniblock_number: MiniblockNumber,
) -> u32 {
if first_in_batch || miniblock_number.0 % self.virtual_blocks_interval == 0 {
return self.virtual_blocks_per_miniblock;
}
0
}
}

/// Getters required for testing the MempoolIO.
Expand Down
22 changes: 5 additions & 17 deletions core/lib/zksync_core/src/state_keeper/io/seal_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use multivm::utils::{get_max_batch_gas_limit, get_max_gas_per_pubdata_byte};
use zksync_dal::{Connection, Core, CoreDal};
use zksync_shared_metrics::{BlockStage, MiniblockStage, APP_METRICS};
use zksync_types::{
block::{unpack_block_info, L1BatchHeader, MiniblockHeader},
block::{L1BatchHeader, MiniblockHeader},
event::{extract_added_tokens, extract_long_l2_to_l1_messages},
helpers::unix_timestamp_ms,
l1::L1Tx,
Expand All @@ -23,10 +23,9 @@ use zksync_types::{
},
zk_evm_types::LogQuery,
AccountTreeId, Address, ExecuteTransactionCommon, L1BlockNumber, ProtocolVersionId, StorageKey,
StorageLog, StorageLogQuery, Transaction, VmEvent, CURRENT_VIRTUAL_BLOCK_INFO_POSITION, H256,
SYSTEM_CONTEXT_ADDRESS,
StorageLog, StorageLogQuery, Transaction, VmEvent, H256,
};
use zksync_utils::{h256_to_u256, u256_to_h256};
use zksync_utils::u256_to_h256;

use crate::state_keeper::{
metrics::{
Expand Down Expand Up @@ -460,16 +459,6 @@ impl MiniblockSealCommand {
progress.observe(user_l2_to_l1_log_count);

let progress = MINIBLOCK_METRICS.start(MiniblockSealStage::CommitMiniblock, is_fictive);
let current_l2_virtual_block_info = transaction
.storage_web3_dal()
.get_value(&StorageKey::new(
AccountTreeId::new(SYSTEM_CONTEXT_ADDRESS),
CURRENT_VIRTUAL_BLOCK_INFO_POSITION,
))
.await
.context("failed getting virtual block info from VM state")?;
let (current_l2_virtual_block_number, _) =
unpack_block_info(h256_to_u256(current_l2_virtual_block_info));

transaction.commit().await?;
progress.observe(None);
Expand All @@ -478,7 +467,7 @@ impl MiniblockSealCommand {
self.report_transaction_metrics();
progress.observe(Some(self.miniblock.executed_transactions.len()));

self.report_miniblock_metrics(started_at, current_l2_virtual_block_number);
self.report_miniblock_metrics(started_at);
Ok(())
}

Expand Down Expand Up @@ -647,7 +636,7 @@ impl MiniblockSealCommand {
}
}

fn report_miniblock_metrics(&self, started_at: Instant, latest_virtual_block_number: u64) {
fn report_miniblock_metrics(&self, started_at: Instant) {
let miniblock_number = self.miniblock.number;

MINIBLOCK_METRICS
Expand All @@ -660,7 +649,6 @@ impl MiniblockSealCommand {
let stage = &MiniblockStage::Sealed;
APP_METRICS.miniblock_latency[stage].observe(Duration::from_secs_f64(miniblock_latency));
APP_METRICS.miniblock_number[stage].set(miniblock_number.0.into());
APP_METRICS.miniblock_virtual_block_number[stage].set(latest_virtual_block_number);

tracing::debug!(
"Sealed miniblock {miniblock_number} in {:?}",
Expand Down
2 changes: 0 additions & 2 deletions core/lib/zksync_core/src/state_keeper/io/tests/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ impl Tester {
let mempool = MempoolGuard::new(PriorityOpId(0), 100);
let config = StateKeeperConfig {
minimal_l2_gas_price: self.minimal_l2_gas_price(),
virtual_blocks_interval: 1,
virtual_blocks_per_miniblock: 1,
validation_computational_gas_limit: BATCH_COMPUTATIONAL_GAS_LIMIT,
..StateKeeperConfig::for_tests()
};
Expand Down
2 changes: 0 additions & 2 deletions core/node/shared_metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ pub struct AppMetrics {
pub block_latency: Family<BlockStage, Histogram<Duration>>,
#[metrics(buckets = Buckets::LATENCIES)]
pub miniblock_latency: Family<MiniblockStage, Histogram<Duration>>,
/// Latest virtual block number produced by the state keeper.
pub miniblock_virtual_block_number: Family<MiniblockStage, Gauge<u64>>,
pub processed_txs: Family<TxStage, Counter>,
pub processed_l1_txs: Family<TxStage, Counter>,

Expand Down
7 changes: 6 additions & 1 deletion core/tests/revert-test/tests/revert-and-restart-en.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,12 @@ describe('Block reverting test', function () {
await mainNode.terminate();

console.log('Ask block_reverter to suggest to which L1 batch we should revert');
const values_json = runBlockReverter(['print-suggested-values', '--json']);
const values_json = runBlockReverter([
'print-suggested-values',
'--json',
'--operator-address',
'0xde03a0B5963f75f1C8485B355fF6D30f3093BDE7'
]);
console.log(`values = ${values_json}`);
const values = parseSuggestedValues(values_json);
assert(lastExecuted.eq(values.lastExecutedL1BatchNumber));
Expand Down
Loading

0 comments on commit a22ce74

Please sign in to comment.