#pragma once #include "evo/server/lifecycle/cellular_lives.hpp" #include #include #include #include #include #include #include namespace evo::server { struct CellularBatchHeader { std::uint64_t world{}, region{}, frame{}; std::array predecessor{}; std::array predecessor_digest{}; std::uint64_t begin_tick{}, end_tick{}; friend bool operator==(const CellularBatchHeader&, const CellularBatchHeader&) = default; }; struct CellularTickIntents { // One intention for each life alive at the start of this tick, sorted by life_id. std::vector lives; friend bool operator==(const CellularTickIntents&, const CellularTickIntents&) = default; }; struct CellularBatch { CellularBatchHeader header{}; std::vector ticks; friend bool operator==(const CellularBatch&, const CellularBatch&) = default; }; struct CellularActionRecord { std::array account{}; std::uint64_t action_id{}; std::array input{}; friend bool operator==(const CellularActionRecord&, const CellularActionRecord&) = default; }; inline constexpr std::uint32_t cellular_batch_format = 1; inline constexpr std::size_t cellular_batch_header_bytes = 112; inline constexpr std::size_t cellular_batch_tick_header_bytes = 4; inline constexpr std::size_t cellular_batch_intent_bytes = 24; inline constexpr std::size_t max_cellular_batch_ticks = 64; inline constexpr std::size_t max_cellular_batch_bytes = cellular_batch_header_bytes + max_cellular_batch_ticks * (cellular_batch_tick_header_bytes + biology::max_cellular_tick_lives * cellular_batch_intent_bytes); enum class CellularBatchError : std::uint8_t { format, version, scope, state }; inline constexpr std::size_t cellular_action_record_bytes = 48; inline constexpr std::size_t max_cellular_action_records = 1'024; enum class CellularActionBlockError : std::uint8_t { format, mismatch }; // Canonical replay input: one bounded, life-ID-ordered intention set per tick. [[nodiscard]] std::expected, CellularBatchError> encode_cellular_batch(const CellularBatch& batch); [[nodiscard]] std::expected decode_cellular_batch(std::span bytes); // Replays from an immutable predecessor snapshot. The caller must first bind the // header identity, predecessor commit/digest and tick range to trusted manifests. // Every tick must cover its living set; the caller compares the returned snapshot. [[nodiscard]] std::expected, CellularBatchError> replay_cellular_batch(const CellularLives& base, const CellularBatch& batch); [[nodiscard]] std::expected, CellularActionBlockError> encode_cellular_action_block(std::span actions, std::uint64_t begin_tick, std::uint64_t end_tick); [[nodiscard]] std::expected, CellularActionBlockError> decode_cellular_action_block(std::span bytes, std::uint64_t begin_tick, std::uint64_t end_tick); // Every durable action must match the canonical input for that account's life // in the corresponding replay tick. An action cannot create a life or intent. [[nodiscard]] std::expected match_cellular_actions_to_trace(const CellularLives& predecessor, const CellularBatch& batch, std::span actions); } // namespace evo::server