Skip to main content

espresso_types/v0/v0_1/
instance_state.rs

1use std::fmt::Debug;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{v0::utils::Timestamp, v0_3::ChainConfig};
6
7/// Represents the specific type of upgrade.
8#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
9#[serde(rename_all = "snake_case")]
10pub enum UpgradeType {
11    Fee { chain_config: ChainConfig },
12    Epoch { chain_config: ChainConfig },
13    DrbAndHeader { chain_config: ChainConfig },
14    NewProtocol { chain_config: ChainConfig },
15    EpochReward { chain_config: ChainConfig },
16    LargeBlock { chain_config: ChainConfig },
17}
18
19impl UpgradeType {
20    /// Get the upgrade data from `UpgradeType`. As of this writing,
21    /// we are only concerned w/ `ChainConfig`.
22    pub fn chain_config(&self) -> Option<ChainConfig> {
23        match self {
24            UpgradeType::Fee { chain_config } => Some(*chain_config),
25            UpgradeType::Epoch { chain_config } => Some(*chain_config),
26            UpgradeType::DrbAndHeader { chain_config } => Some(*chain_config),
27            UpgradeType::NewProtocol { chain_config } => Some(*chain_config),
28            UpgradeType::EpochReward { chain_config } => Some(*chain_config),
29            UpgradeType::LargeBlock { chain_config } => Some(*chain_config),
30        }
31    }
32}
33
34/// Represents an upgrade based on time (unix timestamp).
35#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
36pub struct TimeBasedUpgrade {
37    /// the earliest unix timestamp in which the node can propose an upgrade
38    pub start_proposing_time: Timestamp,
39    /// timestamp after which the node stops proposing an upgrade
40    pub stop_proposing_time: Timestamp,
41    /// The timestamp at which voting for the upgrade proposal starts
42    pub start_voting_time: Option<Timestamp>,
43    /// The timestamp at which voting for the upgrade proposal stops
44    pub stop_voting_time: Option<Timestamp>,
45}
46
47/// Represents an upgrade based on view.
48#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
49pub struct ViewBasedUpgrade {
50    /// the earliest view in which the node can propose an upgrade
51    pub start_proposing_view: u64,
52    /// view after which the node stops proposing an upgrade
53    pub stop_proposing_view: u64,
54    /// The view at which voting for the upgrade proposal starts
55    pub start_voting_view: Option<u64>,
56    /// The view at which voting for the upgrade proposal stops
57    pub stop_voting_view: Option<u64>,
58}
59
60/// Represents the specific type of upgrade.
61#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
62#[serde(untagged)]
63pub enum UpgradeMode {
64    /// Upgrade based on unix timestamp.
65    Time(TimeBasedUpgrade),
66    /// Upgrade based on view.
67    View(ViewBasedUpgrade),
68}
69
70/// Represents a general upgrade with mode and type.
71#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
72pub struct Upgrade {
73    /// The mode of the upgrade (time-based or view-based).
74    pub mode: UpgradeMode,
75    /// The type of the upgrade.
76    pub upgrade_type: UpgradeType,
77}
78
79#[derive(Clone, Copy, Debug)]
80pub struct NoStorage;