Skip to content

Commit

Permalink
feat: Extract eth_watch and shared metrics into separate crates (#1572)
Browse files Browse the repository at this point in the history
## What ❔

- Extracts `zksync_core::metrics` module to `zksync_shared_metrics`
crate
- Extracts `zksync_core::eth_watch` to `zksync_eth_watch` crate
- Moves house keeper metrics from global metrics module to a module
specific to `house_keeper`.

## Why ❔

First two: to modularize the codebase, required for legolizer and
publishing on crates.io.
Last one: the metrics were misplaced, and do not fit in the new notion
of "shared" metrics crate.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
- [ ] Linkcheck has been run via `zk linkcheck`.
  • Loading branch information
popzxc committed Apr 5, 2024
1 parent 9e7db59 commit 4013771
Show file tree
Hide file tree
Showing 40 changed files with 165 additions and 96 deletions.
32 changes: 32 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Expand Up @@ -213,3 +213,8 @@ zksync_types = { path = "core/lib/types" }
zksync_utils = { path = "core/lib/utils" }
zksync_web3_decl = { path = "core/lib/web3_decl" }
zksync_crypto_primitives = { path = "core/lib/crypto_primitives" }

# Framework and components
zksync_node_framework = { path = "core/node/node_framework" }
zksync_eth_watch = { path = "core/node/eth_watch" }
zksync_shared_metrics = { path = "core/node/shared_metrics" }
2 changes: 2 additions & 0 deletions core/lib/zksync_core/Cargo.toml
Expand Up @@ -42,6 +42,8 @@ zksync_web3_decl = { workspace = true, features = [
zksync_object_store.workspace = true
zksync_health_check.workspace = true
vlog.workspace = true
zksync_eth_watch.workspace = true
zksync_shared_metrics.workspace = true

multivm.workspace = true

Expand Down
Expand Up @@ -2,6 +2,7 @@ use std::time::Duration;

use multivm::interface::{VmExecutionResultAndLogs, VmMemoryMetrics};
use vise::{Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics};
use zksync_shared_metrics::InteractionType;
use zksync_state::StorageViewMetrics;
use zksync_types::{
event::{extract_long_l2_to_l1_messages, extract_published_bytecodes},
Expand All @@ -10,8 +11,6 @@ use zksync_types::{
};
use zksync_utils::bytecode::bytecode_len_in_bytes;

use crate::metrics::InteractionType;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)]
#[metrics(label = "type", rename_all = "snake_case")]
enum SizeType {
Expand Down
Expand Up @@ -2,13 +2,11 @@ use std::collections::hash_map::{Entry, HashMap};

use tokio::sync::Mutex;
use zksync_dal::{transactions_dal::L2TxSubmissionResult, ConnectionPool, Core, CoreDal};
use zksync_shared_metrics::{TxStage, APP_METRICS};
use zksync_types::{fee::TransactionExecutionMetrics, l2::L2Tx, Address, Nonce, H256};

use super::{tx_sink::TxSink, SubmitTxError};
use crate::{
api_server::web3::metrics::API_METRICS,
metrics::{TxStage, APP_METRICS},
};
use crate::api_server::web3::metrics::API_METRICS;

/// Wrapper for the master DB pool that allows to submit transactions to the mempool.
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion core/lib/zksync_core/src/api_server/tx_sender/proxy.rs
Expand Up @@ -7,6 +7,7 @@ use std::{

use tokio::sync::{watch, RwLock};
use zksync_dal::{transactions_dal::L2TxSubmissionResult, ConnectionPool, Core, CoreDal};
use zksync_shared_metrics::{TxStage, APP_METRICS};
use zksync_types::{
api::{BlockId, Transaction, TransactionDetails, TransactionId},
fee::TransactionExecutionMetrics,
Expand All @@ -20,7 +21,6 @@ use zksync_web3_decl::{
};

use super::{tx_sink::TxSink, SubmitTxError};
use crate::metrics::{TxStage, APP_METRICS};

#[derive(Debug, Clone, Default)]
pub(crate) struct TxCache {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/zksync_core/src/consistency_checker/mod.rs
Expand Up @@ -8,6 +8,7 @@ use zksync_dal::{Connection, ConnectionPool, Core, CoreDal};
use zksync_eth_client::{CallFunctionArgs, Error as L1ClientError, EthInterface};
use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck};
use zksync_l1_contract_interface::i_executor::commit::kzg::ZK_SYNC_BYTES_PER_BLOB;
use zksync_shared_metrics::{CheckerComponent, EN_METRICS};
use zksync_types::{
commitment::L1BatchWithMetadata,
ethabi::Token,
Expand All @@ -18,7 +19,6 @@ use zksync_types::{

use crate::{
eth_sender::l1_batch_commit_data_generator::L1BatchCommitDataGenerator,
metrics::{CheckerComponent, EN_METRICS},
utils::wait_for_l1_batch_with_metadata,
};

Expand Down
2 changes: 1 addition & 1 deletion core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs
Expand Up @@ -10,6 +10,7 @@ use zksync_l1_contract_interface::{
multicall3::{Multicall3Call, Multicall3Result},
Detokenize, Tokenizable, Tokenize,
};
use zksync_shared_metrics::BlockL1Stage;
use zksync_types::{
aggregated_operations::AggregatedActionType,
commitment::SerializeCommitment,
Expand All @@ -31,7 +32,6 @@ use crate::{
Aggregator, ETHSenderError,
},
gas_tracker::agg_l1_batch_base_cost,
metrics::BlockL1Stage,
};

/// Data queried from L1 using multicall contract.
Expand Down
3 changes: 2 additions & 1 deletion core/lib/zksync_core/src/eth_sender/eth_tx_manager.rs
Expand Up @@ -8,6 +8,7 @@ use zksync_eth_client::{
encode_blob_tx_with_sidecar, BoundEthInterface, Error, EthInterface, ExecutedTxStatus, Options,
RawTransactionBytes, SignedCallResult,
};
use zksync_shared_metrics::BlockL1Stage;
use zksync_types::{
aggregated_operations::AggregatedActionType,
eth_sender::{EthTx, EthTxBlobSidecar},
Expand All @@ -20,7 +21,7 @@ use zksync_types::{
use zksync_utils::time::seconds_since_epoch;

use super::{metrics::METRICS, ETHSenderError};
use crate::{l1_gas_price::L1TxParamsProvider, metrics::BlockL1Stage};
use crate::l1_gas_price::L1TxParamsProvider;

#[derive(Debug)]
struct EthFee {
Expand Down
6 changes: 2 additions & 4 deletions core/lib/zksync_core/src/eth_sender/metrics.rs
Expand Up @@ -4,13 +4,11 @@ use std::{fmt, time::Duration};

use vise::{Buckets, Counter, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, Metrics};
use zksync_dal::{Connection, Core, CoreDal};
use zksync_shared_metrics::{BlockL1Stage, BlockStage, APP_METRICS};
use zksync_types::{aggregated_operations::AggregatedActionType, eth_sender::EthTx};
use zksync_utils::time::seconds_since_epoch;

use crate::{
eth_sender::eth_tx_manager::L1BlockNumbers,
metrics::{BlockL1Stage, BlockStage, APP_METRICS},
};
use crate::eth_sender::eth_tx_manager::L1BlockNumbers;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelSet, EncodeLabelValue)]
#[metrics(label = "kind", rename_all = "snake_case")]
Expand Down
@@ -1,11 +1,9 @@
use async_trait::async_trait;
use zksync_dal::{ConnectionPool, Core, CoreDal};
use zksync_shared_metrics::{BlockL1Stage, BlockStage, L1StageLatencyLabel, APP_METRICS};
use zksync_utils::time::seconds_since_epoch;

use crate::{
house_keeper::periodic_job::PeriodicJob,
metrics::{BlockL1Stage, BlockStage, L1StageLatencyLabel, APP_METRICS},
};
use crate::house_keeper::periodic_job::PeriodicJob;

#[derive(Debug)]
pub struct L1BatchMetricsReporter {
Expand Down
@@ -1,7 +1,7 @@
use prover_dal::{Prover, ProverDal};
use zksync_db_connection::connection_pool::ConnectionPool;

use crate::{house_keeper::periodic_job::PeriodicJob, metrics::HOUSE_KEEPER_METRICS};
use crate::house_keeper::{metrics::HOUSE_KEEPER_METRICS, periodic_job::PeriodicJob};

/// FriGpuProverArchiver is a task that periodically archives old fri GPU prover records.
/// The task will archive the `dead` prover records that have not been updated for a certain amount of time.
Expand Down
@@ -1,7 +1,7 @@
use prover_dal::{Prover, ProverDal};
use zksync_db_connection::connection_pool::ConnectionPool;

use crate::{house_keeper::periodic_job::PeriodicJob, metrics::HOUSE_KEEPER_METRICS};
use crate::house_keeper::{metrics::HOUSE_KEEPER_METRICS, periodic_job::PeriodicJob};

#[derive(Debug)]
pub struct FriProverJobArchiver {
Expand Down
11 changes: 11 additions & 0 deletions core/lib/zksync_core/src/house_keeper/metrics.rs
@@ -0,0 +1,11 @@
use vise::{Counter, Metrics};

#[derive(Debug, Metrics)]
#[metrics(prefix = "house_keeper")]
pub(crate) struct HouseKeeperMetrics {
pub prover_job_archived: Counter,
pub gpu_prover_archived: Counter,
}

#[vise::register]
pub(crate) static HOUSE_KEEPER_METRICS: vise::Global<HouseKeeperMetrics> = vise::Global::new();
1 change: 1 addition & 0 deletions core/lib/zksync_core/src/house_keeper/mod.rs
Expand Up @@ -8,5 +8,6 @@ pub mod fri_prover_queue_monitor;
pub mod fri_scheduler_circuit_queuer;
pub mod fri_witness_generator_jobs_retry_manager;
pub mod fri_witness_generator_queue_monitor;
mod metrics;
pub mod periodic_job;
pub mod waiting_to_queued_fri_witness_job_mover;
6 changes: 2 additions & 4 deletions core/lib/zksync_core/src/lib.rs
Expand Up @@ -43,9 +43,11 @@ use zksync_eth_client::{
clients::{PKSigningClient, QueryClient},
BoundEthInterface,
};
use zksync_eth_watch::start_eth_watch;
use zksync_health_check::{AppHealthCheck, HealthStatus, ReactiveHealthCheck};
use zksync_object_store::{ObjectStore, ObjectStoreFactory};
use zksync_queued_job_processor::JobProcessor;
use zksync_shared_metrics::{InitStage, APP_METRICS};
use zksync_state::PostgresStorageCaches;
use zksync_types::{fee_model::FeeModelConfig, L2ChainId};

Expand All @@ -67,7 +69,6 @@ use crate::{
},
Aggregator, EthTxAggregator, EthTxManager,
},
eth_watch::start_eth_watch,
genesis::GenesisParams,
house_keeper::{
blocks_state_reporter::L1BatchMetricsReporter,
Expand All @@ -87,7 +88,6 @@ use crate::{
GasAdjusterSingleton, PubdataPricing, RollupPubdataPricing, ValidiumPubdataPricing,
},
metadata_calculator::{MetadataCalculator, MetadataCalculatorConfig},
metrics::{InitStage, APP_METRICS},
state_keeper::{
create_state_keeper, MempoolFetcher, MempoolGuard, OutputHandler, SequencerSealer,
StateKeeperPersistence,
Expand All @@ -102,14 +102,12 @@ pub mod commitment_generator;
pub mod consensus;
pub mod consistency_checker;
pub mod eth_sender;
pub mod eth_watch;
pub mod fee_model;
pub mod gas_tracker;
pub mod genesis;
pub mod house_keeper;
pub mod l1_gas_price;
pub mod metadata_calculator;
mod metrics;
pub mod proof_data_handler;
pub mod proto;
pub mod reorg_detector;
Expand Down
2 changes: 1 addition & 1 deletion core/lib/zksync_core/src/metadata_calculator/metrics.rs
Expand Up @@ -6,11 +6,11 @@ use vise::{
Buckets, EncodeLabelSet, EncodeLabelValue, Family, Gauge, Histogram, LatencyObserver, Metrics,
Unit,
};
use zksync_shared_metrics::{BlockStage, APP_METRICS};
use zksync_types::block::L1BatchHeader;
use zksync_utils::time::seconds_since_epoch;

use super::MetadataCalculator;
use crate::metrics::{BlockStage, APP_METRICS};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)]
#[metrics(label = "stage", rename_all = "snake_case")]
Expand Down
6 changes: 2 additions & 4 deletions core/lib/zksync_core/src/reorg_detector/mod.rs
Expand Up @@ -5,17 +5,15 @@ use async_trait::async_trait;
use tokio::sync::watch;
use zksync_dal::{ConnectionPool, Core, CoreDal, DalError};
use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck};
use zksync_shared_metrics::{CheckerComponent, EN_METRICS};
use zksync_types::{L1BatchNumber, MiniblockNumber, H256};
use zksync_web3_decl::{
client::L2Client,
error::{ClientRpcContext, EnrichedClientError, EnrichedClientResult},
namespaces::{EthNamespaceClient, ZksNamespaceClient},
};

use crate::{
metrics::{CheckerComponent, EN_METRICS},
utils::binary_search_with,
};
use crate::utils::binary_search_with;

#[cfg(test)]
mod tests;
Expand Down
Expand Up @@ -15,18 +15,16 @@ use tokio::{
runtime::Handle,
sync::{mpsc, watch},
};
use zksync_shared_metrics::{InteractionType, TxStage, APP_METRICS};
use zksync_state::{ReadStorage, StorageView, WriteStorage};
use zksync_types::{vm_trace::Call, Transaction};
use zksync_utils::bytecode::CompressedBytecodeInfo;

use super::{BatchExecutor, BatchExecutorHandle, Command, TxExecutionResult};
use crate::{
metrics::{InteractionType, TxStage, APP_METRICS},
state_keeper::{
metrics::{TxExecutionStage, BATCH_TIP_METRICS, EXECUTOR_METRICS, KEEPER_METRICS},
state_keeper_storage::ReadStorageFactory,
types::ExecutionMetricsForCriteria,
},
use crate::state_keeper::{
metrics::{TxExecutionStage, BATCH_TIP_METRICS, EXECUTOR_METRICS, KEEPER_METRICS},
state_keeper_storage::ReadStorageFactory,
types::ExecutionMetricsForCriteria,
};

/// The default implementation of [`BatchExecutor`].
Expand Down
12 changes: 5 additions & 7 deletions core/lib/zksync_core/src/state_keeper/io/persistence.rs
Expand Up @@ -5,15 +5,13 @@ use std::time::Instant;
use async_trait::async_trait;
use tokio::sync::{mpsc, oneshot};
use zksync_dal::{ConnectionPool, Core};
use zksync_shared_metrics::{BlockStage, APP_METRICS};
use zksync_types::Address;

use crate::{
metrics::{BlockStage, APP_METRICS},
state_keeper::{
io::StateKeeperOutputHandler,
metrics::{MiniblockQueueStage, MINIBLOCK_METRICS},
updates::{MiniblockSealCommand, UpdatesManager},
},
use crate::state_keeper::{
io::StateKeeperOutputHandler,
metrics::{MiniblockQueueStage, MINIBLOCK_METRICS},
updates::{MiniblockSealCommand, UpdatesManager},
};

/// A command together with the return address allowing to track command processing completion.
Expand Down
14 changes: 6 additions & 8 deletions core/lib/zksync_core/src/state_keeper/io/seal_logic.rs
Expand Up @@ -6,6 +6,7 @@ use std::time::{Duration, Instant};
use itertools::Itertools;
use multivm::utils::{get_max_batch_gas_limit, get_max_gas_per_pubdata_byte};
use zksync_dal::{Connection, Core, CoreDal};
use zksync_shared_metrics::{BlockStage, MiniblockStage, APP_METRICS};
use zksync_types::{
block::{unpack_block_info, L1BatchHeader, MiniblockHeader},
event::{extract_added_tokens, extract_long_l2_to_l1_messages},
Expand All @@ -26,15 +27,12 @@ use zksync_types::{
};
use zksync_utils::{h256_to_u256, u256_to_h256};

use crate::{
metrics::{BlockStage, MiniblockStage, APP_METRICS},
state_keeper::{
metrics::{
L1BatchSealStage, MiniblockSealStage, TxExecutionType, KEEPER_METRICS,
L1_BATCH_METRICS, MINIBLOCK_METRICS,
},
updates::{MiniblockSealCommand, UpdatesManager},
use crate::state_keeper::{
metrics::{
L1BatchSealStage, MiniblockSealStage, TxExecutionType, KEEPER_METRICS, L1_BATCH_METRICS,
MINIBLOCK_METRICS,
},
updates::{MiniblockSealCommand, UpdatesManager},
};

impl UpdatesManager {
Expand Down

0 comments on commit 4013771

Please sign in to comment.