Queue births in cellular tick batches
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 40s
Foundation / checks (postgres) (push) Canceled after 0s
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 (network) (push) Canceled after 1m9s
Foundation / checks (client) (push) Canceled after 1m53s
Foundation / checks (ecs) (push) Canceled after 1m48s

This commit is contained in:
dingo
2026-10-11 00:51:05 -04:00
parent bb6e00ebca
commit 704ce0f2c8
5 changed files with 109 additions and 8 deletions
+46 -4
View File
@@ -101,7 +101,8 @@ CellularSessionBatchBuilder::create(const CellularLives& committed_state,
std::expected<void, CellularSessionBatchError>
CellularSessionBatchBuilder::append(std::uint64_t tick,
std::span<const CellularLifeIntent> baseline,
std::span<const network::CarriedAction> actions) {
std::span<const network::CarriedAction> actions,
std::span<const CellularTickIntents::Birth> births) {
if (batch_.ticks.size() >= max_cellular_batch_ticks)
return std::unexpected{CellularSessionBatchError::batch_full};
if (actions_.size() + actions.size() > max_cellular_action_records)
@@ -115,10 +116,51 @@ CellularSessionBatchBuilder::append(std::uint64_t tick,
previous.action_id == action.action_id;
}) != actions_.end())
return std::unexpected{CellularSessionBatchError::duplicate_action};
if (!working_->advance_tick(prepared->intents.lives))
if (births.size() > biology::max_cellular_tick_lives)
return std::unexpected{CellularSessionBatchError::invalid_birth};
prepared->intents.births.assign(births.begin(), births.end());
std::ranges::sort(prepared->intents.births, [](const auto& left, const auto& right) {
if (left.account != right.account)
return left.account < right.account;
return left.request < right.request;
});
for (std::size_t i = 0; i < prepared->intents.births.size(); ++i) {
const auto& birth = prepared->intents.births[i];
if (std::ranges::all_of(birth.account, [](std::uint8_t value) { return value == 0; }) ||
birth.request == 0 || birth.generation == 0 || birth.identity == 0)
return std::unexpected{CellularSessionBatchError::invalid_birth};
if (i > 0 && prepared->intents.births[i - 1].account == birth.account)
return std::unexpected{CellularSessionBatchError::duplicate_birth};
for (const auto& previous_tick : batch_.ticks)
if (std::ranges::any_of(previous_tick.births, [&](const auto& previous) {
return previous.account == birth.account ||
previous.identity == birth.identity;
}))
return std::unexpected{CellularSessionBatchError::duplicate_birth};
}
auto next = CellularLives::restore(working_->snapshot(), working_->world(),
working_->region(), working_->frame(), working_->tick());
if (!next || !(*next)->advance_tick(prepared->intents.lives))
return std::unexpected{CellularSessionBatchError::biology};
batch_.ticks.push_back(std::move(prepared->intents));
batch_.header.end_tick = tick;
for (const auto& birth : prepared->intents.births) {
const LifeRequest request{birth.account, birth.request};
const LifeAllocation allocation{birth.identity, birth.identity, birth.identity,
birth.identity, {tick}};
auto created = (*next)->birth_candidate(request, allocation);
if (!created)
return std::unexpected{CellularSessionBatchError::invalid_birth};
*next = std::move(*created);
}
auto next_batch = batch_;
next_batch.ticks.push_back(std::move(prepared->intents));
next_batch.header.end_tick = tick;
if (!encode_cellular_batch(next_batch))
return std::unexpected{CellularSessionBatchError::invalid_birth};
working_ = std::move(*next);
batch_ = std::move(next_batch);
actions_.insert(actions_.end(), prepared->actions.begin(), prepared->actions.end());
return {};
}