Files
dingo 41237bd289
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m53s
Foundation / checks (checks) (push) Failing after 4m11s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 4m28s
Foundation / checks (network) (push) Canceled after 6m39s
Foundation / checks (client) (push) Canceled after 8m43s
Add bounded funded-birth batch replay (M11.2c-2a)
2026-10-10 04:51:30 -04:00

46 lines
2.3 KiB
C++

#pragma once
#include "evo/server/lifecycle/primitive_lives.hpp"
namespace evo::server {
// Creation-only trace. Publication binds this header to the committed predecessor.
// Generation records authorization evidence; replay grants no authority.
struct PrimitiveBatchHeader {
std::uint64_t world{}, region{}, frame{};
std::array<std::uint8_t, 16> predecessor{};
std::array<std::uint8_t, 32> predecessor_digest{};
std::uint64_t begin_tick{}, end_tick{};
friend bool operator==(const PrimitiveBatchHeader&, const PrimitiveBatchHeader&) = default;
};
struct PrimitiveBirth {
LifeRequest request{};
std::uint64_t identity{}, generation{};
Tick born{};
friend bool operator==(const PrimitiveBirth&, const PrimitiveBirth&) = default;
};
struct PrimitiveBatch {
PrimitiveBatchHeader header{};
std::vector<PrimitiveBirth> births;
friend bool operator==(const PrimitiveBatch&, const PrimitiveBatch&) = default;
};
inline constexpr std::uint32_t primitive_batch_format = 1;
inline constexpr std::size_t primitive_batch_header_bytes = 112;
inline constexpr std::size_t primitive_birth_bytes = 48;
inline constexpr std::size_t max_primitive_batch_bytes =
primitive_batch_header_bytes + primitive_birth_bytes * max_primitive_lives;
enum class PrimitiveBatchError : std::uint8_t { format, version, scope, state };
// 1..64 ticks, <=256 births, ordered by (born, account, request), unique accounts
// and identities. Empty batches advance the owner's checkpoint tick without
// progressing biology. No implicit reserve consumption or timer advancement.
[[nodiscard]] std::expected<std::vector<std::uint8_t>, PrimitiveBatchError>
encode_primitive_batch(const PrimitiveBatch& batch);
[[nodiscard]] std::expected<PrimitiveBatch, PrimitiveBatchError>
decode_primitive_batch(std::span<const std::uint8_t> bytes);
// Clones the base and applies every funded birth; all-or-nothing. Caller MUST
// match predecessor/digest/begin tick to its trusted committed manifest, then
// compare replayed payload bytes with the proposed checkpoint. Allocation uses
// the same value in each of the four distinct world identity namespaces.
[[nodiscard]] std::expected<std::unique_ptr<PrimitiveLives>, PrimitiveBatchError>
replay_primitive_batch(const PrimitiveLives& base, const PrimitiveBatch& batch);
} // namespace evo::server