Record cellular births in replay traces
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (ecs) (push) Successful in 2m0s
Foundation / checks (postgres) (push) Failing after 52s
Foundation / checks (tsan) (push) Failing after 33s
Foundation / checks (network) (push) Failing after 3m4s
Foundation / checks (client) (push) Failing after 4m22s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (ecs) (push) Successful in 2m0s
Foundation / checks (postgres) (push) Failing after 52s
Foundation / checks (tsan) (push) Failing after 33s
Foundation / checks (network) (push) Failing after 3m4s
Foundation / checks (client) (push) Failing after 4m22s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <bit>
|
||||
#include <optional>
|
||||
#include <ranges>
|
||||
#include <set>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
@@ -39,8 +40,11 @@ bool valid_intent(const CellularLifeIntent& life) {
|
||||
step.movement.y <= movement_limit;
|
||||
}
|
||||
bool valid_ticks(std::span<const CellularTickIntents> ticks) {
|
||||
std::set<std::uint64_t> identities;
|
||||
std::set<LifeAccount> accounts;
|
||||
for (const auto& tick : ticks) {
|
||||
if (tick.lives.size() > biology::max_cellular_tick_lives)
|
||||
if (tick.lives.size() > biology::max_cellular_tick_lives ||
|
||||
tick.births.size() > biology::max_cellular_tick_lives)
|
||||
return false;
|
||||
for (std::size_t i = 0; i < tick.lives.size(); ++i) {
|
||||
const auto& life = tick.lives[i];
|
||||
@@ -48,6 +52,17 @@ bool valid_ticks(std::span<const CellularTickIntents> ticks) {
|
||||
(i > 0 && tick.lives[i - 1].life_id >= life.life_id))
|
||||
return false;
|
||||
}
|
||||
for (std::size_t i = 0; i < tick.births.size(); ++i) {
|
||||
const auto& birth = tick.births[i];
|
||||
if (all_zero(birth.account) || birth.request == 0 || birth.generation == 0 ||
|
||||
birth.identity == 0 ||
|
||||
(i > 0 && std::tie(tick.births[i - 1].account,
|
||||
tick.births[i - 1].request) >=
|
||||
std::tie(birth.account, birth.request)))
|
||||
return false;
|
||||
if (!identities.insert(birth.identity).second || !accounts.insert(birth.account).second)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -107,7 +122,8 @@ encode_cellular_batch(const CellularBatch& batch) {
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
std::size_t size = cellular_batch_header_bytes;
|
||||
for (const auto& tick : batch.ticks) {
|
||||
const auto records = tick.lives.size() * cellular_batch_intent_bytes;
|
||||
const auto records = tick.lives.size() * cellular_batch_intent_bytes +
|
||||
tick.births.size() * cellular_batch_birth_bytes;
|
||||
if (records > max_cellular_batch_bytes - size - cellular_batch_tick_header_bytes)
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
size += cellular_batch_tick_header_bytes + records;
|
||||
@@ -129,8 +145,15 @@ encode_cellular_batch(const CellularBatch& batch) {
|
||||
put(out, 0, 4);
|
||||
for (const auto& tick : batch.ticks) {
|
||||
put(out, tick.lives.size(), 4);
|
||||
put(out, tick.births.size(), 4);
|
||||
for (const auto& life : tick.lives)
|
||||
put_intent(out, life);
|
||||
for (const auto& birth : tick.births) {
|
||||
out.insert(out.end(), birth.account.begin(), birth.account.end());
|
||||
put(out, birth.request, 8);
|
||||
put(out, birth.generation, 8);
|
||||
put(out, birth.identity, 8);
|
||||
}
|
||||
}
|
||||
if (out.size() != size)
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
@@ -142,7 +165,9 @@ decode_cellular_batch(std::span<const std::uint8_t> bytes) {
|
||||
if (bytes.size() < cellular_batch_header_bytes || bytes.size() > max_cellular_batch_bytes ||
|
||||
!std::ranges::equal(bytes.first(magic.size()), magic))
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
if (get(bytes, 8, 4) != cellular_batch_format || get(bytes, 12, 4) != 4)
|
||||
const auto format = get(bytes, 8, 4);
|
||||
if ((format != cellular_batch_format && format != cellular_batch_legacy_format) ||
|
||||
get(bytes, 12, 4) != 4)
|
||||
return std::unexpected{CellularBatchError::version};
|
||||
if (get(bytes, 108, 4) != 0)
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
@@ -166,12 +191,21 @@ decode_cellular_batch(std::span<const std::uint8_t> bytes) {
|
||||
std::size_t offset = cellular_batch_header_bytes;
|
||||
out.ticks.reserve(static_cast<std::size_t>(tick_count));
|
||||
for (std::uint64_t tick_index = 0; tick_index < tick_count; ++tick_index) {
|
||||
if (bytes.size() - offset < cellular_batch_tick_header_bytes)
|
||||
const auto tick_header_bytes = format == cellular_batch_format
|
||||
? cellular_batch_tick_header_bytes
|
||||
: sizeof(std::uint32_t);
|
||||
if (bytes.size() - offset < tick_header_bytes)
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
const auto count = get(bytes, offset, 4);
|
||||
offset += cellular_batch_tick_header_bytes;
|
||||
offset += 4;
|
||||
std::uint64_t birth_count{};
|
||||
if (format == cellular_batch_format) {
|
||||
birth_count = get(bytes, offset, 4);
|
||||
offset += 4;
|
||||
}
|
||||
if (count > biology::max_cellular_tick_lives ||
|
||||
count > (bytes.size() - offset) / cellular_batch_intent_bytes)
|
||||
count > (bytes.size() - offset) / cellular_batch_intent_bytes ||
|
||||
birth_count > biology::max_cellular_tick_lives)
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
CellularTickIntents step;
|
||||
step.lives.reserve(static_cast<std::size_t>(count));
|
||||
@@ -198,6 +232,25 @@ decode_cellular_batch(std::span<const std::uint8_t> bytes) {
|
||||
step.lives.push_back(life);
|
||||
offset += cellular_batch_intent_bytes;
|
||||
}
|
||||
if (birth_count > (bytes.size() - offset) / cellular_batch_birth_bytes)
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
step.births.reserve(static_cast<std::size_t>(birth_count));
|
||||
for (std::uint64_t i = 0; i < birth_count; ++i) {
|
||||
const auto record = bytes.subspan(offset, cellular_batch_birth_bytes);
|
||||
CellularTickIntents::Birth birth;
|
||||
std::ranges::copy(record.first(16), birth.account.begin());
|
||||
birth.request = get(record, 16, 8);
|
||||
birth.generation = get(record, 24, 8);
|
||||
birth.identity = get(record, 32, 8);
|
||||
if (all_zero(birth.account) || birth.request == 0 || birth.generation == 0 ||
|
||||
birth.identity == 0 ||
|
||||
(!step.births.empty() &&
|
||||
std::tie(step.births.back().account, step.births.back().request) >=
|
||||
std::tie(birth.account, birth.request)))
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
step.births.push_back(birth);
|
||||
offset += cellular_batch_birth_bytes;
|
||||
}
|
||||
out.ticks.push_back(std::move(step));
|
||||
}
|
||||
if (offset != bytes.size())
|
||||
@@ -217,9 +270,19 @@ replay_cellular_batch(const CellularLives& base, const CellularBatch& batch) {
|
||||
base.tick());
|
||||
if (!replay)
|
||||
return std::unexpected{CellularBatchError::state};
|
||||
for (const auto& tick : batch.ticks)
|
||||
for (const auto& tick : batch.ticks) {
|
||||
if (!(*replay)->advance_tick(tick.lives))
|
||||
return std::unexpected{CellularBatchError::state};
|
||||
for (const auto& birth : tick.births) {
|
||||
const LifeRequest request{birth.account, birth.request};
|
||||
const LifeAllocation allocation{birth.identity, birth.identity, birth.identity,
|
||||
birth.identity, {(*replay)->tick()}};
|
||||
auto born = (*replay)->birth_candidate(request, allocation);
|
||||
if (!born)
|
||||
return std::unexpected{CellularBatchError::state};
|
||||
*replay = std::move(*born);
|
||||
}
|
||||
}
|
||||
return std::move(*replay);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user