Skip to main content

hotmint_types/
sync.rs

1use serde::{Deserialize, Serialize};
2
3use crate::block::{Block, Height};
4use crate::certificate::QuorumCertificate;
5use crate::epoch::EpochNumber;
6use crate::view::ViewNumber;
7
8/// Maximum number of blocks in a single sync response
9pub const MAX_SYNC_BATCH: u64 = 100;
10
11/// Sync request sent by a node that needs to catch up
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub enum SyncRequest {
14    /// Request blocks in [from_height, to_height] inclusive
15    GetBlocks {
16        from_height: Height,
17        to_height: Height,
18    },
19    /// Request the peer's current tip status
20    GetStatus,
21    /// Request the list of available state snapshots
22    GetSnapshots,
23    /// Request a specific chunk of a snapshot at the given height
24    GetSnapshotChunk { height: Height, chunk_index: u32 },
25}
26
27/// Sync response from a node serving blocks
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub enum SyncResponse {
30    /// Requested blocks with their commit QCs (may be fewer than requested).
31    /// Each tuple is `(Block, Option<QC>)` — QC is None for genesis or if not available.
32    Blocks(Vec<(Block, Option<QuorumCertificate>)>),
33    /// Current status of the responding node
34    Status {
35        last_committed_height: Height,
36        current_view: ViewNumber,
37        epoch: EpochNumber,
38    },
39    /// Error (e.g., invalid range)
40    Error(String),
41    /// List of available state snapshots
42    Snapshots(Vec<SnapshotInfo>),
43    /// A chunk of a state snapshot
44    SnapshotChunk {
45        height: Height,
46        chunk_index: u32,
47        data: Vec<u8>,
48    },
49}
50
51/// Metadata for a state snapshot.
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct SnapshotInfo {
54    pub height: Height,
55    pub chunks: u32,
56    pub hash: [u8; 32],
57}
58
59/// Result of offering a snapshot to the application.
60#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
61pub enum SnapshotOfferResult {
62    Accept,
63    Reject,
64    Abort,
65}
66
67/// Result of applying a snapshot chunk.
68#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
69pub enum ChunkApplyResult {
70    Accept,
71    Retry,
72    Abort,
73}