dig_events_protocol/sync.rs
1//! Sync-state contract: where the sync loop sits relative to the chain tip (SPEC §6).
2
3use serde::{Deserialize, Serialize};
4
5/// Where the sync loop is relative to the chain tip (a tri-state, pushed via a `SyncProgress`
6/// event).
7///
8/// Serializes as a snake_case string on the wire (`"idle"` / `"syncing"` / `"synced"`).
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11pub enum SyncLifecycle {
12 /// Not yet started / no peer.
13 Idle,
14 /// Actively catching up to the tip.
15 Syncing,
16 /// Caught up to the tip and tracking live.
17 Synced,
18}
19
20/// A snapshot of sync state for a wallet.
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
22pub struct SyncStatus {
23 /// The tri-state lifecycle.
24 pub state: SyncLifecycle,
25 /// The height the wallet has processed up to.
26 pub peak_height: u32,
27 /// The chain tip height the wallet is syncing toward.
28 pub target_height: u32,
29}