reth_optimism_txpool/supervisor/
metrics.rs

1//! Optimism supervisor and sequencer metrics
2
3use crate::supervisor::InteropTxValidatorError;
4use op_alloy_rpc_types::SuperchainDAError;
5use reth_metrics::{
6    metrics::{Counter, Histogram},
7    Metrics,
8};
9use std::time::Duration;
10
11/// Optimism supervisor metrics
12#[derive(Metrics, Clone)]
13#[metrics(scope = "optimism_transaction_pool.supervisor")]
14pub struct SupervisorMetrics {
15    /// How long it takes to query the supervisor in the Optimism transaction pool
16    pub(crate) supervisor_query_latency: Histogram,
17
18    /// Counter for the number of times data was skipped
19    pub(crate) skipped_data_count: Counter,
20    /// Counter for the number of times an unknown chain was encountered
21    pub(crate) unknown_chain_count: Counter,
22    /// Counter for the number of times conflicting data was encountered
23    pub(crate) conflicting_data_count: Counter,
24    /// Counter for the number of times ineffective data was encountered
25    pub(crate) ineffective_data_count: Counter,
26    /// Counter for the number of times data was out of order
27    pub(crate) out_of_order_count: Counter,
28    /// Counter for the number of times data was awaiting replacement
29    pub(crate) awaiting_replacement_count: Counter,
30    /// Counter for the number of times data was out of scope
31    pub(crate) out_of_scope_count: Counter,
32    /// Counter for the number of times there was no parent for the first block
33    pub(crate) no_parent_for_first_block_count: Counter,
34    /// Counter for the number of times future data was encountered
35    pub(crate) future_data_count: Counter,
36    /// Counter for the number of times data was missed
37    pub(crate) missed_data_count: Counter,
38    /// Counter for the number of times data corruption was encountered
39    pub(crate) data_corruption_count: Counter,
40}
41
42impl SupervisorMetrics {
43    /// Records the duration of supervisor queries
44    #[inline]
45    pub fn record_supervisor_query(&self, duration: Duration) {
46        self.supervisor_query_latency.record(duration.as_secs_f64());
47    }
48
49    /// Increments the metrics for the given error
50    pub fn increment_metrics_for_error(&self, error: &InteropTxValidatorError) {
51        if let InteropTxValidatorError::InvalidEntry(inner) = error {
52            match inner {
53                SuperchainDAError::SkippedData => self.skipped_data_count.increment(1),
54                SuperchainDAError::UnknownChain => self.unknown_chain_count.increment(1),
55                SuperchainDAError::ConflictingData => self.conflicting_data_count.increment(1),
56                SuperchainDAError::IneffectiveData => self.ineffective_data_count.increment(1),
57                SuperchainDAError::OutOfOrder => self.out_of_order_count.increment(1),
58                SuperchainDAError::AwaitingReplacement => {
59                    self.awaiting_replacement_count.increment(1)
60                }
61                SuperchainDAError::OutOfScope => self.out_of_scope_count.increment(1),
62                SuperchainDAError::NoParentForFirstBlock => {
63                    self.no_parent_for_first_block_count.increment(1)
64                }
65                SuperchainDAError::FutureData => self.future_data_count.increment(1),
66                SuperchainDAError::MissedData => self.missed_data_count.increment(1),
67                SuperchainDAError::DataCorruption => self.data_corruption_count.increment(1),
68                _ => {}
69            }
70        }
71    }
72}
73
74/// Optimism sequencer metrics
75#[derive(Metrics, Clone)]
76#[metrics(scope = "optimism_transaction_pool.sequencer")]
77pub struct SequencerMetrics {
78    /// How long it takes to forward a transaction to the sequencer
79    pub(crate) sequencer_forward_latency: Histogram,
80}
81
82impl SequencerMetrics {
83    /// Records the duration it took to forward a transaction
84    #[inline]
85    pub fn record_forward_latency(&self, duration: Duration) {
86        self.sequencer_forward_latency.record(duration.as_secs_f64());
87    }
88}