espresso_types/v0/v0_1/
instance_state.rs

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