π§βπ§ Canic π§βπ§ β Internet Computer Orchestration
Canic is a Rust toolkit for orchestrating Internet Computer (IC) canisters at scale. It packages the battle-tested patterns from large multi-canister deployments into a reusable crate: lifecycle macros, stable-memory helpers, orchestration ops, and endpoint bundles that keep your boundary layer thin while enforcing clean layering inside the canister graph.
The crate was historically known as ICU (Internet Computer Utilities). All core APIs have been renamed to Canic for the crates.io release.
Highlights
- π§© Bootstrap macros β
canic::start!,canic::start_root!,canic_build!, andcanic_build_root!wire init/upgrade hooks, export endpoints, and validate config at compile time. - π§ State layers β opinionated separation for stable memory, volatile state, ops/business logic, and public endpoints.
- πΊοΈ Topology-aware config β typed subnet blocks, app directories, and reserve policies validated straight from
canic.toml. - π Auth utilities β composable guards (
auth_require_any!,auth_require_all!) for controllers, parents, whitelist principals, and more. - ποΈ Stable memory ergonomics β
ic_memory!,ic_memory_range!, andeager_static!manage IC stable structures safely across upgrades. - π¦ WASM registry β consistently ship/lookup child canister WASMs with hash tracking.
- πͺ΅ Configurable logging β ring/age retention with second-level timestamps and paged log/query helpers.
- β»οΈ Lifecycle helpers β shard policies, reserve pools, scaling helpers, and sync cascades keep fleets healthy.
- π§ͺ Ready for CI β Rust 2024 edition, MSRV 1.90, with
cargo fmt,cargo clippy -- -D warnings, andcargo testwired viamaketargets.
For canister signatures, use the ops faΓ§ade (ops::signature::prepare/get/verify_auth_token) instead of feeding raw principals into ic-signature-verification; the helper builds the proper DER canister-sig public key and domain-prefixed message to avoid slice panics on short (10-byte) canister IDs.
π Repository Layout
assets/β documentation media (logo and shared imagery).crates/β workspace crates.canic/β core library crate with orchestration primitives and macros.src/auth.rs&src/guard.rsβ reusable authorization helpers.src/cdk/β IC CDK shims and patched utilities used by the macros.src/config/β configuration loaders, validators, and schema helpers.src/env/β curated canister ID constants (ck, NNS, SNS) and helpers.src/interface/β typed wrappers for IC management calls, ck-ledgers, and ICRC ledgers.src/log.rsβ logging macros.src/macros/β public macro entrypoints (canic::start!,canic_endpoints_*, memory helpers).src/memory/β stable storage abstractions and registries built onic-stable-structures.src/ops/β orchestration/business logic bridging memory and state layers.src/runtime.rsβ runtime glue shared by macros.src/serialize.rsβ deterministic codecs.src/spec/β representations of external IC specs (ICRC, NNS, SNS, etc.).src/state/β volatile runtime state caches and registries.src/types/β shared domain types.src/utils/β time helpers, wasm utilities, etc.examples/β runnable demos for guards, shard lifecycle, and canister ops.
canisters/β reference canisters that exercise the library end to end:root/orchestrator tying together shards, scaling, and reserve flows.app/β sample application canister used in integration flows.auth/β auxiliary canister covering authorization patterns.shard/,shard_hub/β shard lifecycle pair for pool management.scale/,scale_hub/β reserve scaling agents demonstrating capacity workflows.blank/β minimal canister template.
scripts/β build, release, and environment helpers.app/β dfx bootstrap scripts for the demo topology.ci/β version bumping and security checks used by CI.env/β local environment utilities (e.g., shared env updates).
.github/workflows/β CI pipelines (fmt, clippy, tests, release)..githooks/β optional git hooks;pre-commitformats and runs cargo sort before committing..cargo/β workspace Cargo config that pins the tmp dir to avoid cross-device link errors when sandboxed.
Getting Started
1. Install
Inside your workspace:
Or reference the workspace path if you pulled the repository directly.
2. Configure build.rs
Every canister crate should declare a config file (default name: canic.toml). Use one of the provided build macros:
// Root canister build.rs
// Non-root canister build.rs
The macro validates the TOML during compilation, emits the right cfg flags (such as canic and canic_root), and exposes the canonical config path via CANIC_CONFIG_PATH.
3. Bootstrap your canister
In lib.rs:
use *;
use EXAMPLE;
start!; // or canic::start_root!() for the orchestrator canister
async
async
async
See crates/canisters/root and the hub/shard reference canisters under crates/canisters/* for end-to-end patterns, including WASM registries and endpoint exports.
4. Define your topology
Populate canic.toml with subnet definitions, directory membership, and per-canister policies. Each [subnets.<name>] block lists auto_create and subnet_directory canister types, then nests [subnets.<name>.canisters.<type>] tables for top-up settings plus optional sharding and scaling pools. Global tables such as controllers, app_directory, reserve, log, and standards shape the overall cluster. The [log] block controls ring/age retention in seconds. The full schema lives in CONFIG.md.
Layered Architecture
Canic enforces clear separation between storage, transient state, orchestration logic, and public endpoints:
memory/β stable data backed byic-stable-structures(e.g. shard registries, reserve pools).state/β volatile caches and session stores that reset on upgrade.ops/β business logic tying state + memory together (sharding policies, scaling flows, reserve management).endpoints/β macro-generated IC entrypoints that delegate toops/and keep boundary code minimal.- Temporary exception (target revisit in ~2 weeks): when no ops faΓ§ade exists yet, read-only queries may pull directly from
memory/orstate/; mutations should still flow throughops/.
Capabilities & Endpoints
Sharding π¦
canic::ops::ext::sharding assigns tenants to shard canisters according to a ShardingPolicy (initial capacity, max shards, growth thresholds). Admin work flows through a single controller-only endpoint:
canic_sharding_admin
Command variants cover register, audit, drain, rebalance, and decommission flows. Your application is responsible for data migration around these moves.
Scaling & Reserve Pools βοΈ
canic_scaling_registry()provides controller insight into scaling pools via the shared endpoint bundle.- Root canisters manage spare capacity through
canic::ops::root::reserveand thecanic_reserve_*endpoints.
Directory Views π
canic_app_directory()returns the prime root directory view for operator dashboards.canic_subnet_directory()exposes the per-subnet directory so children can discover peers.
ICRC Support π
The base endpoint bundle includes:
icrc10_supported_standards()icrc21_canister_call_consent_message(request)
Register consent messages via state::icrc::Icrc21Registry for rich UX flows.
Tooling & DX
- Format:
cargo fmt --all(ormake fmt) - Fmt check:
make fmt-check - Check (type-check only):
make check - Lint:
make clippy - Test:
make test - Build release WASMs:
make build - Run the example suite:
make examplesorcargo build -p canic --examples
The make targets pin CARGO_TARGET_DIR/TMPDIR to target/tmp to dodge Invalid cross-device link errors in sandboxed environments. If you prefer raw cargo invocations, mirror the same env:
CARGO_TARGET_DIR=/target TMPDIR=/target/tmp
rust-toolchain.toml pins the toolchain so CI and local builds stay in sync.
Examples
Explore the runnable examples under crates/canic/examples/:
auth_rules.rsβ compose guard policies.minimal_root.rsβ bootstrap a bare-bones orchestrator.ops_create_canister.rsβ walk through the create-canister flow.shard_lifecycle.rsβ simulate register/assign/drain/rebalance operations.
Project Status & Contributing
Canic is the successor to the internal ICU toolkit. The repository is in the process of being opened for wider use; issues and PRs are currently limited to the core team. Follow AGENTS.md, VERSIONING.md, and RELEASE_GUIDE.md for workflow expectations.
License
MIT. See LICENSE for details.