Skip to content

Commit

Permalink
refactor(papyrus_sync): update metrics tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonLStarkWare committed Feb 11, 2025
1 parent 004f4f7 commit 335500b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
7 changes: 2 additions & 5 deletions crates/papyrus_p2p_sync/src/client/header.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use chrono::{TimeZone, Utc};
use futures::future::BoxFuture;
use futures::{FutureExt, StreamExt};
use metrics::gauge;
use papyrus_network::network_manager::ClientResponsesManager;
use papyrus_protobuf::sync::{DataOrFin, SignedBlockHeader};
use papyrus_storage::header::{HeaderStorageReader, HeaderStorageWriter};
Expand Down Expand Up @@ -50,8 +49,7 @@ impl BlockData for SignedBlockHeader {
.expect("Vec::first should return a value on a vector of size 1"),
)?
.commit()?;
// TODO(alonl): fix this metric
gauge!(PAPYRUS_HEADER_MARKER.get_name()).set(
PAPYRUS_HEADER_MARKER.set(
self.block_header.block_header_without_hash.block_number.unchecked_next().0 as f64,
);
// TODO(shahak): Fix code dup with central sync
Expand All @@ -66,8 +64,7 @@ impl BlockData for SignedBlockHeader {
let header_latency = time_delta.num_seconds();
debug!("Header latency: {}.", header_latency);
if header_latency >= 0 {
// TODO(alonl): fix this metric
gauge!(PAPYRUS_HEADER_LATENCY_SEC.get_name()).set(header_latency as f64);
PAPYRUS_HEADER_LATENCY_SEC.set(header_latency as f64);
}
Ok(())
}
Expand Down
4 changes: 1 addition & 3 deletions crates/papyrus_p2p_sync/src/client/state_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashSet;

use futures::future::BoxFuture;
use futures::{FutureExt, StreamExt};
use metrics::gauge;
use papyrus_network::network_manager::ClientResponsesManager;
use papyrus_proc_macros::latency_histogram;
use papyrus_protobuf::sync::{DataOrFin, StateDiffChunk};
Expand Down Expand Up @@ -34,8 +33,7 @@ impl BlockData for (ThinStateDiff, BlockNumber) {
) -> BoxFuture<'a, Result<(), P2pSyncClientError>> {
async move {
storage_writer.begin_rw_txn()?.append_state_diff(self.1, self.0)?.commit()?;
// TODO(alonl): fix this metric
gauge!(PAPYRUS_STATE_MARKER.get_name()).set(self.1.unchecked_next().0 as f64);
PAPYRUS_STATE_MARKER.set(self.1.unchecked_next().0 as f64);
Ok(())
}
.boxed()
Expand Down
4 changes: 4 additions & 0 deletions crates/papyrus_sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ starknet_class_manager_types = { path = "../starknet_class_manager_types", featu
starknet_client = { path = "../starknet_client", features = ["testing"] }
tokio-stream.workspace = true

[package.metadata.cargo-machete]
# `metrics` is used in `latency_histogram` but is falsely detected as unused.
ignored = ["metrics"]

[lints]
workspace = true
21 changes: 8 additions & 13 deletions crates/papyrus_sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,8 @@ impl<
.append_block_signature(block_number, signature)?
.append_body(block_number, block.body)?
.commit()?;
metrics::gauge!(PAPYRUS_HEADER_MARKER.get_name())
.set(block_number.unchecked_next().0 as f64);
metrics::gauge!(PAPYRUS_BODY_MARKER.get_name()).set(block_number.unchecked_next().0 as f64);
PAPYRUS_HEADER_MARKER.set(block_number.unchecked_next().0 as f64);
PAPYRUS_BODY_MARKER.set(block_number.unchecked_next().0 as f64);
let time_delta = Utc::now()
- Utc
.timestamp_opt(block.header.block_header_without_hash.timestamp.0 as i64, 0)
Expand All @@ -457,7 +456,7 @@ impl<
let header_latency = time_delta.num_seconds();
debug!("Header latency: {}.", header_latency);
if header_latency >= 0 {
metrics::gauge!(PAPYRUS_HEADER_LATENCY_SEC.get_name()).set(header_latency as f64);
PAPYRUS_HEADER_LATENCY_SEC.set(header_latency as f64);
}
Ok(())
}
Expand Down Expand Up @@ -511,11 +510,9 @@ impl<
.update_class_manager_block_marker(&block_number)?
.commit()?;
}
metrics::gauge!(PAPYRUS_STATE_MARKER.get_name())
.set(block_number.unchecked_next().0 as f64);
let compiled_class_marker = self.reader.begin_ro_txn()?.get_compiled_class_marker()?;
metrics::gauge!(PAPYRUS_COMPILED_CLASS_MARKER.get_name())
.set(compiled_class_marker.0 as f64);
PAPYRUS_STATE_MARKER.set(block_number.unchecked_next().0 as f64);
PAPYRUS_COMPILED_CLASS_MARKER.set(compiled_class_marker.0 as f64);

// Info the user on syncing the block once all the data is stored.
info!("Added block {} with hash {:#064x}.", block_number, block_hash.0);
Expand All @@ -539,8 +536,7 @@ impl<
txn.commit()?;
let compiled_class_marker =
self.reader.begin_ro_txn()?.get_compiled_class_marker()?;
metrics::gauge!(PAPYRUS_COMPILED_CLASS_MARKER.get_name())
.set(compiled_class_marker.0 as f64);
PAPYRUS_COMPILED_CLASS_MARKER.set(compiled_class_marker.0 as f64);
debug!("Added compiled class.");
Ok(())
}
Expand Down Expand Up @@ -582,8 +578,7 @@ impl<
if txn.get_base_layer_block_marker()? != block_number.unchecked_next() {
info!("Verified block {block_number} hash against base layer.");
txn.update_base_layer_block_marker(&block_number.unchecked_next())?.commit()?;
metrics::gauge!(PAPYRUS_BASE_LAYER_MARKER.get_name())
.set(block_number.unchecked_next().0 as f64);
PAPYRUS_BASE_LAYER_MARKER.set(block_number.unchecked_next().0 as f64);
}
Ok(())
}
Expand Down Expand Up @@ -717,7 +712,7 @@ fn stream_new_blocks<
let central_block_marker = latest_central_block.map_or(
BlockNumber::default(), |block_hash_and_number| block_hash_and_number.number.unchecked_next()
);
metrics::gauge!(PAPYRUS_CENTRAL_BLOCK_MARKER.get_name()).set(central_block_marker.0 as f64);
PAPYRUS_CENTRAL_BLOCK_MARKER.set(central_block_marker.0 as f64);
if header_marker == central_block_marker {
// Only if the node have the last block and state (without casms), sync pending data.
if collect_pending_data && reader.begin_ro_txn()?.get_state_marker()? == header_marker{
Expand Down

0 comments on commit 335500b

Please sign in to comment.