feat(lifecycle): qualify portable maturing wildlife transfers
Foundation / checks (ecs) (push) Successful in 2m26s
Foundation / checks (deploy) (push) Successful in 4m12s
Foundation / checks (network) (push) Successful in 20m57s
Foundation / checks (client) (push) Successful in 22m9s
Foundation / checks (tsan) (push) Successful in 28m49s
Foundation / checks (postgres) (push) Successful in 1h5m2s
Foundation / checks (checks) (push) Successful in 1h17m42s
Foundation / postgres-tools (push) Successful in 1m10s
Foundation / server-image (push) Successful in 3m51s
Foundation / image (push) Successful in 4m54s

This commit is contained in:
dingo
2026-10-19 09:09:15 -04:00
parent 274f62cb89
commit 5e168d67c3
22 changed files with 412 additions and 41 deletions
@@ -6,6 +6,7 @@
namespace evo::server {
namespace {
constexpr std::array<std::uint8_t, 8> magic{'A', 'E', 'V', 'M', 'I', 'G', '0', '1'};
constexpr std::array<std::uint8_t, 8> maturing_magic{'A', 'E', 'V', 'M', 'I', 'G', '0', '2'};
template <typename T> bool zero(const T& bytes) {
return std::ranges::all_of(bytes, [](auto byte) { return byte == 0; });
}
@@ -23,7 +24,8 @@ bool valid_request(const CellularMigrationRequest& request) {
return std::ranges::adjacent_find(ids) == ids.end();
}
bool shape(const CellularMigrationTrace& trace) {
if ((trace.representation != CellularMigrationRepresentation::individual &&
if ((trace.format_version != 1 && trace.format_version != 2) ||
(trace.representation != CellularMigrationRepresentation::individual &&
trace.representation != CellularMigrationRepresentation::population) ||
trace.world == 0 || trace.frame == 0 || trace.tick == 0 || !valid_request(trace.request) ||
trace.transferred == accounting::Inventory{} || trace.members.empty() ||
@@ -55,6 +57,8 @@ record(const Owner& source, const Owner& destination, const CellularMigrationReq
CellularMigrationTrace trace{
representation, state(source)->world(), state(source)->frame(), state(source)->tick(),
request, execution->transferred, execution->members};
trace.format_version =
state(source)->rules_version() == cellular_lives_maturation_rules ? 2 : 1;
if (!shape(trace))
return std::unexpected(CellularMigrationError::format);
return Recorded{std::move(trace), std::move(*execution)};
@@ -65,6 +69,10 @@ auto replay(const Owner& source, const Owner& destination, const CellularMigrati
-> decltype(CellularMigration::prepare(source, destination, trusted.genome)) {
if (!shape(trace))
return std::unexpected(CellularMigrationError::format);
const auto version =
state(source)->rules_version() == cellular_lives_maturation_rules ? 2U : 1U;
if (trace.format_version != version)
return std::unexpected(CellularMigrationError::version);
if (trace.request != trusted || trace.representation != representation ||
trace.world != state(source)->world() || trace.frame != state(source)->frame() ||
trace.tick != state(source)->tick() || trusted.source.region != state(source)->region() ||
@@ -144,8 +152,8 @@ encode_migration_trace(const CellularMigrationTrace& trace) {
return std::unexpected(CellularMigrationError::format);
std::vector<std::uint8_t> bytes;
bytes.reserve(migration_trace_header_bytes + 8 * trace.members.size() + 8);
append(bytes, magic);
put(bytes, 1, 4);
append(bytes, trace.format_version == 1 ? magic : maturing_magic);
put(bytes, trace.format_version, 4);
put(bytes, static_cast<std::uint32_t>(trace.representation), 4);
for (const auto value : {trace.world, trace.frame, trace.tick, trace.request.genome})
put(bytes, value);
@@ -174,14 +182,17 @@ decode_migration_trace(std::span<const std::uint8_t> bytes) {
if (end.get() != checksum(bytes.first(bytes.size() - 8)))
return std::unexpected(CellularMigrationError::checksum);
Reader in(bytes);
if (in.array<8>() != magic)
const auto tag = in.array<8>();
if (tag != magic && tag != maturing_magic)
return std::unexpected(CellularMigrationError::format);
if (in.get(4) != 1)
const auto version = in.get(4);
if ((version != 1 && version != 2) || (version == 1 ? tag != magic : tag != maturing_magic))
return std::unexpected(CellularMigrationError::version);
const auto representation = in.get(4);
if (representation != 1 && representation != 2)
return std::unexpected(CellularMigrationError::version);
CellularMigrationTrace trace;
trace.format_version = static_cast<std::uint32_t>(version);
trace.representation = static_cast<CellularMigrationRepresentation>(representation);
trace.world = in.get();
trace.frame = in.get();