Skip to main content

Module reducer

Module reducer 

Source
Expand description

Pure separable reducer over canonical events.

apply_event is the deterministic state-transition function: given a Project and a StateEvent, it produces the next Project. It does not construct events, validate proposals, or call into network code. It is the inverse pole of proposals::apply_proposal, which prepares an event from a proposal and a current state.

Why this matters: v0 doctrine says “proposal → canonical event → reducer → replayable frontier state.” Until v0.3, the reducer step was implicit inside apply_proposal — replay was hash-walking, not reduction. Phase C of the v0.3 focusing run pulls the reducer out so a second implementation can independently reduce a canonical event log and produce byte-identical state.

Replay verification (replay_from_genesis + verify_replay) is the check that turns “state was claimed to result from these events” into “state demonstrably results from these events when re-derived from scratch.”

Structs§

ReplayVerification

Constants§

REDUCER_MUTATION_KINDS
Single source of truth for the event kinds whose mutations the reducer enforces. The no-op anchor frontier.created is excluded because it does not mutate state. Used by:

Functions§

apply_event
Apply one canonical event to state, mutating it in place.
apply_event_indexed
v0.105: indexed dispatch. Used by replay_from_genesis so the finding-id index gets built once and reused across every event. apply_event builds the index lazily for one-off callers.
build_finding_index
Build the finding-id index from the current state. O(N) once.
replay_from_genesis
Replay an entire event log from genesis state.
verify_replay
Verify that state.events, when replayed from state.findings_at_genesis (or a derived genesis if absent), produces a frontier whose finding states match the materialized state. Returns the diff if any.

Type Aliases§

FindingIndex
v0.105: per-replay finding-id index. Keys are content-addressed finding ids; values are positions into state.findings. Replay builds this once from genesis state and updates it in lockstep with finding.asserted pushes. Per-kind apply functions look up their target via idx.get(...) instead of an O(N) linear scan. findings are append-only in the substrate (no removals), so the index never goes stale; positions remain valid for the life of a replay.