Skip to main content

Kernel

Struct Kernel 

Source
pub struct Kernel { /* private fields */ }
Expand description

Top-level kernel orchestrator.

Lifecycle: Kernel::new (or Kernel::new_with_wal / Kernel::new_with_wal_signed) → register_actioncreate_instancesubmitstep (repeat) → optional snapshot / export_wal.

Kernel is !Sync (A2 single-thread) and is owned by the caller — no internal locking, no async. All determinism guarantees depend on the caller driving a single kernel from one thread.

Implementations§

Source§

impl Kernel

Source

pub fn new() -> Self

Construct a fresh kernel with no instances, no observers, and no WAL. Use new_with_wal or new_with_wal_signed instead if you want WAL recording from step zero.

Source

pub fn new_with_wal(world_id: [u8; 32], manifest_digest: [u8; 32]) -> Self

Construct a Kernel with an attached WAL writer. Each successfully committed step appends one record (A13/A14).

Source

pub fn new_with_wal_signed( world_id: [u8; 32], manifest_digest: [u8; 32], sig_class: SignatureClass, ) -> Self

Construct a Kernel with a WAL writer that signs each record under the supplied SignatureClass (A16 — Ed25519 (Tier 2) or Hybrid (Ed25519 + ML-DSA 65, CNSA 2.0)). The verifying key is pinned in the WAL header so post-hoc verification is self-contained.

Source

pub fn wal_chain_tip(&self) -> Option<[u8; 32]>

Current chain tip if the kernel has a WAL attached.

Source

pub fn wal_record_count(&self) -> Option<usize>

Number of WAL records currently buffered (None if no WAL attached).

Source

pub fn export_wal(self) -> Option<Wal>

Consume the kernel and return the accumulated WAL (if any).

Source

pub fn register_action<A: Action>(&mut self)

Register a domain action type with the kernel’s dispatch registry. Required before submit accepts the action’s TYPE_CODE.

Source

pub fn register_observer( &mut self, obs: Box<dyn KernelObserver>, ) -> ObserverHandle

Register an observer for every kernel event. Equivalent to register_observer_filtered with EventMask::ALL.

Source

pub fn register_observer_filtered( &mut self, obs: Box<dyn KernelObserver>, mask: EventMask, ) -> ObserverHandle

Register an observer with an event-class filter. Only events whose variant bit is set in mask are delivered to this observer — useful when an observer cares about a narrow slice of the event stream (e.g. only DOMAIN_EVENT_EMITTED). EventMask::ALL is equivalent to register_observer.

Source

pub fn create_instance(&mut self, config: InstanceConfig) -> InstanceId

Create a new instance with the supplied config. Returns the freshly-allocated InstanceId (monotonic per kernel lifetime).

Source

pub fn instances_len(&self) -> usize

Number of live instances.

Source

pub fn instance_view(&self, id: InstanceId) -> Option<InstanceView<'_>>

Read-only view of one instance’s state. Returns None if id does not exist. The borrow is &self, so callers cannot mutate the kernel concurrently while a view is live.

Source

pub fn snapshot(&self) -> KernelSnapshot

Capture current kernel state as a serializable snapshot. Excludes observers and action registry — caller re-registers those after Kernel::from_snapshot(...). WAL is independent and not captured here.

Source

pub fn from_snapshot(snap: KernelSnapshot) -> Self

Restore a Kernel from a snapshot. The returned kernel has no observers, an empty action registry, and no attached WAL — caller must re-register everything before resuming step().

Source

pub fn stats(&self) -> Stats

Aggregate observability across all instances. See Stats.

Source

pub fn force_unload( &mut self, route_id: RouteId, caps: CapabilityMask, ) -> Result<usize, ArkheError>

Force-unload: drop every instance’s inflight-refs entry for route_id and emit KernelEvent::ModuleForceUnloaded with the summed live-ref count for the audit trail. Requires ADMIN_UNLOAD.

Returns the total live refs that were dropped (Ok(0) if no instance held the route).

Source

pub fn submit( &mut self, instance: InstanceId, principal: Principal, actor: Option<EntityId>, at: Tick, action_type_code: TypeCode, action_bytes: Vec<u8>, ) -> Result<ScheduledActionId, ArkheError>

Schedule a serialized action against an instance for execution at tick at. The bytes must be the canonical postcard encoding produced by <A as Action>::canonical_bytes() for some previously-registered action type matching action_type_code. Returns the freshly-allocated ScheduledActionId.

Errors with ArkheError::InstanceNotFound if instance is unknown.

Source

pub fn step(&mut self, now: Tick, caps: CapabilityMask) -> StepReport

Process at most one due action per instance, in ascending InstanceId order (A23). Returns aggregated counters for the step.

Trait Implementations§

Source§

impl Default for Kernel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.