Minima storage foundation
Experimental fixed encodings, exclusive stable block ownership and explicit
borrowed workspace. Algorithms live in
cdk-rsx-collections-minima.
Minima owns the architecture and measured-reference
scope; upgrades owns admission and conversion rules.
Keep Root, collection descriptors and scalar control in private, root-attached
Nyxus Data. Stable bytes contain fixed payloads, not arbitrary Rust layouts.
Minima is a collection-controlled storage engine, not another Store Memory
declaration selector. Native provider tests show allocation,
ownership and reopening; actual IC KEEP and rollback require the checks described
in testing.
Provider and retained ownership
Arena::format(memory) consumes the sole physical stable Memory capability;
save arena.root() in owning Data. Collection::new(&mut arena) creates an
empty move-only owner. It acquires whole, absolutely aligned 64 KiB blocks on
demand, with sixteen 4 KiB node positions and no allocator metadata inside.
One private BlockAuthority embeds the retained Root and collection identity.
The PageDirectory keeps 16-byte physical-page/generation entries, with sixteen
inline and a retained Nyxus vector for arbitrary overflow. Each entry owns its
whole block; the larger inline descriptor is a placement tradeoff, not a promise
of fewer charged heap regions.
Collection and raw Block cannot be cloned or decoded into owning edges.
Collection node/range operations privately construct a 16-byte
CollectionBlockRef: a borrow of the whole descriptor and an admitted block
base. Its lifetime excludes retirement and truncation, proving live ownership
without an owner-table lookup. Storage::read_collection/write_collection
still check exact provider Root and byte bounds before IO.
Raw blocks lend a separate 16-byte BlockRef to Storage::read/write.
Those operations retain exact root/domain, live owner generation and bounds
checks: a raw block can outlive its collection, whose retirement invalidates
its access. No operation takes a duplicate caller-supplied owner argument.
Collection admission checks an allocation's root and owner before transfer.
Drop checks physical generation and returns whole blocks through retained
authority without stable IO. Nonowning IDs grant no block ownership.
Storage::allocate returns an exclusive, all-byte-zero whole block; wrappers
must preserve that promise. allocate_collection returns the same initialized
page as a temporary CollectionAllocation borrowed from the live collection.
The borrow proves owner liveness without a table lookup or retained Root clone.
Only that collection can consume the ticket into its directory; an abandoned
ticket releases its page. Growth initializes new bytes and reuse clears the
entire acquired block. Exposing another logical node inside a retained partial
block does not establish fresh zero bytes. Bulk growth reserves its complete
directory capacity before acquiring payload pages. Arena preflights the needed
free-list prefix and exact fresh extent, reserves slot capacity once, and grows
physical memory once for that extent. It publishes each page with its own reuse
generation; no spare physical capacity or uninitialized tail is exposed.
read_at supports narrow fixed slots; read_node fetches one aligned 4 KiB node.
A range within one block dispatches directly; a range crossing blocks is checked
in full before its first read or write. There is no automatic cache or preceding
stable metadata read. Storage
wrappers forward read/write and read_collection/write_collection with
matching counters and fault behavior. Forward allocate_collection to retain
the borrowed acquisition path; its default adapter preserves raw-allocation
instrumentation for wrappers that only implement allocate. Forward
grow_collection for bulk physical growth; its default preserves each existing
allocation hook. Forward
same_root for its read-only identity check; no capability may be reconstructed
from offsets or IDs.
Reusable workspace
use cdk_rsx_engine_minima::NodeBuffer;
let mut buffer = NodeBuffer::new();
let mut workspace = buffer.workspace();
// Borrow workspace sequentially for collection operations.
The initialized buffer needs no special destination alignment or heap allocation;
stable source nodes remain aligned. Workspace is one thin borrowed reference.
Keep the buffer outside repeated operations. A node view cannot
outlive its loan or the next overwrite. No workspace/provider loan crosses
await; retain owned results and reacquire access afterward.
Hylix composition and KEEP
let mut minima = cdk_rsx_engine_minima::Arena::format(physical_memory)?;
let rooted_descriptor = minima.root(); // save in private Nyxus Data
let hylix = cdk_rsx_engine_hylix::Arena::format(
minima.hylix_memory(), hylix_contract,
)?;
// Supply hylix through Store::with_hylix in ordinary Store setup.
The single leased hylix_memory() image is virtually contiguous; its pages map
to disjoint physical blocks from the same authority. Image growth claims only
missing whole pages through the same bulk acquisition path as collection growth,
preserving existing mappings and per-page generations. An already satisfied
growth request returns without borrowing the physical provider. Never acquire a
second independent StableMemory provider.
Release the transient Arena and Hylix provider during root teardown before
KEEP. Their byte capability is not persisted in Root. After catalog admission,
read the retained descriptor, call Arena::open(physical_memory, root.clone()),
then recreate its Hylix adapter and open that unchanged virtual image. Root
rejects simultaneous provider bindings. Format/high-water checks occur at open,
not before each node fetch. See Minima restoration
for the lifecycle sequence; native provider reopening alone does not establish
actual IC upgrade or rollback behavior.
Encoding and contracts
Fixed gives an exact compile-time width and positional encoding. Integers are
little endian; FixedBytes<N> is N bytes; FixedText<N> is exactly N valid UTF-8
bytes. Arrays, tuples and fixed_record! concatenate fields. No field tags,
per-entry lengths, native padding, pointers, truncation or implicit text padding
enter the encoding. FixedKey additionally requires canonical identity bytes
and total Ord consistent with equality; LE bytes need not sort numerically.
Retained admission automatically carries the concrete carrier's required
interpretation proof. Collection contracts include their production source,
relevant helpers, MINIMA_POLICY and encoded logical type contracts. Custom
codec/comparator and owner-specific configuration inputs remain explicit. Physical
certificates must follow the complete retained Root/Collection graph, including
private allocator and Nyxus Vec/Rc layouts. Changed encoding, ordering, hashing
or geometry needs explicit conversion before existing bytes can be interpreted.
Validate expected rejection before mutation. Provider mutation failures abort the physical execution and rely on IC rollback; no local journal is maintained. Native hosts catching an abort must restore the complete image and dependent retained descriptors before reuse.
License
This crate is available under the ICP3V License.