1use serde::{Deserialize, Serialize};
2
3use crate::block::{Block, Height};
4use crate::certificate::QuorumCertificate;
5use crate::epoch::EpochNumber;
6use crate::view::ViewNumber;
7
8pub const MAX_SYNC_BATCH: u64 = 100;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13pub enum SyncRequest {
14 GetBlocks {
16 from_height: Height,
17 to_height: Height,
18 },
19 GetStatus,
21 GetSnapshots,
23 GetSnapshotChunk { height: Height, chunk_index: u32 },
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29pub enum SyncResponse {
30 Blocks(Vec<(Block, Option<QuorumCertificate>)>),
33 Status {
35 last_committed_height: Height,
36 current_view: ViewNumber,
37 epoch: EpochNumber,
38 },
39 Error(String),
41 Snapshots(Vec<SnapshotInfo>),
43 SnapshotChunk {
45 height: Height,
46 chunk_index: u32,
47 data: Vec<u8>,
48 },
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct SnapshotInfo {
54 pub height: Height,
55 pub chunks: u32,
56 pub hash: [u8; 32],
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
61pub enum SnapshotOfferResult {
62 Accept,
63 Reject,
64 Abort,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
69pub enum ChunkApplyResult {
70 Accept,
71 Retry,
72 Abort,
73}