Skip to content

Commit

Permalink
feat(eth-watch): redesign to support Gateway (#2775)
Browse files Browse the repository at this point in the history
Signed-off-by: tomg10 <[email protected]>
  • Loading branch information
tomg10 authored Sep 5, 2024
1 parent 91f3cdc commit b908eae
Show file tree
Hide file tree
Showing 47 changed files with 826 additions and 486 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ jobs:
ci_run zk contract migrate-to-sync-layer
ci_run zk contract prepare-sync-layer-validators
ci_run zk contract update-config-for-sync-layer
ci_run zk server --clear-l1-txs-history
ci_run sleep 120
ci_run zk server >> server2.log 2>&1 &
ci_run sleep 5
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions core/bin/external_node/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ impl ExternalNodeBuilder {
let query_eth_client_layer = QueryEthClientLayer::new(
self.config.required.settlement_layer_id(),
self.config.required.eth_client_url.clone(),
// TODO(EVM-676): add this config for external node
Default::default(),
self.config.optional.gateway_url.clone(),
);
self.node.add_layer(query_eth_client_layer);
Ok(self)
Expand Down
13 changes: 11 additions & 2 deletions core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use zksync_core_leftovers::{
temp_config_store::{decode_yaml_repr, TempConfigStore},
Component, Components,
};
use zksync_env_config::FromEnv;
use zksync_env_config::{FromEnv, FromEnvVariant};

use crate::node_builder::MainNodeBuilder;

Expand Down Expand Up @@ -143,6 +143,8 @@ fn main() -> anyhow::Result<()> {
}
};

let gateway_contracts_config = ContractsConfig::from_env_variant("GATEWAY_".to_string()).ok();

let genesis = match opt.genesis_path {
None => GenesisConfig::from_env().context("Genesis config")?,
Some(path) => {
Expand Down Expand Up @@ -174,7 +176,14 @@ fn main() -> anyhow::Result<()> {
return Ok(());
}

let node = MainNodeBuilder::new(configs, wallets, genesis, contracts_config, secrets)?;
let node = MainNodeBuilder::new(
configs,
wallets,
genesis,
contracts_config,
gateway_contracts_config,
secrets,
)?;

let observability_guard = {
// Observability initialization should be performed within tokio context.
Expand Down
17 changes: 12 additions & 5 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub struct MainNodeBuilder {
wallets: Wallets,
genesis_config: GenesisConfig,
contracts_config: ContractsConfig,
gateway_contracts_config: Option<ContractsConfig>,
secrets: Secrets,
}

Expand All @@ -96,6 +97,7 @@ impl MainNodeBuilder {
wallets: Wallets,
genesis_config: GenesisConfig,
contracts_config: ContractsConfig,
gateway_contracts_config: Option<ContractsConfig>,
secrets: Secrets,
) -> anyhow::Result<Self> {
Ok(Self {
Expand All @@ -104,6 +106,7 @@ impl MainNodeBuilder {
wallets,
genesis_config,
contracts_config,
gateway_contracts_config,
secrets,
})
}
Expand Down Expand Up @@ -147,6 +150,7 @@ impl MainNodeBuilder {
self.node.add_layer(PKSigningEthClientLayer::new(
eth_config,
self.contracts_config.clone(),
self.gateway_contracts_config.clone(),
self.genesis_config.settlement_layer_id(),
wallets,
));
Expand All @@ -159,11 +163,7 @@ impl MainNodeBuilder {
let query_eth_client_layer = QueryEthClientLayer::new(
genesis.settlement_layer_id(),
eth_config.l1_rpc_url,
self.configs
.eth
.as_ref()
.and_then(|x| Some(x.gas_adjuster?.settlement_mode))
.unwrap_or(SettlementMode::SettlesToL1),
eth_config.gateway_url,
);
self.node.add_layer(query_eth_client_layer);
Ok(self)
Expand Down Expand Up @@ -294,6 +294,12 @@ impl MainNodeBuilder {
.add_layer(EthWatchLayer::new(
try_load_config!(eth_config.watcher),
self.contracts_config.clone(),
self.gateway_contracts_config.clone(),
self.configs
.eth
.as_ref()
.and_then(|x| Some(x.gas_adjuster?.settlement_mode))
.unwrap_or(SettlementMode::SettlesToL1),
));
Ok(self)
}
Expand Down Expand Up @@ -454,6 +460,7 @@ impl MainNodeBuilder {
.add_layer(EthTxAggregatorLayer::new(
eth_sender_config,
self.contracts_config.clone(),
self.gateway_contracts_config.clone(),
self.genesis_config.l2_chain_id,
self.genesis_config.l1_batch_commit_data_generator_mode,
self.configs
Expand Down
8 changes: 8 additions & 0 deletions core/lib/config/src/configs/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ impl SenderConfig {
.map(|pk| pk.parse().unwrap())
}

// Don't load gateway private key, if it's not required
#[deprecated]
pub fn private_key_gateway(&self) -> Option<H256> {
std::env::var("ETH_SENDER_SENDER_OPERATOR_GATEWAY_PRIVATE_KEY")
.ok()
.map(|pk| pk.parse().unwrap())
}

const fn default_tx_aggregation_paused() -> bool {
false
}
Expand Down
1 change: 1 addition & 0 deletions core/lib/config/src/configs/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct DatabaseSecrets {
#[derive(Debug, Clone, PartialEq)]
pub struct L1Secrets {
pub l1_rpc_url: SensitiveUrl,
pub gateway_url: Option<SensitiveUrl>,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down
2 changes: 2 additions & 0 deletions core/lib/config/src/configs/wallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl Wallet {
pub struct EthSender {
pub operator: Wallet,
pub blob_operator: Option<Wallet>,
pub gateway: Option<Wallet>,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -89,6 +90,7 @@ impl Wallets {
blob_operator: Some(
Wallet::from_private_key_bytes(H256::repeat_byte(0x2), None).unwrap(),
),
gateway: None,
}),
state_keeper: Some(StateKeeper {
fee_account: AddressWallet::from_address(H160::repeat_byte(0x3)),
Expand Down
2 changes: 2 additions & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ impl Distribution<configs::secrets::L1Secrets> for EncodeDist {
use configs::secrets::L1Secrets;
L1Secrets {
l1_rpc_url: format!("localhost:{}", rng.gen::<u16>()).parse().unwrap(),
gateway_url: Some(format!("localhost:{}", rng.gen::<u16>()).parse().unwrap()),
}
}
}
Expand Down Expand Up @@ -900,6 +901,7 @@ impl Distribution<configs::wallets::EthSender> for EncodeDist {
configs::wallets::EthSender {
operator: self.sample(rng),
blob_operator: self.sample_opt(|| self.sample(rng)),
gateway: None,
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ const CHAIN_ADMIN_CONTRACT_FILE: (&str, &str) = ("governance", "IChainAdmin.sol/

const MULTICALL3_CONTRACT_FILE: (&str, &str) = ("dev-contracts", "Multicall3.sol/Multicall3.json");
const VERIFIER_CONTRACT_FILE: (&str, &str) = ("state-transition", "Verifier.sol/Verifier.json");

const GETTERS_CONTRACT_FILE: (&str, &str) = (
"state-transition/chain-interfaces",
"IGetters.sol/IGetters.json",
);
const _IERC20_CONTRACT_FILE: &str =
"contracts/l1-contracts/artifacts/contracts/common/interfaces/IERC20.sol/IERC20.json";
const _FAIL_ON_RECEIVE_CONTRACT_FILE: &str =
Expand Down Expand Up @@ -161,6 +166,10 @@ pub fn verifier_contract() -> Contract {
load_contract_for_both_compilers(VERIFIER_CONTRACT_FILE)
}

pub fn getters_contract() -> Contract {
load_contract_for_both_compilers(GETTERS_CONTRACT_FILE)
}

#[derive(Debug, Clone)]
pub struct TestContract {
/// Contract bytecode to be used for sending deploy transaction.
Expand Down

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

This file was deleted.

Loading

0 comments on commit b908eae

Please sign in to comment.