snark/block_verify/
mod.rs

1//! # Block Verification State Machine
2//!
3//! This module implements the state machine for verifying blockchain block proofs
4//! within the Mina protocol. It manages the lifecycle of block verification
5//! requests and maintains verification state.
6//!
7//! ## Overview
8//!
9//! Block verification ensures that:
10//! - Block proofs are cryptographically valid
11//! - Block headers contain correct consensus information
12//! - Blockchain state transitions are legitimate
13//!
14//! ## Usage
15//!
16//! Block verification is typically initiated by:
17//! - Consensus mechanisms validating incoming blocks
18//! - Fork resolution comparing competing chains
19//!
20//! The verification process runs asynchronously in service threads to avoid
21//! blocking the main state machine.
22
23mod snark_block_verify_state;
24pub use snark_block_verify_state::*;
25
26mod snark_block_verify_actions;
27pub use snark_block_verify_actions::*;
28
29mod snark_block_verify_reducer;
30pub use snark_block_verify_reducer::reducer;
31
32pub use crate::block_verify_effectful::{
33    SnarkBlockVerifyError, SnarkBlockVerifyId, SnarkBlockVerifyIdType,
34};
35
36use serde::{Deserialize, Serialize};
37use std::sync::Arc;
38
39use mina_core::block::{Block, BlockHash, BlockHeader, BlockHeaderWithHash, BlockWithHash};
40
41#[derive(derive_more::From, Serialize, Deserialize, Debug, Clone)]
42pub enum VerifiableBlockWithHash {
43    FullBox(BlockWithHash<Box<Block>>),
44    FullArc(BlockWithHash<Arc<Block>>),
45    HeaderBox(BlockHeaderWithHash<Box<BlockHeader>>),
46    HeaderArc(BlockHeaderWithHash<Arc<BlockHeader>>),
47}
48
49impl VerifiableBlockWithHash {
50    pub fn hash_ref(&self) -> &BlockHash {
51        match self {
52            Self::FullBox(v) => &v.hash,
53            Self::FullArc(v) => &v.hash,
54            Self::HeaderBox(v) => &v.hash,
55            Self::HeaderArc(v) => &v.hash,
56        }
57    }
58
59    pub fn full_ref(&self) -> Option<&Block> {
60        match self {
61            Self::FullBox(v) => Some(&v.block),
62            Self::FullArc(v) => Some(&v.block),
63            Self::HeaderBox(_) => None,
64            Self::HeaderArc(_) => None,
65        }
66    }
67
68    pub fn header_ref(&self) -> &BlockHeader {
69        match self {
70            Self::FullBox(v) => &v.block.header,
71            Self::FullArc(v) => &v.block.header,
72            Self::HeaderBox(v) => &v.header,
73            Self::HeaderArc(v) => &v.header,
74        }
75    }
76}
77
78impl AsRef<BlockHeader> for VerifiableBlockWithHash {
79    fn as_ref(&self) -> &BlockHeader {
80        self.header_ref()
81    }
82}
83
84impl From<(BlockHash, Box<Block>)> for VerifiableBlockWithHash {
85    fn from((hash, block): (BlockHash, Box<Block>)) -> Self {
86        BlockWithHash { hash, block }.into()
87    }
88}
89
90impl From<(BlockHash, Arc<Block>)> for VerifiableBlockWithHash {
91    fn from((hash, block): (BlockHash, Arc<Block>)) -> Self {
92        BlockWithHash { hash, block }.into()
93    }
94}
95
96impl From<(BlockHash, Box<BlockHeader>)> for VerifiableBlockWithHash {
97    fn from((hash, header): (BlockHash, Box<BlockHeader>)) -> Self {
98        BlockHeaderWithHash { hash, header }.into()
99    }
100}
101
102impl From<(BlockHash, Arc<BlockHeader>)> for VerifiableBlockWithHash {
103    fn from((hash, header): (BlockHash, Arc<BlockHeader>)) -> Self {
104        BlockHeaderWithHash { hash, header }.into()
105    }
106}