Skip to content

Commit 1045edc

Browse files
authored
feat(eth-proof-manager): Add proper metrics (#4439)
## What ❔ <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- The `Why` has to be clear to non-Matter Labs entities running their own ZK Chain --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Is this a breaking change? - [ ] Yes - [ ] No ## Operational changes <!-- Any config changes? Any new flags? Any changes to any scripts? --> <!-- Please add anything that non-Matter Labs entities running their own ZK Chain may need to know --> ## 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 `zkstack dev fmt` and `zkstack dev lint`.
1 parent 3d02076 commit 1045edc

File tree

9 files changed

+86
-22
lines changed

9 files changed

+86
-22
lines changed

core/node/eth_proof_manager/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use zksync_types::L2ChainId;
99
use crate::client::EthProofManagerClient;
1010

1111
mod client;
12+
mod metrics;
1213
pub mod node;
1314
mod sender;
1415
#[cfg(test)]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use vise::{Counter, EncodeLabelSet, EncodeLabelValue, Family, Metrics};
2+
3+
use crate::types::ProvingNetwork;
4+
5+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)]
6+
#[metrics(label = "tx_type", rename_all = "snake_case")]
7+
pub(super) enum TxType {
8+
ProofRequest,
9+
ValidationResult,
10+
}
11+
12+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)]
13+
#[metrics(label = "validation_result", rename_all = "snake_case")]
14+
pub(super) enum ValidationResult {
15+
Success,
16+
Failed,
17+
}
18+
19+
#[derive(Debug, Metrics)]
20+
#[metrics(prefix = "server_eth_proof_manager")]
21+
pub(super) struct EthProofManagerMetrics {
22+
pub failed_to_send_tx: Family<TxType, Counter>,
23+
pub validated_batches: Family<ValidationResult, Counter>,
24+
pub proven_batches: Family<ProvingNetwork, Counter>,
25+
pub acknowledged_batches: Family<ProvingNetwork, Counter>,
26+
pub fallbacked_batches: Counter<u64>,
27+
}
28+
29+
#[vise::register]
30+
pub(super) static METRICS: vise::Global<EthProofManagerMetrics> = vise::Global::new();

core/node/eth_proof_manager/src/sender/submit_proof_request.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use zksync_types::{L1BatchId, L1BatchNumber, L2ChainId};
1212

1313
use crate::{
1414
client::EthProofManagerClient,
15+
metrics::{TxType, METRICS},
1516
types::{ProofRequestIdentifier, ProofRequestParams},
1617
};
1718

@@ -80,6 +81,7 @@ impl ProofRequestSubmitter {
8081
batch_id,
8182
e
8283
);
84+
METRICS.fallbacked_batches.inc();
8385
self.connection_pool
8486
.connection()
8587
.await?
@@ -146,31 +148,36 @@ impl ProofRequestSubmitter {
146148
max_reward: self.config.max_reward,
147149
};
148150

149-
let tx_hash = self
151+
match self
150152
.client
151153
.submit_proof_request(proof_request_identifier, proof_request_parameters)
152154
.await
153-
.map_err(|e| {
154-
anyhow::anyhow!(
155+
{
156+
Ok(tx_hash) => {
157+
self.connection_pool
158+
.connection()
159+
.await?
160+
.eth_proof_manager_dal()
161+
.mark_batch_as_sent(batch_id, tx_hash)
162+
.await?;
163+
164+
tracing::info!(
165+
"Submitted proof request for batch {}, chain_id: {}, with tx hash {}",
166+
proof_generation_data.l1_batch_number,
167+
proof_generation_data.chain_id,
168+
tx_hash
169+
);
170+
}
171+
Err(e) => {
172+
METRICS.failed_to_send_tx[&TxType::ProofRequest].inc();
173+
return Err(anyhow::anyhow!(
155174
"Failed to submit proof request for batch {}, error: {}",
156175
batch_id,
157176
e
158-
)
159-
})?;
160-
161-
self.connection_pool
162-
.connection()
163-
.await?
164-
.eth_proof_manager_dal()
165-
.mark_batch_as_sent(batch_id, tx_hash)
166-
.await?;
177+
));
178+
}
179+
}
167180

168-
tracing::info!(
169-
"Submitted proof request for batch {}, chain_id: {}, with tx hash {}",
170-
proof_generation_data.l1_batch_number,
171-
proof_generation_data.chain_id,
172-
tx_hash
173-
);
174181
Ok(())
175182
}
176183
}

core/node/eth_proof_manager/src/sender/submit_proof_validation.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ use tokio::sync::watch;
44
use zksync_dal::{ConnectionPool, Core, CoreDal};
55
use zksync_types::L2ChainId;
66

7-
use crate::{client::EthProofManagerClient, types::ProofRequestIdentifier};
7+
use crate::{
8+
client::EthProofManagerClient,
9+
metrics::{TxType, METRICS},
10+
types::ProofRequestIdentifier,
11+
};
812

913
pub struct SubmitProofValidationSubmitter {
1014
client: Box<dyn EthProofManagerClient>,
@@ -78,11 +82,17 @@ impl SubmitProofValidationSubmitter {
7882
return Ok(());
7983
}
8084
Err(e) => {
85+
METRICS.failed_to_send_tx[&TxType::ValidationResult].inc();
8186
tracing::error!(
8287
"Failed to submit proof validation for batch {}: {}",
8388
batch_number,
8489
e
8590
);
91+
return Err(anyhow::anyhow!(
92+
"Failed to submit proof validation for batch {}: {}",
93+
batch_number,
94+
e
95+
));
8696
}
8797
}
8898
}

core/node/eth_proof_manager/src/types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use bellman::bn256::Bn256;
22
use circuit_definitions::circuit_definitions::aux_layer::ZkSyncSnarkWrapperCircuitNoLookupCustomGate;
33
use fflonk::FflonkVerificationKey;
4+
use vise::{EncodeLabelSet, EncodeLabelValue};
45
use zksync_eth_client::{ContractCallError, EnrichedClientError, SigningError};
56
use zksync_types::{ethabi, U256};
67

7-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EncodeLabelValue, EncodeLabelSet)]
9+
#[metrics(label = "proving_network", rename_all = "snake_case")]
810
pub enum ProvingNetwork {
911
None = 0,
1012
Fermah = 1,

core/node/eth_proof_manager/src/watcher/events/proof_request_acknowledged.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use async_trait::async_trait;
33
use zksync_dal::{eth_watcher_dal::EventType, ConnectionPool, Core, CoreDal};
44
use zksync_types::{api::Log, ethabi, h256_to_u256, L1BatchNumber, H256, U256};
55

6-
use crate::{types::ProvingNetwork, watcher::events::EventHandler};
6+
use crate::{metrics::METRICS, types::ProvingNetwork, watcher::events::EventHandler};
77

88
//event ProofRequestAcknowledged(
99
// uint256 indexed chainId,
@@ -91,6 +91,8 @@ impl EventHandler for ProofRequestAcknowledgedHandler {
9191

9292
tracing::info!("Received ProofRequestAcknowledgedEvent: {:?}", event);
9393

94+
METRICS.acknowledged_batches[&event.assigned_to].inc();
95+
9496
if accepted {
9597
self.connection_pool
9698
.connection()
@@ -106,6 +108,7 @@ impl EventHandler for ProofRequestAcknowledgedHandler {
106108
"Proof request for batch {} not accepted, moving to prover cluster",
107109
event.block_number
108110
);
111+
METRICS.fallbacked_batches.inc();
109112
self.connection_pool
110113
.connection()
111114
.await?

core/node/eth_proof_manager/src/watcher/events/proof_request_proven.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use zksync_types::{
1818
};
1919

2020
use crate::{
21+
metrics::{ValidationResult, METRICS},
2122
types::{FflonkFinalVerificationKey, ProvingNetwork},
2223
watcher::events::EventHandler,
2324
};
@@ -153,6 +154,11 @@ impl EventHandler for ProofRequestProvenHandler {
153154
.proof_generation_dal()
154155
.save_proof_artifacts_metadata(batch_number, &proof_blob_url)
155156
.await?;
157+
158+
METRICS.validated_batches[&ValidationResult::Success].inc();
159+
METRICS.proven_batches[&event.assigned_to].inc();
160+
} else {
161+
METRICS.validated_batches[&ValidationResult::Failed].inc();
156162
}
157163

158164
tracing::info!(

core/node/proof_data_handler/src/metrics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use vise::{Histogram, Metrics};
1+
use vise::{Counter, Histogram, Metrics};
22
use zksync_object_store::bincode;
33
use zksync_prover_interface::inputs::WitnessInputData;
44

@@ -14,6 +14,7 @@ pub(super) struct ProofDataHandlerMetrics {
1414
pub eip_4844_blob_size_in_mb: Histogram<u64>,
1515
#[metrics(buckets = vise::Buckets::exponential(1.0..=2_048.0, 2.0))]
1616
pub total_blob_size_in_mb: Histogram<u64>,
17+
pub fallbacked_batches: Counter<u64>,
1718
}
1819

1920
impl ProofDataHandlerMetrics {

core/node/proof_data_handler/src/proof_router.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::time::Duration;
33
use tokio::sync::watch;
44
use zksync_dal::{ConnectionPool, Core, CoreDal};
55

6+
use crate::metrics::METRICS;
7+
68
pub struct ProofRouter {
79
connection_pool: ConnectionPool<Core>,
810
acknowledgment_timeout: Duration,
@@ -48,6 +50,8 @@ impl ProofRouter {
4850

4951
tracing::info!("Fallbacked {} batches with timeouts: acknowledgment timeout: {:?} and proving timeout: {:?}", amount, self.acknowledgment_timeout, self.proving_timeout);
5052

53+
METRICS.fallbacked_batches.inc_by(amount as u64);
54+
5155
tokio::time::sleep(Duration::from_secs(10)).await;
5256
}
5357
Ok(())

0 commit comments

Comments
 (0)