canic_core/model/memory/
mod.rs

1pub mod cycles;
2pub mod directory;
3pub mod env;
4pub mod log;
5pub mod reserve;
6pub mod scaling;
7pub mod sharding;
8pub mod state;
9#[cfg(test)]
10pub mod tests;
11pub mod topology;
12pub mod types;
13
14pub use canic_memory::MemoryRegistryError;
15pub(crate) use env::Env;
16pub use types::*;
17
18use crate::{
19    Error,
20    model::{ModelError, memory::log::LogError},
21};
22use thiserror::Error as ThisError;
23
24///
25/// CANIC is only allowed to allocate within this inclusive range.
26/// Keep small but with room for future expansion.
27///
28
29pub(crate) const CANIC_MEMORY_MIN: u8 = 5;
30pub(crate) const CANIC_MEMORY_MAX: u8 = 30;
31
32///
33/// CANIC Memory IDs (5-30)
34///
35
36pub(crate) mod id {
37    // environment
38    // creation-only, and it stays immutable
39    // all canisters get env
40    pub const ENV_ID: u8 = 5;
41
42    // subnet-level state payloads
43    pub mod state {
44        pub const APP_STATE_ID: u8 = 7;
45        pub const SUBNET_STATE_ID: u8 = 8;
46    }
47
48    // directory
49    pub mod directory {
50        pub const APP_DIRECTORY_ID: u8 = 10;
51        pub const SUBNET_DIRECTORY_ID: u8 = 11;
52    }
53
54    // log
55    pub mod log {
56        pub const LOG_INDEX_ID: u8 = 13;
57        pub const LOG_DATA_ID: u8 = 14;
58    }
59
60    // topology
61    pub mod topology {
62        pub mod app {
63            // prime root is authoritative
64            pub const APP_SUBNET_REGISTRY_ID: u8 = 16;
65        }
66
67        pub mod subnet {
68            // registry is root-authoritative, the others are cascaded views
69            pub const SUBNET_CANISTER_REGISTRY_ID: u8 = 17;
70            pub const SUBNET_CANISTER_CHILDREN_ID: u8 = 18;
71        }
72    }
73
74    // root
75    // various structures handled solely by root
76    pub mod root {
77        pub const CANISTER_RESERVE_ID: u8 = 20;
78    }
79
80    // cycles
81    pub mod cycles {
82        pub const CYCLE_TRACKER_ID: u8 = 24;
83    }
84
85    // scaling
86    pub mod scaling {
87        pub const SCALING_REGISTRY_ID: u8 = 26;
88    }
89
90    // sharding
91    pub mod sharding {
92        pub const SHARDING_REGISTRY_ID: u8 = 27;
93        pub const SHARDING_ASSIGNMENT_ID: u8 = 28;
94    }
95}
96
97///
98/// MemoryError
99///
100
101#[derive(Debug, ThisError)]
102pub enum MemoryError {
103    // top level registry error
104    #[error(transparent)]
105    MemoryRegistryError(#[from] MemoryRegistryError),
106
107    #[error(transparent)]
108    LogError(#[from] LogError),
109}
110
111impl From<MemoryError> for Error {
112    fn from(err: MemoryError) -> Self {
113        ModelError::MemoryError(err).into()
114    }
115}