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    InstrumentedThreads(serde_json::Value), // Directly use the serialized form here to avoid dependency on near-async.
44}
45
46#[cfg(feature = "debug_types")]
47#[derive(Debug, serde::Serialize)]
48pub struct RpcDebugStatusResponse {
49    pub status_response: DebugStatusResponse,
50}
51
52#[derive(Debug, serde::Serialize, serde::Deserialize)]
53#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
54pub struct RpcHealthResponse;
55
56#[derive(thiserror::Error, Debug, Clone, serde::Serialize, serde::Deserialize)]
57#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
58#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
59pub enum RpcStatusError {
60    #[error("Node is syncing")]
61    NodeIsSyncing,
62    #[error("No blocks for {elapsed:?}")]
63    NoNewBlocks {
64        #[cfg_attr(feature = "schemars", schemars(with = "DurationSchemarsProvider"))]
65        elapsed: time::Duration,
66    },
67    #[error("Epoch Out Of Bounds {epoch_id:?}")]
68    EpochOutOfBounds { epoch_id: near_primitives::types::EpochId },
69    #[error("The node reached its limits. Try again later. More details: {error_message}")]
70    InternalError { error_message: String },
71}
72
73impl From<RpcStatusError> for crate::errors::RpcError {
74    fn from(error: RpcStatusError) -> Self {
75        let error_data = match serde_json::to_value(error) {
76            Ok(value) => value,
77            Err(err) => {
78                return Self::new_internal_error(
79                    None,
80                    format!("Failed to serialize RpcStateChangesError: {:?}", err),
81                );
82            }
83        };
84        Self::new_internal_or_handler_error(Some(error_data.clone()), error_data)
85    }
86}