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

fix(configs): Refactor contracts config #3660

Open
wants to merge 25 commits into
base: deniallugo-multilayer-client
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 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
1 change: 1 addition & 0 deletions chains/era/ZkStack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ base_token:
nominator: 1
denominator: 1
wallet_creation: Localhost
evm_emulator: false
30 changes: 15 additions & 15 deletions core/Cargo.lock

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

4 changes: 2 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ members = [
"lib/external_price_api",
"lib/task_management",
"lib/test_contracts",
"lib/multilayer_client",
"lib/gateway_migrator",
"lib/zk_os_merkle_tree",
# Test infrastructure
"tests/loadnext",
Expand Down Expand Up @@ -334,4 +334,4 @@ zksync_contract_verification_server = { version = "26.5.0-non-semver-compat", pa
zksync_node_api_server = { version = "26.5.0-non-semver-compat", path = "node/api_server" }
zksync_base_token_adjuster = { version = "26.5.0-non-semver-compat", path = "node/base_token_adjuster" }
zksync_logs_bloom_backfill = { version = "26.5.0-non-semver-compat", path = "node/logs_bloom_backfill" }
zksync_multilayer_client = { version = "26.5.0-non-semver-compat", path = "lib/multilayer_client" }
zksync_gateway_migrator = { version = "26.5.0-non-semver-compat", path = "lib/gateway_migrator" }
50 changes: 23 additions & 27 deletions core/bin/block_reverter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ use zksync_block_reverter::{
use zksync_config::{
configs::{
chain::NetworkConfig, wallets::Wallets, BasicWitnessInputProducerConfig, DatabaseSecrets,
GatewayChainConfig, GeneralConfig, L1Secrets, ObservabilityConfig,
ProtectiveReadsWriterConfig,
GeneralConfig, L1Secrets, ObservabilityConfig, ProtectiveReadsWriterConfig,
},
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};
use zksync_env_config::{object_store::SnapshotsObjectStoreConfig, FromEnv};
use zksync_object_store::ObjectStoreFactory;
use zksync_protobuf_config::proto;
use zksync_types::{Address, L1BatchNumber};
use zksync_types::{settlement::SettlementMode, Address, L1BatchNumber};

#[derive(Debug, Parser)]
#[command(author = "Matter Labs", version, about = "Block revert utility", long_about = None)]
Expand Down Expand Up @@ -203,7 +202,6 @@ async fn main() -> anyhow::Result<()> {

let gas_adjuster = eth_sender.gas_adjuster.context("gas_adjuster")?;
let default_priority_fee_per_gas = gas_adjuster.default_priority_fee_per_gas;
let settlement_mode = gas_adjuster.settlement_mode;

let database_secrets = match &secrets_config {
Some(secrets_config) => secrets_config
Expand Down Expand Up @@ -235,33 +233,30 @@ async fn main() -> anyhow::Result<()> {
}
};

let (sl_rpc_url, sl_diamond_proxy, sl_validator_timelock) = if settlement_mode.is_gateway() {
// Gateway config is required to be provided by file for now.
let gateway_chain_config: GatewayChainConfig =
read_yaml_repr::<proto::gateway::GatewayChainConfig>(
&opts
.gateway_chain_path
.context("Genesis config path not provided")?,
)
.context("failed decoding genesis YAML config")?;

let gateway_url = l1_secrets
.gateway_rpc_url
.context("Gateway URL not found")?;
let contracts = SettlementLayerContracts::new(&contracts, None);

// TODO think more about it
let (sl_rpc_url, settlement_mode) = if opts.gateway_chain_path.is_some() {
(
gateway_url,
gateway_chain_config.diamond_proxy_addr,
gateway_chain_config.validator_timelock_addr,
l1_secrets
.gateway_rpc_url
.context("Gateway URL not found")?,
SettlementMode::Gateway,
)
} else {
(
l1_secrets.l1_rpc_url,
contracts.diamond_proxy_addr,
contracts.validator_timelock_addr,
)
(l1_secrets.l1_rpc_url, SettlementMode::SettlesToL1)
};

let sl_diamond_proxy = contracts
.current_contracts()
.chain_contracts_config
.diamond_proxy_addr;
let sl_validator_timelock = contracts
.current_contracts()
.ecosystem_contracts
.validator_timelock_addr
.expect("Should be presented");

let config = BlockReverterEthConfig::new(
&eth_sender,
sl_diamond_proxy,
Expand Down Expand Up @@ -302,7 +297,8 @@ async fn main() -> anyhow::Result<()> {
priority_fee_per_gas,
nonce,
} => {
let sl_client = Client::http(sl_rpc_url).context("Ethereum client")?.build();
let sl_client: Client<L1> =
Client::http(sl_rpc_url).context("Ethereum client")?.build();
let reverter_private_key = if let Some(wallets_config) = wallets_config {
wallets_config
.eth_sender
Expand Down
95 changes: 69 additions & 26 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ use zksync_config::{
configs::{
api::{MaxResponseSize, MaxResponseSizeOverrides},
consensus::{ConsensusConfig, ConsensusSecrets},
contracts::{
chain::{ChainContracts, L2Contracts},
ecosystem::{EcosystemCommonContracts, L1SpecificContracts},
ChainSpecificContracts,
},
en_config::ENConfig,
DataAvailabilitySecrets, GeneralConfig, Secrets,
},
Expand All @@ -27,7 +32,7 @@ use zksync_env_config::da_client::{da_client_config_from_env, da_client_secrets_
use zksync_metadata_calculator::MetadataCalculatorRecoveryConfig;
use zksync_node_api_server::{
tx_sender::{TimestampAsserterParams, TxSenderConfig},
web3::{state::InternalApiConfig, Namespace},
web3::{state::InternalApiConfigBuilder, Namespace},
};
use zksync_protobuf_config::proto;
use zksync_snapshots_applier::SnapshotsApplierConfig;
Expand Down Expand Up @@ -131,7 +136,7 @@ pub(crate) struct RemoteENConfig {
pub l2_timestamp_asserter_addr: Option<Address>,
pub l1_wrapped_base_token_store: Option<Address>,
pub l1_server_notifier_addr: Option<Address>,
pub base_token_addr: Address,
pub base_token_addr: Option<Address>,
pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode,
pub dummy_verifier: bool,
}
Expand Down Expand Up @@ -191,10 +196,10 @@ impl RemoteENConfig {
l1_bridgehub_proxy_addr: ecosystem_contracts.as_ref().map(|a| a.bridgehub_proxy_addr),
l1_state_transition_proxy_addr: ecosystem_contracts
.as_ref()
.map(|a| a.state_transition_proxy_addr),
.and_then(|a| a.state_transition_proxy_addr),
l1_transparent_proxy_admin_addr: ecosystem_contracts
.as_ref()
.map(|a| a.transparent_proxy_admin_addr),
.and_then(|a| a.transparent_proxy_admin_addr),
l1_bytecodes_supplier_addr: ecosystem_contracts
.as_ref()
.and_then(|a| a.l1_bytecodes_supplier_addr),
Expand All @@ -213,7 +218,7 @@ impl RemoteENConfig {
l2_legacy_shared_bridge_addr: bridges.l2_legacy_shared_bridge,
l1_weth_bridge_addr: bridges.l1_weth_bridge,
l2_weth_bridge_addr: bridges.l2_weth_bridge,
base_token_addr,
base_token_addr: Some(base_token_addr),
l1_batch_commit_data_generator_mode: genesis
.as_ref()
.map(|a| a.l1_batch_commit_data_generator_mode)
Expand All @@ -238,7 +243,7 @@ impl RemoteENConfig {
l2_erc20_bridge_addr: Some(Address::repeat_byte(3)),
l2_weth_bridge_addr: None,
l2_testnet_paymaster_addr: None,
base_token_addr: Address::repeat_byte(4),
base_token_addr: Some(Address::repeat_byte(4)),
l1_shared_bridge_proxy_addr: Some(Address::repeat_byte(5)),
l1_weth_bridge_addr: None,
l2_shared_bridge_addr: Some(Address::repeat_byte(6)),
Expand Down Expand Up @@ -1479,37 +1484,37 @@ impl ExternalNodeConfig {
}
}

impl From<&ExternalNodeConfig> for InternalApiConfig {
impl From<&ExternalNodeConfig> for InternalApiConfigBuilder {
fn from(config: &ExternalNodeConfig) -> Self {
Self {
l1_chain_id: config.required.l1_chain_id,
l2_chain_id: config.required.l2_chain_id,
max_tx_size: config.optional.max_tx_size_bytes,
estimate_gas_scale_factor: config.optional.estimate_gas_scale_factor,
estimate_gas_acceptable_overestimation: config
.optional
.estimate_gas_acceptable_overestimation,
estimate_gas_optimize_search: config.optional.estimate_gas_optimize_search,
bridge_addresses: BridgeAddresses {
max_tx_size: Some(config.optional.max_tx_size_bytes),
estimate_gas_scale_factor: Some(config.optional.estimate_gas_scale_factor),
estimate_gas_acceptable_overestimation: Some(
config.optional.estimate_gas_acceptable_overestimation,
),
estimate_gas_optimize_search: Some(config.optional.estimate_gas_optimize_search),
bridge_addresses: Some(BridgeAddresses {
l1_erc20_default_bridge: config.remote.l1_erc20_bridge_proxy_addr,
l2_erc20_default_bridge: config.remote.l2_erc20_bridge_addr,
l1_shared_default_bridge: config.remote.l1_shared_bridge_proxy_addr,
l2_shared_default_bridge: config.remote.l2_shared_bridge_addr,
l2_legacy_shared_bridge: config.remote.l2_legacy_shared_bridge_addr,
l1_weth_bridge: config.remote.l1_weth_bridge_addr,
l2_weth_bridge: config.remote.l2_weth_bridge_addr,
},
}),
l1_bytecodes_supplier_addr: config.remote.l1_bytecodes_supplier_addr,
l1_wrapped_base_token_store: config.remote.l1_wrapped_base_token_store,
l1_bridgehub_proxy_addr: config.remote.l1_bridgehub_proxy_addr,
l1_state_transition_proxy_addr: config.remote.l1_state_transition_proxy_addr,
l1_transparent_proxy_admin_addr: config.remote.l1_transparent_proxy_admin_addr,
l1_diamond_proxy_addr: config.l1_diamond_proxy_address(),
l1_diamond_proxy_addr: Some(config.l1_diamond_proxy_address()),
l2_testnet_paymaster_addr: config.remote.l2_testnet_paymaster_addr,
req_entities_limit: config.optional.req_entities_limit,
fee_history_limit: config.optional.fee_history_limit,
base_token_address: Some(config.remote.base_token_addr),
filters_disabled: config.optional.filters_disabled,
req_entities_limit: Some(config.optional.req_entities_limit),
fee_history_limit: Some(config.optional.fee_history_limit),
base_token_address: config.remote.base_token_addr,
filters_disabled: Some(config.optional.filters_disabled),
dummy_verifier: config.remote.dummy_verifier,
l1_batch_commit_data_generator_mode: config.remote.l1_batch_commit_data_generator_mode,
timestamp_asserter_address: config.remote.l2_timestamp_asserter_addr,
Expand All @@ -1536,17 +1541,55 @@ impl From<&ExternalNodeConfig> for TxSenderConfig {
chain_id: config.required.l2_chain_id,
// Does not matter for EN.
whitelisted_tokens_for_aa: Default::default(),
timestamp_asserter_params: config.remote.l2_timestamp_asserter_addr.map(|address| {
timestamp_asserter_params: config.remote.l2_timestamp_asserter_addr.map(|addr| {
TimestampAsserterParams {
address,
address: addr,
min_time_till_end: Duration::from_secs(
config
.optional
.timestamp_asserter_min_time_till_end_sec
.into(),
config.optional.timestamp_asserter_min_time_till_end_sec as u64,
),
}
}),
}
}
}

impl From<&ExternalNodeConfig> for L1SpecificContracts {
fn from(config: &ExternalNodeConfig) -> Self {
L1SpecificContracts {
bytecodes_supplier_addr: config.remote.l1_bytecodes_supplier_addr,
wrapped_base_token_store: config.remote.l1_wrapped_base_token_store,
bridge_hub: config.remote.l1_bridgehub_proxy_addr,
shared_bridge: config.remote.l1_shared_bridge_proxy_addr,
erc_20_bridge: config.remote.l1_erc20_bridge_proxy_addr,
base_token_address: config.remote.base_token_addr,
l1_diamond_proxy: config.l1_diamond_proxy_address(),
}
}
}

impl From<&ExternalNodeConfig> for ChainSpecificContracts {
fn from(config: &ExternalNodeConfig) -> Self {
ChainSpecificContracts {
ecosystem_contracts: EcosystemCommonContracts {
bridgehub_proxy_addr: config.remote.l1_bridgehub_proxy_addr,
state_transition_proxy_addr: config.remote.l1_state_transition_proxy_addr,
server_notifier_addr: config.remote.l1_server_notifier_addr,
multicall3: None,
validator_timelock_addr: None,
no_da_validium_l1_validator_addr: None,
},
chain_contracts_config: ChainContracts {
diamond_proxy_addr: config.remote.l1_diamond_proxy_addr,
chain_admin: None,
},
l2_contracts: L2Contracts {
erc20_default_bridge: config.remote.l2_erc20_bridge_addr,
shared_bridge_addr: config.remote.l2_shared_bridge_addr,
legacy_shared_bridge_addr: config.remote.l2_legacy_shared_bridge_addr,
timestamp_asserter_addr: config.remote.l2_timestamp_asserter_addr,
da_validator_addr: None,
testnet_paymaster_addr: config.remote.l2_testnet_paymaster_addr,
},
}
}
}
Loading
Loading