Add cellular mutation replay trace v3
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 2m9s
Foundation / checks (ecs) (push) Successful in 2m2s
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 (client) (push) Canceled after 3m11s
Foundation / checks (postgres) (push) Canceled after 1m3s
Foundation / checks (network) (push) Canceled after 1m9s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 2m9s
Foundation / checks (ecs) (push) Successful in 2m2s
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 (client) (push) Canceled after 3m11s
Foundation / checks (postgres) (push) Canceled after 1m3s
Foundation / checks (network) (push) Canceled after 1m9s
This commit is contained in:
@@ -18,6 +18,9 @@ struct CellularBatchHeader {
|
||||
std::uint64_t begin_tick{}, end_tick{};
|
||||
friend bool operator==(const CellularBatchHeader&, const CellularBatchHeader&) = default;
|
||||
};
|
||||
inline constexpr std::uint32_t cellular_batch_format = 3;
|
||||
inline constexpr std::uint32_t cellular_batch_v2_format = 2;
|
||||
inline constexpr std::uint32_t cellular_batch_legacy_format = 1;
|
||||
struct CellularTickIntents {
|
||||
// One intention for each life alive at the start of this tick, sorted by life_id.
|
||||
std::vector<CellularLifeIntent> lives;
|
||||
@@ -29,11 +32,15 @@ struct CellularTickIntents {
|
||||
friend bool operator==(const Birth&, const Birth&) = default;
|
||||
};
|
||||
std::vector<Birth> births;
|
||||
// Choices accepted against the preceding checkpoint and scheduled for this tick.
|
||||
// The successor identity is durably reserved before the batch is replayed.
|
||||
std::vector<CellularMutationSelection> mutations;
|
||||
friend bool operator==(const CellularTickIntents&, const CellularTickIntents&) = default;
|
||||
};
|
||||
struct CellularBatch {
|
||||
CellularBatchHeader header{};
|
||||
std::vector<CellularTickIntents> ticks;
|
||||
std::uint32_t format_version{cellular_batch_format};
|
||||
friend bool operator==(const CellularBatch&, const CellularBatch&) = default;
|
||||
};
|
||||
struct CellularActionRecord {
|
||||
@@ -42,22 +49,38 @@ struct CellularActionRecord {
|
||||
std::array<std::uint8_t, 24> input{};
|
||||
friend bool operator==(const CellularActionRecord&, const CellularActionRecord&) = default;
|
||||
};
|
||||
struct CellularMutationActionInput {
|
||||
std::uint64_t life_id{}, event_index{}, offer_tick{};
|
||||
std::uint16_t operator_id{};
|
||||
friend bool operator==(const CellularMutationActionInput&,
|
||||
const CellularMutationActionInput&) = default;
|
||||
};
|
||||
struct CellularMutationActionRecord {
|
||||
std::array<std::uint8_t, 16> account{};
|
||||
std::uint64_t action_id{}, tick{};
|
||||
CellularMutationActionInput input{};
|
||||
friend bool operator==(const CellularMutationActionRecord&,
|
||||
const CellularMutationActionRecord&) = default;
|
||||
};
|
||||
|
||||
inline constexpr std::uint32_t cellular_batch_format = 2;
|
||||
inline constexpr std::uint32_t cellular_batch_legacy_format = 1;
|
||||
inline constexpr std::size_t cellular_batch_header_bytes = 112;
|
||||
inline constexpr std::size_t cellular_batch_tick_header_bytes = 8;
|
||||
inline constexpr std::size_t cellular_batch_v1_tick_header_bytes = 4;
|
||||
inline constexpr std::size_t cellular_batch_v2_tick_header_bytes = 8;
|
||||
inline constexpr std::size_t cellular_batch_tick_header_bytes = 16;
|
||||
inline constexpr std::size_t cellular_batch_intent_bytes = 24;
|
||||
inline constexpr std::size_t cellular_batch_birth_bytes = 40;
|
||||
inline constexpr std::size_t cellular_batch_mutation_bytes = 40;
|
||||
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 + cellular_batch_birth_bytes));
|
||||
(cellular_batch_intent_bytes + cellular_batch_birth_bytes +
|
||||
cellular_batch_mutation_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;
|
||||
inline constexpr std::size_t cellular_mutation_action_record_bytes = 64;
|
||||
enum class CellularActionBlockError : std::uint8_t { format, mismatch };
|
||||
|
||||
// Canonical replay input: one bounded, life-ID-ordered intention set per tick.
|
||||
@@ -76,9 +99,19 @@ encode_cellular_action_block(std::span<const CellularActionRecord> actions,
|
||||
[[nodiscard]] std::expected<std::vector<CellularActionRecord>, CellularActionBlockError>
|
||||
decode_cellular_action_block(std::span<const std::uint8_t> bytes, std::uint64_t begin_tick,
|
||||
std::uint64_t end_tick);
|
||||
[[nodiscard]] std::expected<std::vector<std::uint8_t>, CellularActionBlockError>
|
||||
encode_cellular_mutation_action_block(std::span<const CellularMutationActionRecord> actions,
|
||||
std::uint64_t begin_tick, std::uint64_t end_tick);
|
||||
[[nodiscard]] std::expected<std::vector<CellularMutationActionRecord>, CellularActionBlockError>
|
||||
decode_cellular_mutation_action_block(std::span<const std::uint8_t> 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<void, CellularActionBlockError>
|
||||
match_cellular_actions_to_trace(const CellularLives& predecessor, const CellularBatch& batch,
|
||||
std::span<const CellularActionRecord> actions);
|
||||
[[nodiscard]] std::expected<void, CellularActionBlockError>
|
||||
match_cellular_mutation_actions_to_trace(const CellularLives& predecessor,
|
||||
const CellularBatch& batch,
|
||||
std::span<const CellularMutationActionRecord> actions);
|
||||
} // namespace evo::server
|
||||
|
||||
@@ -58,6 +58,21 @@ struct CellularLifeIntent {
|
||||
biology::CellularStepIntent intent{};
|
||||
auto operator<=>(const CellularLifeIntent&) const = default;
|
||||
};
|
||||
struct CellularMutationSelection {
|
||||
std::uint64_t life_id{}, event_index{}, offer_tick{}, successor_id{};
|
||||
std::uint16_t operator_id{};
|
||||
auto operator<=>(const CellularMutationSelection&) const = default;
|
||||
};
|
||||
enum class CellularMutationResult : std::uint8_t { applied, life_died, insufficient_funding };
|
||||
struct CellularMutationExecution {
|
||||
std::uint64_t life_id{}, successor_id{};
|
||||
CellularMutationResult result{};
|
||||
auto operator<=>(const CellularMutationExecution&) const = default;
|
||||
};
|
||||
struct CellularTickExecution {
|
||||
biology::CellularRegionStepCandidate step;
|
||||
std::vector<CellularMutationExecution> mutations;
|
||||
};
|
||||
struct CellularLifeTickFeedback {
|
||||
std::uint64_t life_id{}, tick{};
|
||||
accounting::Inventory reserve;
|
||||
@@ -156,6 +171,11 @@ class CellularLives {
|
||||
// this owner byte-for-byte unchanged.
|
||||
[[nodiscard]] std::expected<biology::CellularRegionStepCandidate, CellularLivesError>
|
||||
advance_tick(std::span<const CellularLifeIntent> intents);
|
||||
// Mutation selections are validated against the predecessor offer, then applied
|
||||
// after the normal life step and before births on the same advancing tick.
|
||||
[[nodiscard]] std::expected<CellularTickExecution, CellularLivesError>
|
||||
advance_tick_with_mutations(std::span<const CellularLifeIntent> intents,
|
||||
std::span<const CellularMutationSelection> selections);
|
||||
|
||||
private:
|
||||
struct State;
|
||||
|
||||
Reference in New Issue
Block a user