Skip to main content

qualia_core_db/bundle/stream/runtime/state/
mod.rs

1//! Persistent exact runtime state with short canonical parent scopes.
2//! State moves through the EXISTING transition implementation and restores on
3//! every return/error/unwind. No new ledger or duplicate active tokens.
4mod access;
5mod close;
6mod data;
7mod loans;
8mod parents;
9mod preflight;
10mod restore;
11mod scope;
12use crate::net::peer::runtime::incarnation::CanonicalIncarnation;
13use crate::net::qdnf::errors::QdnfError as E;
14pub use access::RuntimeAccess;
15pub use close::RuntimeCloseError;
16pub(super) use data::RuntimeClosePhase;
17use data::RuntimeData;
18pub use parents::RuntimeParents;
19#[must_use = "drain real I/O and consume try_close; lost state retains canonical charges"]
20pub struct RetainedRuntime<'parent, 'host> {
21    parents: &'parent RuntimeParents<'host>,
22    registration: CanonicalIncarnation,
23    data: Option<RuntimeData>,
24}
25/// Actual retained shell + temporary legacy wrapper + guard/access footprint.
26/// Scope moves at most2*size_of<RuntimeData> logical bytes; this is NOT zero-copy.
27fn charged_bytes() -> Result<u64, E> {
28    let bytes = core::mem::size_of::<RetainedRuntime<'static, 'static>>()
29        .checked_add(core::mem::size_of::<RuntimeData>())
30        .and_then(|n| n.checked_add(core::mem::size_of::<restore::Restore<'static, 'static>>()))
31        .and_then(|n| n.checked_add(core::mem::size_of::<loans::ParentLoans<'static>>()))
32        .and_then(|n| n.checked_add(core::mem::size_of::<RuntimeParents<'static>>()))
33        .and_then(|n| n.checked_add(core::mem::size_of::<RuntimeAccess<'static, 'static>>()))
34        .ok_or(E::Range)?;
35    u64::try_from(bytes).map_err(|_| E::Range)
36}
37#[cfg(test)]
38mod tests;