unc_client_primitives/
debug.rs

1//! Structs in this module are used for debug purposes, and might change at any time
2//! without backwards compatibility of JSON encoding.
3use crate::types::StatusError;
4use chrono::DateTime;
5use std::collections::HashMap;
6use unc_primitives::types::EpochId;
7use unc_primitives::views::{
8    CatchupStatusView, ChainProcessingInfo, EpochValidatorInfo, RequestedStatePartsView,
9    SyncStatusView,
10};
11use unc_primitives::{
12    block_header::ApprovalInner,
13    hash::CryptoHash,
14    sharding::ChunkHash,
15    types::{AccountId, BlockHeight},
16    views::ValidatorInfo,
17};
18
19#[derive(serde::Serialize, serde::Deserialize, Debug)]
20pub struct TrackedShardsView {
21    pub shards_tracked_this_epoch: Vec<bool>,
22    pub shards_tracked_next_epoch: Vec<bool>,
23}
24
25#[derive(serde::Serialize, serde::Deserialize, Debug)]
26pub struct EpochInfoView {
27    pub epoch_id: CryptoHash,
28    pub height: BlockHeight,
29    pub first_block: Option<(CryptoHash, DateTime<chrono::Utc>)>,
30    pub block_producers: Vec<ValidatorInfo>,
31    pub chunk_only_producers: Vec<String>,
32    pub validator_info: Option<EpochValidatorInfo>,
33    pub protocol_version: u32,
34    pub shards_size_and_parts: Vec<(u64, u64, bool)>,
35}
36
37#[derive(serde::Serialize, serde::Deserialize, Debug)]
38pub struct DebugChunkStatus {
39    pub shard_id: u64,
40    pub chunk_hash: ChunkHash,
41    pub chunk_producer: Option<AccountId>,
42    pub gas_used: u64,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub processing_time_ms: Option<u64>,
45}
46
47#[derive(serde::Serialize, serde::Deserialize, Debug)]
48pub struct DebugBlockStatus {
49    pub block_hash: CryptoHash,
50    pub prev_block_hash: CryptoHash,
51    pub block_height: u64,
52    pub block_timestamp: u64,
53    pub block_producer: Option<AccountId>,
54    pub full_block_missing: bool, // only header available
55    pub is_on_canonical_chain: bool,
56    pub chunks: Vec<DebugChunkStatus>,
57    // Time that was spent processing a given block.
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub processing_time_ms: Option<u64>,
60    pub gas_price_ratio: f64,
61}
62
63#[derive(serde::Serialize, serde::Deserialize, Debug)]
64pub struct MissedHeightInfo {
65    pub block_height: u64,
66    pub block_producer: Option<AccountId>,
67}
68
69#[derive(serde::Serialize, serde::Deserialize, Debug)]
70pub struct DebugBlockStatusData {
71    pub blocks: Vec<DebugBlockStatus>,
72    pub missed_heights: Vec<MissedHeightInfo>,
73    pub head: CryptoHash,
74    pub header_head: CryptoHash,
75}
76
77// Information about the approval created by this node.
78// Used for debug purposes only.
79#[derive(serde::Serialize, Debug, Clone)]
80pub struct ApprovalHistoryEntry {
81    // If target_height == base_height + 1  - this is endorsement.
82    // Otherwise this is a skip.
83    pub parent_height: BlockHeight,
84    pub target_height: BlockHeight,
85    // Time when we actually created the approval and sent it out.
86    pub approval_creation_time: DateTime<chrono::Utc>,
87    // The moment when we were ready to send this approval (or skip)
88    pub timer_started_ago_millis: u64,
89    // But we had to wait at least this long before doing it.
90    pub expected_delay_millis: u64,
91}
92
93// Information about chunk produced by this node.
94// For debug purposes only.
95#[derive(serde::Serialize, Debug, Default, Clone)]
96pub struct ChunkProduction {
97    // Time when we produced the chunk.
98    pub chunk_production_time: Option<DateTime<chrono::Utc>>,
99    // How long did the chunk production take (reed solomon encoding, preparing fragments etc.)
100    // Doesn't include network latency.
101    pub chunk_production_duration_millis: Option<u64>,
102}
103// Information about the block produced by this node.
104// For debug purposes only.
105#[derive(serde::Serialize, Debug, Clone, Default)]
106pub struct BlockProduction {
107    // Approvals that we received.
108    pub approvals: ApprovalAtHeightStatus,
109    // Chunk producer and time at which we received chunk for given shard. This field will not be
110    // set if we didn't produce the block.
111    pub chunks_collection_time: Vec<ChunkCollection>,
112    // Time when we produced the block, None if we didn't produce the block.
113    pub block_production_time: Option<DateTime<chrono::Utc>>,
114    // Whether this block is included on the canonical chain.
115    pub block_included: bool,
116}
117
118#[derive(serde::Serialize, Debug, Clone)]
119pub struct ChunkCollection {
120    // Chunk producer of the chunk
121    pub chunk_producer: AccountId,
122    // Time when the chunk was received. Note that this field can be filled even if the block doesn't
123    // include a chunk for the shard, if a chunk at this height was received after the block was produced.
124    pub received_time: Option<DateTime<chrono::Utc>>,
125    // Whether the block included a chunk for this shard
126    pub chunk_included: bool,
127}
128
129// Information about things related to block/chunk production
130// at given height.
131// For debug purposes only.
132#[derive(serde::Serialize, Debug, Default)]
133pub struct ProductionAtHeight {
134    // Stores information about block production is we are responsible for producing this block,
135    // None if we are not responsible for producing this block.
136    pub block_production: Option<BlockProduction>,
137    // Map from shard_id to chunk that we are responsible to produce at this height
138    pub chunk_production: HashMap<u64, ChunkProduction>,
139}
140
141// Infromation about the approvals that we received.
142#[derive(serde::Serialize, Debug, Default, Clone)]
143pub struct ApprovalAtHeightStatus {
144    // Map from validator id to the type of approval that they sent and timestamp.
145    pub approvals: HashMap<AccountId, (ApprovalInner, DateTime<chrono::Utc>)>,
146    // Time at which we received 2/3 approvals (doomslug threshold).
147    pub ready_at: Option<DateTime<chrono::Utc>>,
148}
149
150#[derive(serde::Serialize, Debug)]
151pub struct ValidatorStatus {
152    pub validator_name: Option<AccountId>,
153    // Current number of shards
154    pub shards: u64,
155    // Current height.
156    pub head_height: u64,
157    // Current validators with their pledge (pledge is in UNC - not attounc).
158    pub validators: Option<Vec<(AccountId, u64)>>,
159    // All approvals that we've sent.
160    pub approval_history: Vec<ApprovalHistoryEntry>,
161    // Blocks & chunks that we've produced or about to produce.
162    // Sorted by block height inversely (high to low)
163    // The range of heights are controlled by constants in client_actor.rs
164    pub production: Vec<(BlockHeight, ProductionAtHeight)>,
165    // Chunk producers that this node has banned.
166    pub banned_chunk_producers: Vec<(EpochId, Vec<AccountId>)>,
167}
168
169// Different debug requests that can be sent by HTML pages, via GET.
170#[derive(Debug)]
171pub enum DebugStatus {
172    // Request for the current sync status
173    SyncStatus,
174    // Request currently tracked shards
175    TrackedShards,
176    // Detailed information about last couple epochs.
177    EpochInfo,
178    // Detailed information about last couple blocks.
179    BlockStatus(Option<BlockHeight>),
180    // Consensus related information.
181    ValidatorStatus,
182    // Request for the current catchup status
183    CatchupStatus,
184    // Request for the current state of chain processing (blocks in progress etc).
185    ChainProcessingStatus,
186    // The state parts already requested.
187    RequestedStateParts,
188}
189
190impl actix::Message for DebugStatus {
191    type Result = Result<DebugStatusResponse, StatusError>;
192}
193
194#[derive(serde::Serialize, Debug)]
195pub enum DebugStatusResponse {
196    SyncStatus(SyncStatusView),
197    CatchupStatus(Vec<CatchupStatusView>),
198    TrackedShards(TrackedShardsView),
199    // List of epochs - in descending order (next epoch is first).
200    EpochInfo(Vec<EpochInfoView>),
201    // Detailed information about blocks.
202    BlockStatus(DebugBlockStatusData),
203    // Detailed information about the validator (approvals, block & chunk production etc.)
204    ValidatorStatus(ValidatorStatus),
205    // Detailed information about chain processing (blocks in progress etc).
206    ChainProcessingStatus(ChainProcessingInfo),
207    // The state parts already requested.
208    RequestedStateParts(Vec<RequestedStatePartsView>),
209}