near_jsonrpc_primitives/types/
status.rs

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