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