hotshot_query_service/node/
query_data.rs

1// Copyright (c) 2022 Espresso Systems (espressosys.com)
2// This file is part of the HotShot Query Service library.
3//
4// This program is free software: you can redistribute it and/or modify it under the terms of the GNU
5// General Public License as published by the Free Software Foundation, either version 3 of the
6// License, or (at your option) any later version.
7// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9// General Public License for more details.
10// You should have received a copy of the GNU General Public License along with this program. If not,
11// see <https://www.gnu.org/licenses/>.
12
13use derivative::Derivative;
14use serde::{Deserialize, Serialize};
15
16pub use crate::availability::{BlockHash, BlockId};
17use crate::types::HeightIndexed;
18
19#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
20pub struct SyncStatus {
21    pub missing_blocks: usize,
22    pub missing_leaves: usize,
23    pub missing_vid_common: usize,
24    pub missing_vid_shares: usize,
25    pub pruned_height: Option<usize>,
26}
27
28impl SyncStatus {
29    pub fn fully_synced() -> Self {
30        Self {
31            missing_blocks: 0,
32            missing_leaves: 0,
33            missing_vid_common: 0,
34            missing_vid_shares: 0,
35            pruned_height: None,
36        }
37    }
38
39    pub fn is_fully_synced(&self) -> bool {
40        *self == Self::fully_synced()
41    }
42}
43
44/// Response to a `/:resource/window` query.
45#[derive(Clone, Debug, Derivative, PartialEq, Eq, Serialize, Deserialize)]
46#[derivative(Default(bound = ""))]
47pub struct TimeWindowQueryData<T> {
48    pub window: Vec<T>,
49    pub prev: Option<T>,
50    pub next: Option<T>,
51}
52
53impl<T: HeightIndexed> TimeWindowQueryData<T> {
54    /// The block height of the block that starts the window.
55    ///
56    /// If the window is empty, this is the height of the block that ends the window.
57    pub fn from(&self) -> Option<u64> {
58        self.window
59            .first()
60            .or(self.next.as_ref())
61            .map(|t| t.height())
62    }
63}
64
65#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
66pub struct Limits {
67    pub window_limit: usize,
68}