Skip to main content

Crate spacedb_query

Crate spacedb_query 

Source
Expand description

§spacedb-query — SpaceDB Layer 4 (compute-to-data)

The environment forbids hauling data to a central brain, so SpaceDB inverts it: the query travels to the data; only the answer travels back. A query is a deterministic, fuel/memory-bounded WASM function that runs on the node holding the data — and because the runtime is deterministic, the result is corroboratable: a host that returns a different answer than its peers is caught.

M6-S1 ships the verifiable-compute core: FunctionRuntime (deterministic, no-WASI WASM execution), the FunctionRun attestation, and corroborate. The partition-aware planner + pinned-snapshot reads (S2) and the on-node vector index (spacedb-vector, S3) build on this.

Open-core (MIT): built on wasmtime directly — the engine MATA’s maestro-fn-runtime wraps — with no MATA dependency. Fanning corroboration across independent marketplace hosts is the MATA seam; the runtime, the attestation, and the comparison are here.

Structs§

Coverage
How much of the dataset the result actually covers — the honesty contract.
CtxRights
What the invoking capability lets the function do — checked on every host call. A function has exactly the caller’s rights, never more.
Execution
One execution: the answer the function produced, and the attestation proving it.
FunctionCtx
The context one function invocation executes in: the pinned snapshot it reads, the write-set it accumulates, the rights it may exercise, and the collections it must be refused (zero-knowledge: the host holds ciphertext it provably cannot compute on — serving it to server-side code would break that promise).
FunctionOutcome
One completed function invocation: the execution (output + attestation, with the snapshot hash bound into input_digest) and the context carrying the write-set.
FunctionRun
The deterministic record of one function execution. The fields are exactly what must match across honest hosts; nothing device-dependent (e.g. wall time) is included.
FunctionRuntime
A reusable compute-to-data engine. Construct once per host; run is stateless apart from a compile cache keyed by the workload hash.
PinnedRecords
A RecordSnapshot shared between the functions that run over it, with its content hash taken once. Every FunctionCtx built from it holds the same records (no clone per run) and the same hash (no re-hash per run).
QueryOutcome
The result of a query: the reduced output (if any shard contributed), the coverage, and the per-shard map attestations.
QueryPlan
The query: a map over each shard’s snapshot and an associative/commutative reduce over the partials, both deployed as deterministic WASM.
RunLimits
Per-invocation bounds. Both are deterministic — fuel is an instruction count; the memory cap is in whole MB — so they bound execution identically on every host.
Shard
One shard of a query’s data: a pinned snapshot, on a host that may be down.
Snapshot
A frozen view of one shard’s data at a frontier.

Enums§

Corroboration
The verdict of comparing two attestations of the same workload + input.
QueryError

Functions§

corroborate
Compare two attestations. Honest runs of the same (workload, input) agree on all fields; any divergence (a wrong output, a padded fuel count) disagrees.
run_query
Run plan over shards: map each reachable shard’s snapshot, then reduce the partials. Unreachable shards are skipped (lowering coverage, never failing the query); a map/reduce error on a reachable shard propagates (it signals a systemic deploy/ABI bug, since the same WASM runs everywhere).

Type Aliases§

QueryResult
RecordSnapshot
A pinned record view: (collection, record id) → value bytes, materialized at one frontier. BTreeMap so iteration (and every digest over it) is deterministic on every host.