ifc_lite_core/execution_owner/
allocation_account.rs

1// SPDX-License-Identifier: MPL-2.0
2//! Dependency-visible resource interfaces. None authenticates source work.
3use super::SourceResourceContext;
4use crate::resource_stop::ProgramStop;
5
6/// Classification within one allowance, never a second resource limit.
7#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
8pub enum AllocationClass {
9    #[default]
10    Container,
11    Metadata,
12}
13#[derive(Clone, Copy, Debug, Default)]
14pub struct AllocationCost {
15    pub live: u64,
16    pub work: u64,
17    pub copies: u64,
18    pub class: AllocationClass,
19}
20#[derive(Clone, Copy, Debug)]
21pub enum StorageEvent {
22    Allocated(u64),
23    Deallocated(u64),
24    Replaced { old: u64, new: u64 },
25}
26/// Implementations must allocate nothing, never panic, and consult no ambient
27/// account. Refund is cleanup-only and must validate category and total before
28/// subtracting. Admission commits cancellation/terminal checks under its ledger
29/// lock. Existing cumulative costs are never refunded. This is not source authority.
30pub trait AllocationAccount: Send + Sync {
31    fn check(&self) -> Result<(), ProgramStop>;
32    fn admit(&self, cost: AllocationCost) -> Result<(), ProgramStop>;
33    fn refund(&self, bytes: u64, class: AllocationClass);
34    fn stop(&self, stop: ProgramStop) -> ProgramStop;
35    /// Optional actual-storage observation, after delegated Global operations.
36    fn observe(&self, _event: StorageEvent, _class: AllocationClass) {}
37}
38/// Captured terminal channels only. Implementations release their own locks
39/// before consulting another channel, and grant no decoder or execution rights.
40pub trait AllocationObserver: Send + Sync {
41    fn account_context(&self) -> Option<SourceResourceContext>;
42    fn check(&self) -> Result<(), ProgramStop>;
43    fn record(&self, stop: ProgramStop) -> ProgramStop;
44}