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