sui_core/validator_client_monitor/mod.rs
1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4mod metrics;
5mod monitor;
6mod stats;
7
8#[cfg(test)]
9mod tests;
10
11pub use metrics::ValidatorClientMetrics;
12pub use monitor::ValidatorClientMonitor;
13use std::time::Duration;
14use strum::EnumIter;
15use sui_types::{base_types::AuthorityName, messages_grpc::PingType};
16
17/// Operation types for validator performance tracking
18#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, EnumIter)]
19pub enum OperationType {
20 Submit,
21 Effects,
22 HealthCheck,
23 SingleWriterFinality,
24 SharedObjectFinality,
25}
26
27impl OperationType {
28 pub fn as_str(&self) -> &str {
29 match self {
30 OperationType::Submit => "submit",
31 OperationType::Effects => "effects",
32 OperationType::HealthCheck => "health_check",
33 OperationType::SingleWriterFinality => "single_writer_finality",
34 OperationType::SharedObjectFinality => "shared_object_finality",
35 }
36 }
37}
38
39/// Transaction class for latency tracking. Staggering holds can only ever delay
40/// unrestricted transactions, so the two classes keep separate latency windows:
41/// consumers on the restricted path (routing restricted transactions, choosing
42/// proposer sets) read stats that holds cannot pollute, while the unrestricted view
43/// reflects what unrestricted traffic actually experiences.
44#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
45pub enum TransactionClass {
46 /// The transaction names its allowed proposers.
47 Restricted,
48 /// The transaction does not restrict its proposers.
49 Unrestricted,
50}
51
52impl TransactionClass {
53 pub fn as_str(&self) -> &str {
54 match self {
55 TransactionClass::Restricted => "restricted",
56 TransactionClass::Unrestricted => "unrestricted",
57 }
58 }
59}
60
61/// Feedback from TransactionDriver operations
62#[derive(Debug, Clone)]
63pub struct OperationFeedback {
64 /// The unique authority name (public key)
65 pub authority_name: AuthorityName,
66 /// The human-readable display name for the validator
67 pub display_name: String,
68 /// The operation type
69 pub operation: OperationType,
70 /// The transaction class the observation belongs to; `None` (pings, health
71 /// checks, operations without the transaction at hand) counts toward both
72 /// classes.
73 pub tx_class: Option<TransactionClass>,
74 /// The ping type. If it's not a ping request, then this is None.
75 pub ping_type: Option<PingType>,
76 /// Result of the operation: Ok(latency) if successful, Err(()) if failed.
77 /// Only errors specific to the target validator should be recorded,
78 /// for example, timeout, unavailability or misbehavior from validators can be recorded.
79 /// But other errors unrelated to a specific validator, for example invalid user transaction,
80 /// should not be recorded.
81 pub result: Result<Duration, ()>,
82}