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