Skip to content

Commit

Permalink
server compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Dec 18, 2024
1 parent 9892cdf commit f6f9df3
Show file tree
Hide file tree
Showing 71 changed files with 1,032 additions and 346 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

24 changes: 2 additions & 22 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ use zksync_node_framework::{
service::{ZkStackService, ZkStackServiceBuilder},
};
use zksync_types::{
commitment::{L1BatchCommitmentMode, PubdataType},
pubdata_da::PubdataSendingMode,
settlement::SettlementMode,
commitment::L1BatchCommitmentMode, pubdata_da::PubdataSendingMode, settlement::SettlementMode,
SHARED_BRIDGE_ETHER_TOKEN_ADDRESS,
};
use zksync_vlog::prometheus::PrometheusExporterConfig;
Expand Down Expand Up @@ -121,24 +119,6 @@ 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 @@ -273,7 +253,7 @@ impl MainNodeBuilder {
try_load_config!(self.configs.mempool_config),
try_load_config!(wallets.state_keeper),
self.contracts_config.l2_da_validator_addr,
self.get_pubdata_type(),
self.genesis_config.l1_batch_commit_data_generator_mode,
);
let db_config = try_load_config!(self.configs.db_config);
let experimental_vm_config = self
Expand Down
29 changes: 1 addition & 28 deletions core/lib/basic_types/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,8 @@ 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: PubdataType,
pub pubdata_type: L1BatchCommitmentMode,
}
8 changes: 0 additions & 8 deletions core/lib/config/src/configs/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub struct GenesisConfig {
pub default_aa_hash: Option<H256>,
pub evm_emulator_hash: Option<H256>,
pub l1_chain_id: L1ChainId,
pub sl_chain_id: Option<SLChainId>,
pub l2_chain_id: L2ChainId,
// Note: `serde` isn't used with protobuf config. The same alias is implemented in
// `zksync_protobuf_config` manually.
Expand All @@ -35,12 +34,6 @@ pub struct GenesisConfig {
pub custom_genesis_state_path: Option<String>,
}

impl GenesisConfig {
pub fn settlement_layer_id(&self) -> SLChainId {
self.sl_chain_id.unwrap_or(self.l1_chain_id.into())
}
}

impl GenesisConfig {
pub fn for_tests() -> Self {
GenesisConfig {
Expand All @@ -53,7 +46,6 @@ impl GenesisConfig {
default_aa_hash: Default::default(),
evm_emulator_hash: Default::default(),
l1_chain_id: L1ChainId(9),
sl_chain_id: None,
protocol_version: Some(ProtocolSemanticVersion {
minor: ProtocolVersionId::latest(),
patch: 0.into(),
Expand Down

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

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

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

24 changes: 24 additions & 0 deletions core/lib/dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,30 @@ impl BlocksDal<'_, '_> {
.context("map_l1_batches()")
}

pub async fn get_batch_first_priority_op_id(
&mut self,
batch_number: L1BatchNumber,
) -> DalResult<Option<usize>> {
let row = sqlx::query!(
r#"
SELECT
MIN(priority_op_id) AS "id?"
FROM
transactions
WHERE
l1_batch_number = $1
AND is_priority = TRUE
"#,
i64::from(batch_number.0),
)
.instrument("get_batch_first_priority_op_id")
.with_arg("batch_number", &batch_number)
.fetch_one(self.storage)
.await?;

Ok(row.id.map(|id| id as usize))
}

async fn raw_ready_for_execute_l1_batches(
&mut self,
max_l1_batch_timestamp_seconds: f64,
Expand Down
21 changes: 21 additions & 0 deletions core/lib/dal/src/eth_sender_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,27 @@ impl EthSenderDal<'_, '_> {
Ok(row.and_then(|r| r.chain_id).map(|id| SLChainId(id as u64)))
}

pub async fn get_batch_execute_chain_id(
&mut self,
batch_number: L1BatchNumber,
) -> DalResult<Option<SLChainId>> {
let row = sqlx::query!(
r#"
SELECT eth_txs.chain_id
FROM l1_batches
JOIN eth_txs ON eth_txs.id = l1_batches.eth_execute_tx_id
WHERE
number = $1
"#,
i64::from(batch_number.0),
)
.instrument("get_batch_execute_chain_id")
.with_arg("batch_number", &batch_number)
.fetch_optional(self.storage)
.await?;
Ok(row.and_then(|r| r.chain_id).map(|id| SLChainId(id as u64)))
}

pub async fn get_confirmed_tx_hash_by_eth_tx_id(
&mut self,
eth_tx_id: u32,
Expand Down
28 changes: 27 additions & 1 deletion core/lib/dal/src/transactions_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,37 @@ impl TransactionsDal<'_, '_> {
)
.instrument("insert_transaction_l1")
.with_arg("tx_hash", &tx_hash)
.fetch_optional(self.storage)
.execute(self.storage)
.await?;

Ok(())
}

pub async fn get_l1_transactions_hashes(&mut self, start_id: usize) -> DalResult<Vec<H256>> {
let hashes = sqlx::query!(
r#"
SELECT
hash
FROM
transactions
WHERE
priority_op_id >= $1
AND is_priority = TRUE
ORDER BY
priority_op_id
"#,
start_id as i64
)
.instrument("get_l1_transactions_hashes")
.with_arg("start_id", &start_id)
.fetch_all(self.storage)
.await?;
Ok(hashes
.into_iter()
.map(|row| H256::from_slice(&row.hash))
.collect())
}

pub async fn insert_system_transaction(&mut self, tx: &ProtocolUpgradeTx) -> DalResult<()> {
let contract_address = tx.execute.contract_address;
let contract_address_as_bytes = contract_address.map(|addr| addr.as_bytes().to_vec());
Expand Down
40 changes: 32 additions & 8 deletions core/lib/env_config/src/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
use zksync_config::{configs::EcosystemContracts, ContractsConfig};

use crate::{envy_load, FromEnv};
use crate::{envy_load, FromEnv, FromEnvVariant};

impl FromEnv for EcosystemContracts {
fn from_env() -> anyhow::Result<Self> {
Self::from_env_variant("".to_string())
}
}
impl FromEnvVariant for EcosystemContracts {
fn from_env_variant(variant: String) -> anyhow::Result<Self> {
Ok(Self {
bridgehub_proxy_addr: std::env::var("CONTRACTS_BRIDGEHUB_PROXY_ADDR")?.parse()?,
state_transition_proxy_addr: std::env::var("CONTRACTS_STATE_TRANSITION_PROXY_ADDR")?
.parse()?,
transparent_proxy_admin_addr: std::env::var("CONTRACTS_TRANSPARENT_PROXY_ADMIN_ADDR")?
.parse()?,
bridgehub_proxy_addr: std::env::var(format!(
"{variant}CONTRACTS_BRIDGEHUB_PROXY_ADDR"
))?
.parse()?,
state_transition_proxy_addr: std::env::var(format!(
"{variant}CONTRACTS_STATE_TRANSITION_PROXY_ADDR"
))?
.parse()?,
transparent_proxy_admin_addr: std::env::var(format!(
"{variant}CONTRACTS_TRANSPARENT_PROXY_ADMIN_ADDR"
))?
.parse()?,
// Not supported yet
l1_bytecodes_supplier_addr: None,
})
}
}

impl FromEnv for ContractsConfig {
fn from_env() -> anyhow::Result<Self> {
let mut contracts: ContractsConfig = envy_load("contracts", "CONTRACTS_")?;
Self::from_env_variant("".to_string())
}
}

impl FromEnvVariant for ContractsConfig {
fn from_env_variant(variant: String) -> anyhow::Result<Self> {
let mut contracts: ContractsConfig =
envy_load("contracts", &format!("{variant}CONTRACTS_"))?;
// Note: we are renaming the bridge, the address remains the same
// These two config variables should always have the same value.
// TODO(EVM-578): double check and potentially forbid both of them being `None`.
Expand All @@ -35,7 +56,7 @@ impl FromEnv for ContractsConfig {
panic!("L2 erc20 bridge address and L2 shared bridge address are different.");
}
}
contracts.ecosystem_contracts = EcosystemContracts::from_env().ok();
contracts.ecosystem_contracts = EcosystemContracts::from_env_variant(variant).ok();
Ok(contracts)
}
}
Expand Down Expand Up @@ -70,8 +91,11 @@ mod tests {
bridgehub_proxy_addr: addr("0x35ea7f92f4c5f433efe15284e99c040110cf6297"),
state_transition_proxy_addr: addr("0xd90f1c081c6117241624e97cb6147257c3cb2097"),
transparent_proxy_admin_addr: addr("0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347e5"),
l1_bytecodes_supplier_addr: None,
}),
base_token_addr: Some(SHARED_BRIDGE_ETHER_TOKEN_ADDRESS),
base_token_asset_id: None,
predeployed_l2_wrapped_base_token_address: None,
chain_admin_addr: Some(addr("0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347ff")),
l2_da_validator_addr: Some(addr("0xed6fa5c14e7550b4caf2aa2818d24c69cbc347ff")),
l2_timestamp_asserter_addr: Some(addr("0x0000000000000000000000000000000000000002")),
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 @@ -85,7 +85,6 @@ impl FromEnv for GenesisConfig {
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),
sl_chain_id: Some(network_config.network.chain_id()),
l2_chain_id: network_config.zksync_network_id,
snark_wrapper_vk_hash: contracts_config.snark_wrapper_vk_hash,
fee_account: state_keeper
Expand Down
4 changes: 4 additions & 0 deletions core/lib/env_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub trait FromEnv: Sized {
fn from_env() -> anyhow::Result<Self>;
}

pub trait FromEnvVariant: Sized {
fn from_env_variant(variant_prefix: String) -> anyhow::Result<Self>;
}

/// Convenience function that loads the structure from the environment variable given the prefix.
/// Panics if the config cannot be loaded from the environment variables.
pub fn envy_load<T: DeserializeOwned>(name: &str, prefix: &str) -> anyhow::Result<T> {
Expand Down
Loading

0 comments on commit f6f9df3

Please sign in to comment.