Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pubdata type changes from sync-layer-stable #3425

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ use zksync_node_framework::{
service::{ZkStackService, ZkStackServiceBuilder},
};
use zksync_types::{
pubdata_da::PubdataSendingMode, settlement::SettlementMode, SHARED_BRIDGE_ETHER_TOKEN_ADDRESS,
commitment::{L1BatchCommitmentMode, PubdataType},
pubdata_da::PubdataSendingMode,
settlement::SettlementMode,
SHARED_BRIDGE_ETHER_TOKEN_ADDRESS,
};
use zksync_vlog::prometheus::PrometheusExporterConfig;

Expand Down Expand Up @@ -118,6 +121,24 @@ impl MainNodeBuilder {
self.node.runtime_handle()
}

pub fn get_pubdata_type(&self) -> PubdataType {
if self.genesis_config.l1_batch_commit_data_generator_mode == L1BatchCommitmentMode::Rollup
{
return PubdataType::Rollup;
}

let Some(da_client_config) = self.configs.da_client_config.clone() else {
return PubdataType::NoDA;
};

match da_client_config {
DAClientConfig::Avail(_) => PubdataType::Avail,
DAClientConfig::Celestia(_) => PubdataType::Celestia,
DAClientConfig::Eigen(_) => PubdataType::Eigen,
DAClientConfig::ObjectStore(_) => PubdataType::ObjectStore,
}
}

fn add_sigint_handler_layer(mut self) -> anyhow::Result<Self> {
self.node.add_layer(SigintHandlerLayer);
Ok(self)
Expand Down Expand Up @@ -252,7 +273,7 @@ impl MainNodeBuilder {
try_load_config!(self.configs.mempool_config),
try_load_config!(wallets.state_keeper),
self.contracts_config.l2_da_validator_addr,
self.genesis_config.l1_batch_commit_data_generator_mode,
self.get_pubdata_type(),
);
let db_config = try_load_config!(self.configs.db_config);
let experimental_vm_config = self
Expand Down
29 changes: 28 additions & 1 deletion core/lib/basic_types/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,35 @@ impl FromStr for L1BatchCommitmentMode {
}
}

#[derive(Default, Copy, Debug, Clone, PartialEq, Serialize, Deserialize, Display)]
pub enum PubdataType {
#[default]
Rollup,
NoDA,
Avail,
Celestia,
Eigen,
ObjectStore,
}

impl FromStr for PubdataType {
type Err = &'static str;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Rollup" => Ok(Self::Rollup),
"NoDA" => Ok(Self::NoDA),
"Avail" => Ok(Self::Avail),
"Celestia" => Ok(Self::Celestia),
"Eigen" => Ok(Self::Eigen),
"ObjectStore" => Ok(Self::ObjectStore),
_ => Err("Incorrect DA client type; expected one of `Rollup`, `NoDA`, `Avail`, `Celestia`, `Eigen`, `ObjectStore`"),
}
}
}

#[derive(Default, Copy, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PubdataParams {
pub l2_da_validator_address: Address,
pub pubdata_type: L1BatchCommitmentMode,
pub pubdata_type: PubdataType,
}
29 changes: 12 additions & 17 deletions core/lib/dal/src/consensus/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use zksync_consensus_roles::{attester, node};
use zksync_protobuf::{read_optional_repr, read_required, required, ProtoFmt, ProtoRepr};
use zksync_types::{
abi,
commitment::{L1BatchCommitmentMode, PubdataParams},
commitment::{PubdataParams, PubdataType},
ethabi,
fee::Fee,
h256_to_u256,
Expand Down Expand Up @@ -112,8 +112,8 @@ impl ProtoRepr for proto::PubdataParams {
l2_da_validator_address: required(&self.l2_da_validator_address)
.and_then(|a| parse_h160(a))
.context("l2_da_validator_address")?,
pubdata_type: required(&self.pubdata_type)
.and_then(|x| Ok(proto::L1BatchCommitDataGeneratorMode::try_from(*x)?))
pubdata_type: required(&self.pubdata_info)
.and_then(|x| Ok(proto::PubdataType::try_from(*x)?))
.context("pubdata_type")?
.parse(),
})
Expand All @@ -122,9 +122,7 @@ impl ProtoRepr for proto::PubdataParams {
fn build(this: &Self::Type) -> Self {
Self {
l2_da_validator_address: Some(this.l2_da_validator_address.as_bytes().into()),
pubdata_type: Some(
proto::L1BatchCommitDataGeneratorMode::new(&this.pubdata_type) as i32,
),
pubdata_info: Some(this.pubdata_type as i32),
}
}
}
Expand Down Expand Up @@ -572,18 +570,15 @@ impl ProtoRepr for proto::AttesterCommittee {
}
}

impl proto::L1BatchCommitDataGeneratorMode {
pub(crate) fn new(n: &L1BatchCommitmentMode) -> Self {
match n {
L1BatchCommitmentMode::Rollup => Self::Rollup,
L1BatchCommitmentMode::Validium => Self::Validium,
}
}

pub(crate) fn parse(&self) -> L1BatchCommitmentMode {
impl proto::PubdataType {
pub(crate) fn parse(&self) -> PubdataType {
match self {
Self::Rollup => L1BatchCommitmentMode::Rollup,
Self::Validium => L1BatchCommitmentMode::Validium,
Self::Rollup => PubdataType::Rollup,
Self::NoDa => PubdataType::NoDA,
Self::Avail => PubdataType::Avail,
Self::Celestia => PubdataType::Celestia,
Self::Eigen => PubdataType::Eigen,
Self::ObjectStore => PubdataType::ObjectStore,
}
}
}
11 changes: 8 additions & 3 deletions core/lib/dal/src/consensus/proto/mod.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ message Payload {

message PubdataParams {
optional bytes l2_da_validator_address = 1; // required; H160
optional L1BatchCommitDataGeneratorMode pubdata_type = 2; // required
optional PubdataType pubdata_info = 3; // required
reserved 2; reserved "pubdata_type";
}

message L1Transaction {
Expand Down Expand Up @@ -149,7 +150,11 @@ message AttestationStatus {
optional uint64 next_batch_to_attest = 2; // required
}

enum L1BatchCommitDataGeneratorMode {
enum PubdataType {
Rollup = 0;
Validium = 1;
NoDA = 1;
Avail = 2;
Celestia = 3;
Eigen = 4;
ObjectStore = 5;
}
10 changes: 7 additions & 3 deletions core/lib/dal/src/consensus/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use zksync_protobuf::{
};
use zksync_test_contracts::Account;
use zksync_types::{
commitment::{L1BatchCommitmentMode, PubdataParams},
commitment::{PubdataParams, PubdataType},
web3::Bytes,
Execute, ExecuteTransactionCommon, L1BatchNumber, ProtocolVersionId, Transaction,
};
Expand Down Expand Up @@ -58,8 +58,12 @@ fn payload(rng: &mut impl Rng, protocol_version: ProtocolVersionId) -> Payload {
} else {
PubdataParams {
pubdata_type: match rng.gen_range(0..2) {
0 => L1BatchCommitmentMode::Rollup,
_ => L1BatchCommitmentMode::Validium,
0 => PubdataType::Rollup,
1 => PubdataType::NoDA,
2 => PubdataType::Avail,
3 => PubdataType::Celestia,
4 => PubdataType::Eigen,
_ => PubdataType::ObjectStore,
},
l2_da_validator_address: rng.gen(),
}
Expand Down
40 changes: 23 additions & 17 deletions core/lib/dal/src/factory_deps_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,36 @@ impl FactoryDepsDal<'_, '_> {
.map(|row| row.bytecode))
}

pub async fn get_base_system_contracts(
pub async fn get_base_system_contracts_from_factory_deps(
&mut self,
bootloader_hash: H256,
default_aa_hash: H256,
evm_emulator_hash: Option<H256>,
) -> anyhow::Result<BaseSystemContracts> {
) -> anyhow::Result<Option<BaseSystemContracts>> {
let bootloader_bytecode = self
.get_sealed_factory_dep(bootloader_hash)
.await
.context("failed loading bootloader code")?
.with_context(|| format!("bootloader code with hash {bootloader_hash:?} should be present in the database"))?;
let bootloader_code = SystemContractCode {
code: bootloader_bytecode,
hash: bootloader_hash,
};
.context("failed loading bootloader code")?;

let default_aa_bytecode = self
.get_sealed_factory_dep(default_aa_hash)
.await
.context("failed loading default account code")?
.with_context(|| format!("default account code with hash {default_aa_hash:?} should be present in the database"))?;
.context("failed loading default account code")?;

let default_aa_code = SystemContractCode {
code: default_aa_bytecode,
hash: default_aa_hash,
let (Some(bootloader_bytecode), Some(default_aa_bytecode)) =
(bootloader_bytecode, default_aa_bytecode)
else {
return Ok(None);
};

let evm_emulator_code = if let Some(evm_emulator_hash) = evm_emulator_hash {
let evm_emulator_bytecode = self
.get_sealed_factory_dep(evm_emulator_hash)
.await
.context("failed loading EVM emulator code")?
.with_context(|| format!("EVM emulator code with hash {evm_emulator_hash:?} should be present in the database"))?;
.context("failed loading EVM emulator code")?;
let Some(evm_emulator_bytecode) = evm_emulator_bytecode else {
return Ok(None);
};

Some(SystemContractCode {
code: evm_emulator_bytecode,
Expand All @@ -131,11 +128,20 @@ impl FactoryDepsDal<'_, '_> {
None
};

Ok(BaseSystemContracts {
let bootloader_code = SystemContractCode {
code: bootloader_bytecode,
hash: bootloader_hash,
};

let default_aa_code = SystemContractCode {
code: default_aa_bytecode,
hash: default_aa_hash,
};
Ok(Some(BaseSystemContracts {
bootloader: bootloader_code,
default_aa: default_aa_code,
evm_emulator: evm_emulator_code,
})
}))
}

/// Returns bytecodes for factory deps with the specified `hashes`.
Expand Down
4 changes: 2 additions & 2 deletions core/lib/dal/src/models/storage_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use zksync_contracts::BaseSystemContractsHashes;
use zksync_types::{
api,
block::{L1BatchHeader, L2BlockHeader, UnsealedL1BatchHeader},
commitment::{L1BatchCommitmentMode, L1BatchMetaParameters, L1BatchMetadata, PubdataParams},
commitment::{L1BatchMetaParameters, L1BatchMetadata, PubdataParams, PubdataType},
fee_model::{BatchFeeInput, L1PeggedBatchFeeModelInput, PubdataIndependentBatchFeeModelInput},
l2_to_l1_log::{L2ToL1Log, SystemL2ToL1Log, UserL2ToL1Log},
Address, Bloom, L1BatchNumber, L2BlockNumber, ProtocolVersionId, SLChainId, H256,
Expand Down Expand Up @@ -556,7 +556,7 @@ impl From<StorageL2BlockHeader> for L2BlockHeader {
.unwrap_or_default(),
pubdata_params: PubdataParams {
l2_da_validator_address: Address::from_slice(&row.l2_da_validator_address),
pubdata_type: L1BatchCommitmentMode::from_str(&row.pubdata_type).unwrap(),
pubdata_type: PubdataType::from_str(&row.pubdata_type).unwrap(),
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/lib/dal/src/models/storage_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use zksync_contracts::BaseSystemContractsHashes;
use zksync_db_connection::error::SqlxContext;
use zksync_types::{
api::en,
commitment::{L1BatchCommitmentMode, PubdataParams},
commitment::{PubdataParams, PubdataType},
parse_h160, parse_h256, parse_h256_opt, Address, L1BatchNumber, L2BlockNumber,
ProtocolVersionId, Transaction, H256,
};
Expand Down Expand Up @@ -97,7 +97,7 @@ impl TryFrom<StorageSyncBlock> for SyncBlock {
hash: parse_h256(&block.hash).decode_column("hash")?,
protocol_version: parse_protocol_version(block.protocol_version)?,
pubdata_params: PubdataParams {
pubdata_type: L1BatchCommitmentMode::from_str(&block.pubdata_type)
pubdata_type: PubdataType::from_str(&block.pubdata_type)
.decode_column("Invalid pubdata type")?,
l2_da_validator_address: parse_h160(&block.l2_da_validator_address)
.decode_column("l2_da_validator_address")?,
Expand Down
51 changes: 5 additions & 46 deletions core/lib/dal/src/protocol_versions_dal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::convert::TryInto;

use anyhow::Context as _;
use zksync_contracts::{BaseSystemContracts, BaseSystemContractsHashes};
use zksync_contracts::BaseSystemContractsHashes;
use zksync_db_connection::{
connection::Connection,
error::DalResult,
Expand Down Expand Up @@ -200,12 +200,10 @@ impl ProtocolVersionsDal<'_, '_> {
ProtocolVersionId::try_from(row.id as u16).map_err(|err| sqlx::Error::Decode(err.into()))
}

/// Returns base system contracts' hashes. Prefer `load_base_system_contracts_by_version_id` if
/// you also want to load the contracts themselves AND expect the contracts to be in the DB
/// already.
/// Returns base system contracts' hashes.
pub async fn get_base_system_contract_hashes_by_version_id(
&mut self,
version_id: u16,
version_id: ProtocolVersionId,
) -> anyhow::Result<Option<BaseSystemContractsHashes>> {
let row = sqlx::query!(
r#"
Expand All @@ -218,10 +216,10 @@ impl ProtocolVersionsDal<'_, '_> {
WHERE
id = $1
"#,
i32::from(version_id)
i32::from(version_id as u16)
)
.instrument("get_base_system_contract_hashes_by_version_id")
.with_arg("version_id", &version_id)
.with_arg("version_id", &(version_id as u16))
.fetch_optional(self.storage)
.await
.context("cannot fetch system contract hashes")?;
Expand All @@ -237,45 +235,6 @@ impl ProtocolVersionsDal<'_, '_> {
})
}

pub async fn load_base_system_contracts_by_version_id(
&mut self,
version_id: u16,
) -> anyhow::Result<Option<BaseSystemContracts>> {
let row = sqlx::query!(
r#"
SELECT
bootloader_code_hash,
default_account_code_hash,
evm_emulator_code_hash
FROM
protocol_versions
WHERE
id = $1
"#,
i32::from(version_id)
)
.instrument("load_base_system_contracts_by_version_id")
.with_arg("version_id", &version_id)
.fetch_optional(self.storage)
.await
.context("cannot fetch system contract hashes")?;

Ok(if let Some(row) = row {
let contracts = self
.storage
.factory_deps_dal()
.get_base_system_contracts(
H256::from_slice(&row.bootloader_code_hash),
H256::from_slice(&row.default_account_code_hash),
row.evm_emulator_code_hash.as_deref().map(H256::from_slice),
)
.await?;
Some(contracts)
} else {
None
})
}

pub async fn get_protocol_version_with_latest_patch(
&mut self,
version_id: ProtocolVersionId,
Expand Down
1 change: 0 additions & 1 deletion core/lib/env_config/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ impl FromEnv for GenesisConfig {
bootloader_hash: state_keeper.bootloader_hash,
default_aa_hash: state_keeper.default_aa_hash,
evm_emulator_hash: state_keeper.evm_emulator_hash,
// TODO(EVM-676): for now, the settlement layer is always the same as the L1 network
l1_chain_id: L1ChainId(network_config.network.chain_id().0),
l2_chain_id: network_config.zksync_network_id,
snark_wrapper_vk_hash: contracts_config.snark_wrapper_vk_hash,
Expand Down
Loading
Loading