canic_core/ops/sync/
mod.rs

1//! Synchronization helpers for propagating state and topology snapshots.
2
3pub mod state;
4pub mod topology;
5
6use crate::{Error, ThisError, log, log::Topic, ops::OpsError};
7use candid::Principal;
8
9const SYNC_CALL_WARN_THRESHOLD: usize = 10;
10
11///
12/// SyncOpsError
13/// Errors raised during synchronization
14///
15
16#[derive(Debug, ThisError)]
17pub enum SyncOpsError {
18    #[error("canister not found")]
19    CanisterNotFound(Principal),
20
21    #[error("root canister not found")]
22    RootNotFound,
23
24    #[error("invalid parent chain: empty")]
25    InvalidParentChain,
26
27    #[error("parent chain does not start with self ({0})")]
28    ParentChainMissingSelf(Principal),
29
30    #[error("cycle detected in parent chain at {0}")]
31    ParentChainCycle(Principal),
32
33    #[error("parent chain length {0} exceeds registry size")]
34    ParentChainTooLong(usize),
35
36    #[error("parent chain did not terminate at root (stopped at {0})")]
37    ParentChainNotRootTerminated(Principal),
38
39    #[error("next hop {0} not found in parent chain")]
40    NextHopNotFound(Principal),
41}
42
43impl From<SyncOpsError> for Error {
44    fn from(err: SyncOpsError) -> Self {
45        OpsError::from(err).into()
46    }
47}
48
49///
50/// Helpers
51///
52
53fn warn_if_large(label: &str, count: usize) {
54    if count > SYNC_CALL_WARN_THRESHOLD {
55        log!(
56            Topic::Sync,
57            Warn,
58            "sync: large {}: {} entries",
59            label,
60            count
61        );
62    }
63}