unc_jsonrpc_primitives/types/
status.rs

1#[cfg(feature = "debug_types")]
2use unc_client_primitives::debug::{
3    DebugBlockStatusData, EpochInfoView, TrackedShardsView, ValidatorStatus,
4};
5#[cfg(feature = "debug_types")]
6use unc_primitives::views::{
7    CatchupStatusView, ChainProcessingInfo, NetworkGraphView, NetworkRoutesView, PeerStoreView,
8    RecentOutboundConnectionsView, RequestedStatePartsView, SnapshotHostsView,
9    SplitStorageInfoView, SyncStatusView,
10};
11
12#[derive(Debug, serde::Serialize, serde::Deserialize)]
13pub struct RpcStatusResponse {
14    #[serde(flatten)]
15    pub status_response: unc_primitives::views::StatusResponse,
16}
17
18#[cfg(feature = "debug_types")]
19#[derive(serde::Serialize, Debug)]
20pub enum DebugStatusResponse {
21    SyncStatus(SyncStatusView),
22    CatchupStatus(Vec<CatchupStatusView>),
23    TrackedShards(TrackedShardsView),
24    // List of epochs - in descending order (next epoch is first).
25    EpochInfo(Vec<EpochInfoView>),
26    // Detailed information about blocks.
27    BlockStatus(DebugBlockStatusData),
28    // Detailed information about the validator (approvals, block & chunk production etc.)
29    ValidatorStatus(ValidatorStatus),
30    PeerStore(PeerStoreView),
31    ChainProcessingStatus(ChainProcessingInfo),
32    // The state parts already requested.
33    RequestedStateParts(Vec<RequestedStatePartsView>),
34    NetworkGraph(NetworkGraphView),
35    RecentOutboundConnections(RecentOutboundConnectionsView),
36    Routes(NetworkRoutesView),
37    SnapshotHosts(SnapshotHostsView),
38    SplitStoreStatus(SplitStorageInfoView),
39}
40
41#[cfg(feature = "debug_types")]
42#[derive(Debug, serde::Serialize)]
43pub struct RpcDebugStatusResponse {
44    pub status_response: DebugStatusResponse,
45}
46
47#[derive(Debug, serde::Serialize, serde::Deserialize)]
48pub struct RpcHealthResponse;
49
50#[derive(thiserror::Error, Debug, serde::Serialize, serde::Deserialize)]
51#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
52pub enum RpcStatusError {
53    #[error("Node is syncing")]
54    NodeIsSyncing,
55    #[error("No blocks for {elapsed:?}")]
56    NoNewBlocks { elapsed: std::time::Duration },
57    #[error("Epoch Out Of Bounds {epoch_id:?}")]
58    EpochOutOfBounds { epoch_id: unc_primitives::types::EpochId },
59    #[error("The node reached its limits. Try again later. More details: {error_message}")]
60    InternalError { error_message: String },
61}
62
63impl From<RpcStatusError> for crate::errors::RpcError {
64    fn from(error: RpcStatusError) -> Self {
65        let error_data = match serde_json::to_value(error) {
66            Ok(value) => value,
67            Err(err) => {
68                return Self::new_internal_error(
69                    None,
70                    format!("Failed to serialize RpcStateChangesError: {:?}", err),
71                )
72            }
73        };
74        Self::new_internal_or_handler_error(Some(error_data.clone()), error_data)
75    }
76}