Skip to main content

hotmint_types/
sync.rs

1use serde::{Deserialize, Serialize};
2
3use crate::block::{Block, Height};
4use crate::epoch::EpochNumber;
5use crate::view::ViewNumber;
6
7/// Maximum number of blocks in a single sync response
8pub const MAX_SYNC_BATCH: u64 = 100;
9
10/// Sync request sent by a node that needs to catch up
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub enum SyncRequest {
13    /// Request blocks in [from_height, to_height] inclusive
14    GetBlocks {
15        from_height: Height,
16        to_height: Height,
17    },
18    /// Request the peer's current tip status
19    GetStatus,
20}
21
22/// Sync response from a node serving blocks
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub enum SyncResponse {
25    /// Requested blocks (may be fewer than requested if range exceeds tip)
26    Blocks(Vec<Block>),
27    /// Current status of the responding node
28    Status {
29        last_committed_height: Height,
30        current_view: ViewNumber,
31        epoch: EpochNumber,
32    },
33    /// Error (e.g., invalid range)
34    Error(String),
35}