Block transactions
Current contract for bulk block edits on the server: the one native
submission API every block writer lowers to. Design:
Enki B §2 (docs/superpowers/specs/2026-09-27-enki-b-mod-platform-contract-design.md)
(§2.11 for non-chunk sections, and its “As built” issues 16–30). Source:
crates/manifold-server-state/src/transaction/,
crates/manifold-server-state/src/block_world_apply.rs (single edits),
crates/manifold-world/src/{chunk_cell,chunk_map,world_space}.rs,
crates/manifold-net-protocol/src/chunk_edit.rs.
The rule
A block write goes through transaction::submit as a TxnRequest: an actor
(Player, ModSelf or the server-only Rule), an optional owner, options
and one or more sections. Console /fill and /setblock, the block-world
handler’s decided edits and Talos’s use-block
(navigation) already do. A scheduled system, which
holds the world shared, declares add_resource_write::<TxnEngine>() and
submits with TxnEngine::submit on the engine it reaches through that write:
the same checks and queue as transaction::submit, one code path, except that
a player actor needs the world’s connections and is refused there
(Other("player-actor-needs-world")). Such worlds install the engine up front
with transaction::install, which is idempotent (an installed engine, its
queue and configuration stay as they are); submit installs it on first use.
A section is either the engine’s BlockOps (fill, set, set_component,
remove_component, revert, reapply, expect) or a program’s own
TxnSection. Block components change with their cells in the same
transaction; see block components (docs/architecture/block-components.md). ECS state that must
change atomically with blocks (an item consumed by a placement, loot deposited
by a break) changes in a non-chunk section of the same transaction, never in a
follow-up.
Single-block edits
The handler keeps the block-world decision ABI (take-edit-requests,
queue-edit, reject-edit, plus take-results). The orchestrator lends the
player-edit handler (declared in [block_world], Enki B §3.1) the world,
shared, for its
server-tick systems: ModOrchestrator::tick_server opens the loan before
the schedule walk and closes it before the write-back, and the calls reach
the server through the BlockWorldPort resource ServerSession::new
installs (block_world_apply::install_port). queue-edit calls
block_world_apply::submit_decided_edit during the guest call, which
submits the edit as a one-cell transaction and returns its batch id: actor
and owner the requesting player, requester
Requester::Handler(<handler load-order index>), no undo record,
Replication::BlockUpdates, and a section that applies within the
validating slot. Handler edits validate first in the slot, so an edit
decided this tick commits this tick and is broadcast as BlockUpdate with it.
Locks, reservations, nodes (build.edit, which every player holds by
default), water intake, the commit log, lighting and hierarchy apply as to
any transaction.
- An edit that writes the value already there commits with
changed_cells: 0and sends nothing; the chunk is not dirtied. - A refusal is sent to the requesting client as
BlockEditRejectedin the same tick, under theengine.edit.rejected.*keys (block_world_apply::rejection_text). The handler’s ownreject-edittakes the same path asTxnReject::Protected(reason). queue-editfails at once only with the sharedsubmit-error:malformed(a value wider than a block id) andactor-unknown(the peer is not a connected player), both also sent to the client, andother("not-handler")(a later importer) orother("outside-server-tick")(no loan: outside a server-tick system, or no port installed).- Each edit’s
TxnResultwaits in the handler’s results ring. The guest drains it withtake-results(thetxn-resultspayload, postcardVec<TxnResult>; SDK:manifold_mod_substrate::block_world::take_results); native code withblock_world_apply::take_block_edit_results(world, handler). Results of edits queued in tick N arrive from tick N + 1’s call. Feedback such as a break or place sound belongs toCommittedresults withchanged_cells > 0(block_world::committed_changes), matched toqueue-edit’s batch id. The flagship’sblock_edit_applykeeps each queued edit’s cue by batch id and plays it from the result, a tick after the request: a break on air, a place over the same block and a refused edit are silent (sound_cue_e2e). - The loan is shared, so other per-call world views (Daedalus G’s physics
window) can be held alongside it: the port writes
only the transaction engine and
TickEvents, throughVoxelWorld::structural(transaction::submit_in,take_results_in). Executor parity harnesses lend a scratch world instead (BlockWorldRecord::record,RECORDING_PORT).
Lifecycle
- Queue.
submitchecks framing and the actor and returns a batch id. - Validate at B’s slot in
ServerSession::step_tick, after the F3 flush, before the console drains; the handler’s single edits first, then other native requests, then guest transactions: nodes (requires,build.editfor players; every node goes throughanim_contract::player_has_nodeand the permission catalogue), the cell cap (TxnConfig::max_cells, 262,144 in the slice), residency, locks, values, compare-and-set, component writes (declared, unsealed, applicable, within limits), reservations and water intake. Chunks that hold block components, or that a section writes components in (TxnSection::writes_components), are previewed on scratch copies: an implicit removal of an offline record is refused (ComponentOffline), and removed records withon_removeand added records withon_addappend their handler sections (below). A section that moves value (TxnSection::moves_value) refuses a requested undo record (UndoForbidden). All-or-nothing: a refusal writes nothing. - Lock. Every touched chunk is locked (other transactions get
RegionBusy, which a handler edit’s client sees asengine.edit.rejected.region_busy), pinned by a loader view centre fromPIN_VIEW_BASEup, and held out of save batches until commit. - Apply chunk by chunk inside the “world edits” budget (4 ms, up to 8 ms
with tick headroom); a larger transaction continues on later ticks. Each
chunk is one
WorldSpace::apply_chunk_edit: one snapshot and one diff, one change-log entry, one dirty mark, emitter updates for emissive cells, one hierarchy invalidation and oneChunkEditsdelta (aBlockUpdateper changed cell withReplication::BlockUpdates). - Commit. Non-chunk sections run
apply_oncein submission order, the undo record (MUR1) is written if requested, locks and pins are released, the commit is logged inTxnCommitLog, and the requester’s results ring getsCommitted. Each section’sfinishhook runs in that tick for every outcome; a transaction it submits queues for the next slot.
Before a shutdown save (native shutdown, the browser worker’s shutdown and
flush), hosts call transaction::settle, which applies every queued and
in-flight transaction to completion: held chunks would otherwise miss the
final save.
Non-chunk sections
A section that returns Some(AccessSet) from TxnSection::access is a
non-chunk section: it reads the ECS while validating (ValidateCx::ecs(), a
read-only EcsView) and writes it once at commit (apply_once(&mut ApplyOnceCx)), both only through that set (manifold_ecs::AccessSet, as a
system declares; set_structural for spawn, despawn, insert, remove).
- No ambient world: the contexts expose typed accessors that check the set. Undeclared access panics in debug builds with the scheduler’s §15 message; release skips the check. An exclusive set is refused at submit.
- A transaction holding one is single-tick (validate, chunks,
apply_once, commit in one slot;TooLargeabovesingle_tick_max_cells), so nothing changes the ECS between its validation and its commit.apply_oncecannot fail. Sections validate against the world before the transaction, so a check that depends on another section’s effect belongs in one section; queued transactions validate in turn against what earlier ones committed. - No chunks listed (an inventory move): no residency, locks, pins, previews,
snapshots, change log or
ChunkEdits, and nobuild.edit; it commits in the slot that validates it. Measured bytxn_non_chunk_section(target ≤ 5 µs for three sections). - Structural changes apply at commit through the funnel with
Cause::Transaction { batch, mod_index }; their lifecycle events reach observers at F4. A later transaction in the same slot sees them. TxnCommitLogrecords every commit that changed a cell, a block component or ran a non-chunk section, with all section kinds (CommittedTxn::sections), in two rings of 256: chunk-touching commits (chunk_since, read bylast_at) and ECS-only commits (ecs_since), so inventory traffic never evicts block history.sincemerges both in commit order.- Component cells: a non-chunk section names the cells its
apply_onceupdates in place (component_cells); they must be resident and unlocked, and are neither locked nor snapshotted. - Undo records hold a section’s data only if its
record()writes bytes. Container contents are never recorded (the items program’s sections enforce it).
Removal and add handlers
A block component declaration may name on_remove: Handler(kind) and
on_add: Handler(kind) (items request #482). Any transaction that removes
such a record (a fill, a revert or reapply, a section’s explicit removal, a
cell that stops matching applies_to) or creates one gets the handler
section of that kind appended, unless it already holds one, so the removal
and its spill, or the place and its machine spawn, commit together.
- Constructors are registered per kind:
transaction::register_component_handler(world, kind, constructor). The constructor receives the events that name its kind (HandlerCall) and must build a non-chunk section of that kind; anything else refuses the transaction. - An unregistered kind refuses the transaction with
HandlerMissing(kind): the engine never drops a record whose handler cannot run. - Handler sections validate after the preview and read the events
(
ValidateCx::component_events,ApplyOnceCx::component_events) and the chunk changes (ApplyOnceCx::chunk_changes) in the same commit. - A spill that mints (returns
moves_value) makes the whole transaction refuse an undo record; one that only moves contents keeps it, and the record leaves contents out (undo: Exclude), so undo restores an empty container.
Undo records and tombstones
RecordMode::ToStore(key) writes the MUR1 record under key: block cells,
and the block components that are declared, unsealed and undo: Include.
Sealed and excluded components are never captured, and a revert or reapply
whose record names a sealed key is refused (SealedComponent), so no undo
writes a sealed component’s contents. A transaction holding a section that
moves value (TxnSection::moves_value, an item flow) refuses ToStore
(UndoForbidden); a caller whose history numbers every step passes
RecordMode::Tombstone(key) instead. The engine then writes a tombstone
under the key (the record header, no cell data) with
UndoRecordStore::write_tombstone: kept with the same scope and retention
as records, charged to the owner’s quota like a record (a full quota refuses
the transaction with Quota), and skipped by history listings
(record::is_tombstone). Reverting or reapplying a tombstone fails
Unsupported; a key that never existed fails UnknownTarget.
Guest transactions
A mod’s server half submits transactions through
manifold:world/block-transaction (Enki B §2.2), published in the open
0.2 track:
| Function | Does |
|---|---|
submit(options, ops) -> result<batch-id, submit-error> | one atomic transaction: txn-options (volume, actor, requires, unloaded policy, neighbour updates, undo record mode, reveal, label) and the framed TxnOp list |
take-results() -> list<u8> | this mod’s TxnResults (schema txn-results) |
cancel(batch-id) -> bool | cancel one of this mod’s transactions before its first chunk applies |
supports-op(op-kind) -> bool | whether this host implements an op |
ops follows the core/ops framing (contract foundation §5.3): a sequence
of [u32 length][postcard TxnOp] records, encoded and decoded by the one op
codec every op family shares
(contract::ops (crates/manifold-mod-types/src/contract/ops.rs),
encode_ops/decode_ops with txn::OP_KINDS).
A TxnOp’s variant index is its op kind (0 fill … 10 expect), and the whole
op set is published; only broken framing fails the call (malformed(index)),
while an op the host does not implement or a malformed record rejects the
transaction in its result (Unsupported(kind), Malformed). The host
submits during the call: the orchestrator lends every instance the world for
its systems (Mod contract, the world loan), and
the call lowers to transaction::submit_in with Requester::Mod(load-order index), the guest’s actor (player or mod-self, whose mod id the host
fills in) and the owner it implies
(transaction::guest (crates/manifold-server-state/src/transaction/guest.rs)).
An op the engine cannot run rejects the transaction through a section that
fails validation, after the engine’s own volume, actor and node checks; at
most 4,096 ops per transaction (too-many-ops). cancel during a guest call
is recorded and applied at the start of the next apply slot, before anything
validates, and frees the actor’s one in-flight slot at once. supports-op
answers through the engine’s port, so it reads false outside a system. Undo records and revert/reapply keys are
blob-keys in the calling mod’s namespace. The SDK builds the op list:
manifold_mod_substrate::blocks (crates/manifold-mod-substrate/src/blocks.rs).
Reads go through manifold:world/block-read on both sides: get-block,
read-region, chunk-states, registry-snapshot and registry-hash, live
on the server and from the streamed chunk cache on the client. A read never
loads a chunk: non-resident cells read as the caller’s unknown-value and
their chunks are listed in missing. The client answers only for the space
its chunk cache holds, the player’s (ClientSpace); another space reads as
missing (volume-not-found). Neither side can see a chunk being loaded, so
chunk-states reports resident or absent. A read box holds at most
16,777,216 cells; layers must be empty until Enki A’s layers exist
(unknown-layer).
Cell buffers
A cell buffer is the values of an inclusive box, x fastest, then y, then z
(the chunk order). Each cell is a little-endian block value of the buffer’s
value-width: 2 bytes today, 4 if Enki A widens values. A read-region
result holds one plane per requested layer, solid first, concatenated; a
TxnOp::Expect or TxnOp::Write buffer holds one plane. Readers check the
width.
| Offset | Size | Field |
|---|---|---|
2 * i (width 2) or 4 * i (width 4) | 2 or 4 | value of cell i = x + y * sx + z * sx * sy, little-endian |
Registry snapshot
registry-snapshot returns the compiled block model in Enki A’s snapshot
format (manifold-block-model::snapshot (crates/manifold-block-model/src/snapshot.rs));
a mod rebuilds the model with BlockModel::from_snapshot and checks the
format before decoding anything else. registry-hash is its SHA-256, 32 raw
bytes. Format 1, all integers little-endian:
| Field | Size |
|---|---|
magic MBMS | 4 |
snapshot format (u16, 1) | 2 |
value count (u32) | 4 |
per value: state string length (u32), then the UTF-8 state string | 4 + n |
Guarantees
- Nothing is written per cell outside the chunk writer; capture, logging and replication cost is per chunk.
- Unknown blocks keep their names through fill, revert and reapply.
- Revert and reapply are compare-and-set over the record, block components
included; any mismatch is a
Conflictand nothing changes. Components declaredundo: Excludeare never recorded or restored. - Clients receive one
S2C::ChunkEditsentry per changed chunk they hold (uniform, box or lz4 runs) and remesh and relight the chunk once. - The browser worker runs the same engine through the same
step_tick.
Not yet
Loading unloaded chunks (unloaded = load), reveal at commit, parallel
apply, the per-connection edit backlog, the in-flight ChunkLoad race
(edits for chunks a client does not hold yet are dropped; the chunk streams
fresh), protections and reviews, per-player build.txn-cells.max, the
single-edit rate limit and reach check (Enki B §3.4), the write,
write-sparse, write-if-unchanged, map, component and props ops
(published, answered Unsupported), and the per-system blocks(read) /
blocks(write) declarations that would refuse undeclared guest reads and
transactions (not-declared): they arrive with the shared domain-access
field.
Tests
manifold-server-state unit tests transaction::tests (with
transaction::tests::components for components, handlers and undo rules),
transaction::hooks, transaction::record,
block_world_apply and console::world_edit_commands; manifold-host-core
suite step_tick_block_edits; manifold-server suite txn_two_client,
block_edit and block_world_roundtrip; the benches txn_bulk_section and
txn_non_chunk_section. Guest transactions and reads: manifold-wasm-host-core
capability::{block_transaction, block_read}, manifold-host-core suite
platform_blocks, manifold-server platform_smoke_e2e and the platform
case of web_parity.