node/transition_frontier/genesis/
transition_frontier_genesis_state.rs

1use ledger::dummy::dummy_blockchain_proof;
2use mina_p2p_messages::v2;
3use openmina_core::{block::ArcBlockWithHash, constants::PROTOCOL_VERSION};
4use serde::{Deserialize, Serialize};
5
6use super::{empty_block_body, GenesisConfigLoaded};
7
8#[derive(Serialize, Deserialize, Debug, Clone)]
9pub enum TransitionFrontierGenesisState {
10    Idle,
11    LedgerLoadPending {
12        time: redux::Timestamp,
13    },
14    LedgerLoadSuccess {
15        time: redux::Timestamp,
16        data: GenesisConfigLoaded,
17    },
18    Produced {
19        time: redux::Timestamp,
20        negative_one: v2::MinaStateProtocolStateValueStableV2,
21        genesis: v2::MinaStateProtocolStateValueStableV2,
22        genesis_hash: v2::StateHash,
23        genesis_producer_stake_proof: v2::MinaBaseSparseLedgerBaseStableV2,
24    },
25    ProvePending {
26        time: redux::Timestamp,
27        negative_one: v2::MinaStateProtocolStateValueStableV2,
28        genesis: v2::MinaStateProtocolStateValueStableV2,
29        genesis_hash: v2::StateHash,
30        genesis_producer_stake_proof: v2::MinaBaseSparseLedgerBaseStableV2,
31    },
32    ProveSuccess {
33        time: redux::Timestamp,
34        genesis: ArcBlockWithHash,
35    },
36}
37
38impl TransitionFrontierGenesisState {
39    pub fn block_with_dummy_proof(&self) -> Option<ArcBlockWithHash> {
40        let Self::Produced {
41            genesis,
42            genesis_hash,
43            ..
44        } = self
45        else {
46            return None;
47        };
48        ArcBlockWithHash::try_new(
49            v2::MinaBlockBlockStableV2 {
50                header: v2::MinaBlockHeaderStableV2 {
51                    protocol_state: genesis.clone(),
52                    protocol_state_proof: dummy_blockchain_proof().clone(),
53                    delta_block_chain_proof: (genesis_hash.clone(), std::iter::empty().collect()),
54                    current_protocol_version: PROTOCOL_VERSION.clone(),
55                    proposed_protocol_version_opt: None,
56                },
57                body: v2::StagedLedgerDiffBodyStableV1 {
58                    staged_ledger_diff: empty_block_body(),
59                },
60            }
61            .into(),
62        )
63        .ok()
64    }
65
66    pub fn prove_pending_block_hash(&self) -> Option<v2::StateHash> {
67        match self {
68            Self::ProvePending { genesis_hash, .. } => Some(genesis_hash.clone()),
69            _ => None,
70        }
71    }
72
73    pub fn proven_block(&self) -> Option<&ArcBlockWithHash> {
74        match self {
75            Self::ProveSuccess { genesis, .. } => Some(genesis),
76            _ => None,
77        }
78    }
79
80    pub fn block_with_real_or_dummy_proof(&self) -> Option<ArcBlockWithHash> {
81        self.proven_block()
82            .cloned()
83            .or_else(|| self.block_with_dummy_proof())
84    }
85}