Skip to content

Commit

Permalink
feat(eth-watch): Brush up Ethereum watcher component (#1596)
Browse files Browse the repository at this point in the history
## What ❔

Brushes up the Ethereum Watcher component that was recently moved to its
own crate. Wraps `sqlx` errors in the relevant DB queries.

## Why ❔

Simplifies maintenance.

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `zk spellcheck`.
- [x] Linkcheck has been run via `zk linkcheck`.
  • Loading branch information
slowli committed Apr 12, 2024
1 parent f763d1f commit b0b8f89
Show file tree
Hide file tree
Showing 44 changed files with 513 additions and 683 deletions.
2 changes: 0 additions & 2 deletions 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/bin/block_reverter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Context as _;
use clap::{Parser, Subcommand};
use tokio::io::{self, AsyncReadExt};
use zksync_config::{
configs::ObservabilityConfig, ContractsConfig, DBConfig, ETHConfig, PostgresConfig,
configs::ObservabilityConfig, ContractsConfig, DBConfig, EthConfig, PostgresConfig,
};
use zksync_core::block_reverter::{
BlockReverter, BlockReverterEthConfig, BlockReverterFlags, L1ExecutedBatchesRevert, NodeRole,
Expand Down Expand Up @@ -90,7 +90,7 @@ async fn main() -> anyhow::Result<()> {
}
let _guard = builder.build();

let eth_sender = ETHConfig::from_env().context("ETHSenderConfig::from_env()")?;
let eth_sender = EthConfig::from_env().context("EthConfig::from_env()")?;
let db_config = DBConfig::from_env().context("DBConfig::from_env()")?;
let default_priority_fee_per_gas = U256::from(
eth_sender
Expand Down
6 changes: 3 additions & 3 deletions core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use zksync_config::{
FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, ObservabilityConfig,
PrometheusConfig, ProofDataHandlerConfig,
},
ApiConfig, ContractVerifierConfig, DBConfig, ETHConfig, ETHWatchConfig, GasAdjusterConfig,
ApiConfig, ContractVerifierConfig, DBConfig, EthConfig, EthWatchConfig, GasAdjusterConfig,
GenesisConfig, ObjectStoreConfig, PostgresConfig, SnapshotsCreatorConfig,
};
use zksync_core::{
Expand Down Expand Up @@ -271,8 +271,8 @@ fn load_env_config() -> anyhow::Result<TempConfigStore> {
proof_data_handler_config: ProofDataHandlerConfig::from_env().ok(),
api_config: ApiConfig::from_env().ok(),
db_config: DBConfig::from_env().ok(),
eth_sender_config: ETHConfig::from_env().ok(),
eth_watch_config: ETHWatchConfig::from_env().ok(),
eth_sender_config: EthConfig::from_env().ok(),
eth_watch_config: EthWatchConfig::from_env().ok(),
gas_adjuster_config: GasAdjusterConfig::from_env().ok(),
object_store_config: ObjectStoreConfig::from_env().ok(),
observability: ObservabilityConfig::from_env().ok(),
Expand Down
10 changes: 5 additions & 5 deletions core/lib/config/src/configs/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ use std::time::Duration;
use serde::Deserialize;
use zksync_basic_types::H256;

use crate::ETHWatchConfig;
use crate::EthWatchConfig;

/// Configuration for the Ethereum related components.
#[derive(Debug, Deserialize, Clone, PartialEq)]
pub struct ETHConfig {
pub struct EthConfig {
/// Options related to the Ethereum sender directly.
pub sender: Option<SenderConfig>,
/// Options related to the `GasAdjuster` submodule.
pub gas_adjuster: Option<GasAdjusterConfig>,
pub watcher: Option<ETHWatchConfig>,
pub watcher: Option<EthWatchConfig>,
pub web3_url: String,
}

impl ETHConfig {
impl EthConfig {
/// Creates a mock configuration object suitable for unit tests.
/// Values inside match the config used for localhost development.
pub fn for_tests() -> Self {
Expand Down Expand Up @@ -55,7 +55,7 @@ impl ETHConfig {
internal_pubdata_pricing_multiplier: 1.0,
max_blob_base_fee: None,
}),
watcher: Some(ETHWatchConfig {
watcher: Some(EthWatchConfig {
confirmations_for_eth_event: None,
eth_node_poll_interval: 0,
}),
Expand Down
4 changes: 2 additions & 2 deletions core/lib/config/src/configs/eth_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};

/// Configuration for the Ethereum watch crate.
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
pub struct ETHWatchConfig {
pub struct EthWatchConfig {
/// Amount of confirmations for the priority operation to be processed.
/// If not specified operation will be processed once its block is finalized.
pub confirmations_for_eth_event: Option<u64>,
Expand All @@ -13,7 +13,7 @@ pub struct ETHWatchConfig {
pub eth_node_poll_interval: u64,
}

impl ETHWatchConfig {
impl EthWatchConfig {
/// Converts `self.eth_node_poll_interval` into `Duration`.
pub fn poll_interval(&self) -> Duration {
Duration::from_millis(self.eth_node_poll_interval)
Expand Down
4 changes: 2 additions & 2 deletions core/lib/config/src/configs/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, ObservabilityConfig,
PrometheusConfig, ProofDataHandlerConfig,
},
ApiConfig, ContractVerifierConfig, DBConfig, ETHConfig, PostgresConfig, SnapshotsCreatorConfig,
ApiConfig, ContractVerifierConfig, DBConfig, EthConfig, PostgresConfig, SnapshotsCreatorConfig,
};

#[derive(Debug, PartialEq)]
Expand All @@ -29,7 +29,7 @@ pub struct GeneralConfig {
pub prometheus_config: Option<PrometheusConfig>,
pub proof_data_handler_config: Option<ProofDataHandlerConfig>,
pub db_config: Option<DBConfig>,
pub eth: Option<ETHConfig>,
pub eth: Option<EthConfig>,
pub snapshot_creator: Option<SnapshotsCreatorConfig>,
pub observability: Option<ObservabilityConfig>,
}
4 changes: 2 additions & 2 deletions core/lib/config/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub use self::{
contract_verifier::ContractVerifierConfig,
contracts::ContractsConfig,
database::{DBConfig, PostgresConfig},
eth_sender::{ETHConfig, GasAdjusterConfig},
eth_watch::ETHWatchConfig,
eth_sender::{EthConfig, GasAdjusterConfig},
eth_watch::EthWatchConfig,
fri_proof_compressor::FriProofCompressorConfig,
fri_prover::FriProverConfig,
fri_prover_gateway::FriProverGatewayConfig,
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::{
ApiConfig, ContractVerifierConfig, ContractsConfig, DBConfig, ETHConfig, ETHWatchConfig,
ApiConfig, ContractVerifierConfig, ContractsConfig, DBConfig, EthConfig, EthWatchConfig,
GasAdjusterConfig, GenesisConfig, ObjectStoreConfig, PostgresConfig, SnapshotsCreatorConfig,
};

Expand Down
12 changes: 6 additions & 6 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ impl Distribution<configs::database::PostgresConfig> for EncodeDist {
}
}

impl Distribution<configs::ETHConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::ETHConfig {
configs::ETHConfig {
impl Distribution<configs::EthConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::EthConfig {
configs::EthConfig {
sender: self.sample(rng),
gas_adjuster: self.sample(rng),
watcher: self.sample(rng),
Expand Down Expand Up @@ -379,9 +379,9 @@ impl Distribution<configs::eth_sender::GasAdjusterConfig> for EncodeDist {
}
}

impl Distribution<configs::ETHWatchConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::ETHWatchConfig {
configs::ETHWatchConfig {
impl Distribution<configs::EthWatchConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::EthWatchConfig {
configs::EthWatchConfig {
confirmations_for_eth_event: self.sample(rng),
eth_node_poll_interval: self.sample(rng),
}
Expand Down

This file was deleted.

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

This file was deleted.

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

0 comments on commit b0b8f89

Please sign in to comment.