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}
22
23/// Sync response from a node serving blocks
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub enum SyncResponse {
26    /// Requested blocks with their commit QCs (may be fewer than requested).
27    /// Each tuple is `(Block, Option<QC>)` — QC is None for genesis or if not available.
28    Blocks(Vec<(Block, Option<QuorumCertificate>)>),
29    /// Current status of the responding node
30    Status {
31        last_committed_height: Height,
32        current_view: ViewNumber,
33        epoch: EpochNumber,
34    },
35    /// Error (e.g., invalid range)
36    Error(String),
37}