Skip to content

Commit

Permalink
Rename structs
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Mar 4, 2025
1 parent cf094e2 commit af0626e
Show file tree
Hide file tree
Showing 31 changed files with 163 additions and 128 deletions.
4 changes: 2 additions & 2 deletions core/bin/block_reverter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zksync_config::{
chain::NetworkConfig, wallets::Wallets, BasicWitnessInputProducerConfig, DatabaseSecrets,
GeneralConfig, L1Secrets, ObservabilityConfig, ProtectiveReadsWriterConfig,
},
Contracts, ContractsConfig, DBConfig, EthConfig, GenesisConfig, PostgresConfig,
ContractsConfig, DBConfig, EthConfig, GenesisConfig, PostgresConfig, SettlementLayerContracts,
};
use zksync_core_leftovers::temp_config_store::read_yaml_repr;
use zksync_dal::{ConnectionPool, Core};
Expand Down Expand Up @@ -234,7 +234,7 @@ async fn main() -> anyhow::Result<()> {
}
};

let contracts = Contracts::new(contracts, None);
let contracts = SettlementLayerContracts::new(&contracts, None);

let sl_rpc_url = if settlement_mode.is_gateway() {
l1_secrets
Expand Down
2 changes: 1 addition & 1 deletion core/bin/genesis_generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use zksync_types::{
protocol_version::ProtocolSemanticVersion, url::SensitiveUrl, ProtocolVersionId,
};

const DEFAULT_GENESIS_FILE_PATH: &str = "./etc/env/file_based/genesis.yaml";
const DEFAULT_GENESIS_FILE_PATH: &str = "../etc/env/file_based/genesis.yaml";

#[derive(Debug, Parser)]
#[command(author = "Matter Labs", version, about = "Genesis config generator", long_about = None)]
Expand Down
23 changes: 17 additions & 6 deletions core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use zksync_config::{
CircuitBreakerConfig, MempoolConfig, NetworkConfig, OperationsManagerConfig,
StateKeeperConfig, TimestampAsserterConfig,
},
contracts::ecosystem::EcosystemL1SpecificContracts,
fri_prover_group::FriProverGroupConfig,
house_keeper::HouseKeeperConfig,
BasicWitnessInputProducerConfig, ContractVerifierSecrets, DataAvailabilitySecrets,
Expand All @@ -17,10 +18,10 @@ use zksync_config::{
FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, L1Secrets, ObservabilityConfig,
PrometheusConfig, ProofDataHandlerConfig, ProtectiveReadsWriterConfig, Secrets,
},
ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, Contracts, ContractsConfig,
DAClientConfig, DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig,
ExternalProofIntegrationApiConfig, GasAdjusterConfig, GenesisConfig, ObjectStoreConfig,
PostgresConfig, SnapshotsCreatorConfig,
ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, ContractsConfig, DAClientConfig,
DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig, ExternalProofIntegrationApiConfig,
GasAdjusterConfig, GenesisConfig, ObjectStoreConfig, PostgresConfig, SettlementLayerContracts,
SnapshotsCreatorConfig,
};
use zksync_core_leftovers::{
temp_config_store::{read_yaml_repr, TempConfigStore},
Expand Down Expand Up @@ -157,8 +158,18 @@ fn main() -> anyhow::Result<()> {
.clone()
.context("observability config")?;

let contracts = Contracts::new(contracts_config, gateway_contracts_config);
let node = MainNodeBuilder::new(configs, wallets, genesis, secrets, contracts)?;
let l1_specific_contracts = EcosystemL1SpecificContracts::new(&contracts_config);
let contracts =
SettlementLayerContracts::new(&contracts_config, gateway_contracts_config.as_ref());

let node = MainNodeBuilder::new(
configs,
wallets,
genesis,
secrets,
contracts,
l1_specific_contracts,
)?;

let observability_guard = {
// Observability initialization should be performed within tokio context.
Expand Down
22 changes: 13 additions & 9 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
use anyhow::{bail, Context};
use zksync_config::{
configs::{
da_client::DAClientConfig, secrets::DataAvailabilitySecrets, wallets::Wallets,
GeneralConfig, Secrets,
contracts::ecosystem::EcosystemL1SpecificContracts, da_client::DAClientConfig,
secrets::DataAvailabilitySecrets, wallets::Wallets, GeneralConfig, Secrets,
},
Contracts, GenesisConfig,
GenesisConfig, SettlementLayerContracts,
};
use zksync_core_leftovers::Component;
use zksync_metadata_calculator::MetadataCalculatorConfig;
Expand Down Expand Up @@ -93,7 +93,8 @@ pub struct MainNodeBuilder {
wallets: Wallets,
genesis_config: GenesisConfig,
secrets: Secrets,
contracts: Contracts,
contracts: SettlementLayerContracts,
l1_specific_contracts: EcosystemL1SpecificContracts,
}

impl MainNodeBuilder {
Expand All @@ -102,7 +103,8 @@ impl MainNodeBuilder {
wallets: Wallets,
genesis_config: GenesisConfig,
secrets: Secrets,
contracts: Contracts,
contracts: SettlementLayerContracts,
l1_specific_contracts: EcosystemL1SpecificContracts,
) -> anyhow::Result<Self> {
Ok(Self {
node: ZkStackServiceBuilder::new().context("Cannot create ZkStackServiceBuilder")?,
Expand All @@ -111,6 +113,7 @@ impl MainNodeBuilder {
genesis_config,
secrets,
contracts,
l1_specific_contracts,
})
}

Expand Down Expand Up @@ -214,8 +217,7 @@ impl MainNodeBuilder {

fn add_l1_gas_layer(mut self) -> anyhow::Result<Self> {
// Ensure the BaseTokenRatioProviderResource is inserted if the base token is not ETH.
if self.contracts.l1_specific_contracts().base_token_address
!= Some(SHARED_BRIDGE_ETHER_TOKEN_ADDRESS)
if self.l1_specific_contracts.base_token_address != Some(SHARED_BRIDGE_ETHER_TOKEN_ADDRESS)
{
let base_token_adjuster_config = try_load_config!(self.configs.base_token_adjuster);
self.node
Expand Down Expand Up @@ -314,8 +316,10 @@ impl MainNodeBuilder {
}

fn add_settlement_mode_data(mut self) -> anyhow::Result<Self> {
self.node
.add_layer(SettlementLayerData::new(self.contracts.clone()));
self.node.add_layer(SettlementLayerData::new(
self.contracts.clone(),
self.l1_specific_contracts.clone(),
));
Ok(self)
}

Expand Down
19 changes: 17 additions & 2 deletions core/lib/config/src/configs/contracts/ecosystem.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// External uses
use serde::{Deserialize, Serialize};
// Workspace uses
use zksync_basic_types::Address;

// Workspace uses
use crate::configs::AllContractsConfig;

// Unified ecosystem contracts. To be deleted, after contracts config migration
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct EcosystemContracts {
Expand Down Expand Up @@ -32,7 +34,7 @@ impl EcosystemContracts {

// Ecosystem contracts that are specific only for L1
#[derive(Debug, Clone)]
pub struct EcosystemL1Specific {
pub struct EcosystemL1SpecificContracts {
pub bytecodes_supplier_addr: Option<Address>,
// Note that on the contract side of things this contract is called `L2WrappedBaseTokenStore`,
// while on the server side for consistency with the conventions, where the prefix denotes
Expand All @@ -53,3 +55,16 @@ pub struct EcosystemCommonContracts {
pub validator_timelock_addr: Address,
pub no_da_validium_l1_validator_addr: Option<Address>,
}

impl EcosystemL1SpecificContracts {
pub fn new(contracts_config: &AllContractsConfig) -> Self {
let ecosystem = contracts_config.ecosystem_contracts.as_ref().unwrap();
Self {
bytecodes_supplier_addr: ecosystem.l1_bytecodes_supplier_addr,
wrapped_base_token_store: ecosystem.l1_wrapped_base_token_store,
shared_bridge: contracts_config.l1_shared_bridge_proxy_addr,
erc_20_bridge: contracts_config.l1_erc20_bridge_proxy_addr,
base_token_address: contracts_config.base_token_addr,
}
}
}
26 changes: 7 additions & 19 deletions core/lib/config/src/configs/contracts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use zksync_basic_types::{settlement::SettlementMode, Address, SLChainId, H160};
use crate::configs::{
contracts::{
chain::{AllContractsConfig, ChainContracts, L2Contracts},
ecosystem::{EcosystemCommonContracts, EcosystemL1Specific},
ecosystem::EcosystemCommonContracts,
},
gateway::GatewayChainConfig,
};
Expand All @@ -25,26 +25,21 @@ pub struct ChainSpecificContracts {
}

#[derive(Debug, Clone)]
pub struct Contracts {
l1_specific: EcosystemL1Specific,
pub struct SettlementLayerContracts {
l1_contracts: ChainSpecificContracts,
gateway_contracts: Option<ChainSpecificContracts>,
sl_mode: SettlementMode,
gateway_chain_id: Option<SLChainId>,
}

impl Contracts {
impl SettlementLayerContracts {
pub fn current_contracts(&self) -> &ChainSpecificContracts {
match self.sl_mode {
SettlementMode::SettlesToL1 => &self.l1_contracts,
SettlementMode::Gateway => self.gateway_contracts.as_ref().expect("Settles to Gateway"),
}
}

pub fn l1_specific_contracts(&self) -> &EcosystemL1Specific {
&self.l1_specific
}

pub fn l1_contracts(&self) -> &ChainSpecificContracts {
&self.l1_contracts
}
Expand All @@ -60,20 +55,13 @@ impl Contracts {
}
}

impl Contracts {
impl SettlementLayerContracts {
pub fn new(
contracts_config: AllContractsConfig,
gateway_chain_config: Option<GatewayChainConfig>,
contracts_config: &AllContractsConfig,
gateway_chain_config: Option<&GatewayChainConfig>,
) -> Self {
let ecosystem = contracts_config.ecosystem_contracts.unwrap();
let ecosystem = contracts_config.ecosystem_contracts.as_ref().unwrap();
Self {
l1_specific: EcosystemL1Specific {
bytecodes_supplier_addr: ecosystem.l1_bytecodes_supplier_addr,
wrapped_base_token_store: ecosystem.l1_wrapped_base_token_store,
shared_bridge: contracts_config.l1_shared_bridge_proxy_addr,
erc_20_bridge: contracts_config.l1_erc20_bridge_proxy_addr,
base_token_address: contracts_config.base_token_addr,
},
l1_contracts: ChainSpecificContracts {
ecosystem_contracts: EcosystemCommonContracts {
bridgehub_proxy_addr: ecosystem.bridgehub_proxy_addr,
Expand Down
2 changes: 1 addition & 1 deletion core/lib/config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::upper_case_acronyms, clippy::derive_partial_eq_without_eq)]

pub use crate::configs::{
contracts::{chain::AllContractsConfig as ContractsConfig, Contracts},
contracts::{chain::AllContractsConfig as ContractsConfig, SettlementLayerContracts},
ApiConfig, AvailConfig, BaseTokenAdjusterConfig, CelestiaConfig, ContractVerifierConfig,
DAClientConfig, DADispatcherConfig, DBConfig, EigenConfig, EthConfig, EthWatchConfig,
ExternalProofIntegrationApiConfig, GasAdjusterConfig, GenesisConfig, ObjectStoreConfig,
Expand Down
43 changes: 21 additions & 22 deletions core/node/api_server/src/web3/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use futures::TryFutureExt;
use lru::LruCache;
use tokio::sync::{Mutex, RwLock};
use vise::GaugeGuard;
use zksync_config::{configs::api::Web3JsonRpcConfig, Contracts, GenesisConfig};
use zksync_config::{
configs::{api::Web3JsonRpcConfig, contracts::ecosystem::EcosystemL1SpecificContracts},
GenesisConfig, SettlementLayerContracts,
};
use zksync_dal::{Connection, ConnectionPool, Core, CoreDal, DalError};
use zksync_metadata_calculator::api_server::TreeApiClient;
use zksync_node_sync::SyncState;
Expand Down Expand Up @@ -163,15 +166,19 @@ impl InternalApiConfigBuilder {
self
}

pub fn with_contracts(mut self, contracts_config: Contracts) -> Self {
self.base_token_address = contracts_config.l1_specific_contracts().base_token_address;
pub fn with_contracts(
mut self,
contracts_config: SettlementLayerContracts,
l1_ecosystem_contracts: EcosystemL1SpecificContracts,
) -> Self {
self.base_token_address = l1_ecosystem_contracts.base_token_address;
self.bridge_addresses = Some(BridgeAddresses {
l1_erc20_default_bridge: contracts_config.l1_specific_contracts().erc_20_bridge,
l1_erc20_default_bridge: l1_ecosystem_contracts.erc_20_bridge,
l2_erc20_default_bridge: contracts_config
.current_contracts()
.l2_contracts
.erc20_default_bridge,
l1_shared_default_bridge: contracts_config.l1_specific_contracts().shared_bridge,
l1_shared_default_bridge: l1_ecosystem_contracts.shared_bridge,
l2_shared_default_bridge: contracts_config
.current_contracts()
.l2_contracts
Expand All @@ -197,12 +204,8 @@ impl InternalApiConfigBuilder {
.state_transition_proxy_addr,
);

self.l1_bytecodes_supplier_addr = contracts_config
.l1_specific_contracts()
.bytecodes_supplier_addr;
self.l1_wrapped_base_token_store = contracts_config
.l1_specific_contracts()
.wrapped_base_token_store;
self.l1_bytecodes_supplier_addr = l1_ecosystem_contracts.bytecodes_supplier_addr;
self.l1_wrapped_base_token_store = l1_ecosystem_contracts.wrapped_base_token_store;
self.l1_diamond_proxy_addr = Some(
contracts_config
.current_contracts()
Expand Down Expand Up @@ -280,7 +283,8 @@ pub struct InternalApiConfig {
impl InternalApiConfig {
pub fn new(
web3_config: &Web3JsonRpcConfig,
contracts_config: &Contracts,
contracts_config: &SettlementLayerContracts,
l1_ecosystem_contracts: &EcosystemL1SpecificContracts,
genesis_config: &GenesisConfig,
) -> Self {
Self {
Expand All @@ -292,12 +296,12 @@ impl InternalApiConfig {
.estimate_gas_acceptable_overestimation,
estimate_gas_optimize_search: web3_config.estimate_gas_optimize_search,
bridge_addresses: api::BridgeAddresses {
l1_erc20_default_bridge: contracts_config.l1_specific_contracts().erc_20_bridge,
l1_erc20_default_bridge: l1_ecosystem_contracts.erc_20_bridge,
l2_erc20_default_bridge: contracts_config
.current_contracts()
.l2_contracts
.erc20_default_bridge,
l1_shared_default_bridge: contracts_config.l1_specific_contracts().shared_bridge,
l1_shared_default_bridge: l1_ecosystem_contracts.shared_bridge,
l2_shared_default_bridge: contracts_config
.current_contracts()
.l2_contracts
Expand All @@ -324,12 +328,8 @@ impl InternalApiConfig {
),

l1_transparent_proxy_admin_addr: None,
l1_bytecodes_supplier_addr: contracts_config
.l1_specific_contracts()
.bytecodes_supplier_addr,
l1_wrapped_base_token_store: contracts_config
.l1_specific_contracts()
.wrapped_base_token_store,
l1_bytecodes_supplier_addr: l1_ecosystem_contracts.bytecodes_supplier_addr,
l1_wrapped_base_token_store: l1_ecosystem_contracts.wrapped_base_token_store,
l1_diamond_proxy_addr: contracts_config
.current_contracts()
.chain_contracts_config
Expand All @@ -341,8 +341,7 @@ impl InternalApiConfig {
req_entities_limit: web3_config.req_entities_limit(),
fee_history_limit: web3_config.fee_history_limit(),
base_token_address: Some(
contracts_config
.l1_specific_contracts()
l1_ecosystem_contracts
.base_token_address
.unwrap_or(ETHEREUM_ADDRESS),
),
Expand Down
4 changes: 2 additions & 2 deletions core/node/api_server/src/web3/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use zksync_config::{
chain::{NetworkConfig, StateKeeperConfig},
AllContractsConfig as ContractsConfig,
},
Contracts, GenesisConfig,
GenesisConfig, SettlementLayerContracts,
};
use zksync_contracts::BaseSystemContracts;
use zksync_dal::{Connection, ConnectionPool, CoreDal};
Expand Down Expand Up @@ -287,7 +287,7 @@ async fn test_http_server(test: impl HttpTest) {
let genesis = GenesisConfig::for_tests();
let mut api_config = InternalApiConfig::new(
&web3_config,
&Contracts::new(contracts_config, None),
&SettlementLayerContracts::new(contracts_config, None),
&genesis,
);
api_config.filters_disabled = test.filters_disabled();
Expand Down
4 changes: 2 additions & 2 deletions core/node/api_server/src/web3/tests/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use assert_matches::assert_matches;
use async_trait::async_trait;
use http::StatusCode;
use tokio::sync::watch;
use zksync_config::{configs::chain::NetworkConfig, Contracts};
use zksync_config::{configs::chain::NetworkConfig, SettlementLayerContracts};
use zksync_dal::ConnectionPool;
use zksync_types::{api, Address, Bloom, L1BatchNumber, H160, H256, U64};
use zksync_web3_decl::{
Expand Down Expand Up @@ -171,7 +171,7 @@ async fn test_ws_server(test: impl WsTest) {

let api_config = InternalApiConfig::new(
&web3_config,
&Contracts::new(contracts_config, None),
&SettlementLayerContracts::new(contracts_config, None),
&genesis_config,
);
let mut storage = pool.connection().await.unwrap();
Expand Down
Loading

0 comments on commit af0626e

Please sign in to comment.