pub mod attestation;
pub mod auth;
pub mod cycles;
pub mod install;
pub mod intent;
pub mod log;
mod nonroot;
mod root;
pub mod timer;
use crate::{
InternalError, InternalErrorOrigin,
ops::runtime::{
env::EnvOps,
memory::{MemoryRegistryInitSummary, MemoryRegistryOps},
},
workflow::{self, prelude::*},
};
pub use nonroot::{
init_nonroot_canister, init_nonroot_canister_with_attestation_cache,
post_upgrade_nonroot_canister_after_memory_init,
post_upgrade_nonroot_canister_after_memory_init_with_attestation_cache,
};
pub use root::{init_root_canister, post_upgrade_root_canister_after_memory_init};
pub struct RuntimeWorkflow;
impl RuntimeWorkflow {
pub fn start_all() {
workflow::runtime::log::LogRetentionWorkflow::start();
workflow::runtime::cycles::CycleTrackerWorkflow::start();
}
pub fn start_all_with_attestation_cache() {
auth::RuntimeAuthWorkflow::log_delegation_proof_cache_policy();
workflow::runtime::attestation::AttestationKeyCacheWorkflow::start();
Self::start_all();
}
pub fn start_all_root() -> Result<(), InternalError> {
EnvOps::require_root().map_err(|err| {
InternalError::invariant(
InternalErrorOrigin::Workflow,
format!("root context required: {err}"),
)
})?;
Self::start_all();
workflow::pool::scheduler::PoolSchedulerWorkflow::start();
Ok(())
}
}
pub(super) fn log_memory_summary(summary: &MemoryRegistryInitSummary) {
for range in &summary.ranges {
let used = summary
.entries
.iter()
.filter(|entry| entry.id >= range.start && entry.id <= range.end)
.count();
crate::log!(
Topic::Memory,
Info,
"💾 memory.range: {} [{}-{}] ({}/{} slots used)",
range.crate_name,
range.start,
range.end,
used,
range.end - range.start + 1,
);
}
}
fn init_post_upgrade_memory_registry() -> Result<MemoryRegistryInitSummary, InternalError> {
MemoryRegistryOps::bootstrap_registry().map_err(|err| {
InternalError::invariant(
InternalErrorOrigin::Workflow,
format!("memory init failed: {err}"),
)
})
}
pub fn init_memory_registry_post_upgrade() -> Result<MemoryRegistryInitSummary, InternalError> {
init_post_upgrade_memory_registry()
}