espresso_types/v0/v0_1/
instance_state.rs

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