From cc039b76e2572e50fa261676d3a2e28f48d2b545 Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 11 Oct 2026 09:06:22 -0400 Subject: [PATCH] Format cellular reservation adapter --- include/evo/server/cellular_session_batch.hpp | 9 ++- src/server/session/cellular_session_batch.cpp | 55 +++++++++---------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/include/evo/server/cellular_session_batch.hpp b/include/evo/server/cellular_session_batch.hpp index dee8955..21b899c 100644 --- a/include/evo/server/cellular_session_batch.hpp +++ b/include/evo/server/cellular_session_batch.hpp @@ -41,11 +41,10 @@ struct CellularSessionTick { // behavior; this adapter binds each action to the one live account-owned life and preserves // the canonical input needed for publication and replay. [[nodiscard]] std::expected -prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick, - std::span baseline, - std::span actions, - std::span - mutations = {}); +prepare_cellular_session_tick( + const CellularLives& state, std::uint64_t tick, std::span baseline, + std::span actions, + std::span mutations = {}); // Builds one bounded publication from the last durable head. Its working copy is private; // only the host may publish, and callers must discard it after uncertainty until the host diff --git a/src/server/session/cellular_session_batch.cpp b/src/server/session/cellular_session_batch.cpp index c4f634e..513da92 100644 --- a/src/server/session/cellular_session_batch.cpp +++ b/src/server/session/cellular_session_batch.cpp @@ -102,8 +102,8 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick, reservation.target_tick != tick || life_id == 0 || event_index == 0 || offer_tick == 0 || offer_tick >= tick || operator_id == 0) return std::unexpected{CellularSessionBatchError::mutation}; - const auto life = std::ranges::find(state.lives(), reservation.account, - &CellularOwnedLife::account); + const auto life = + std::ranges::find(state.lives(), reservation.account, &CellularOwnedLife::account); if (life == state.lives().end() || life->identity.life != life_id || life->mutation.event_index != event_index || life->mutation.offer_tick != offer_tick || !life->mutation.offer || @@ -112,10 +112,11 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick, })) return std::unexpected{CellularSessionBatchError::mutation}; - if (std::ranges::any_of(prepared.intents.mutations, [&](const auto& previous) { - return previous.life_id == life_id || - previous.successor_id == reservation.successor_identity; - }) || + if (std::ranges::any_of(prepared.intents.mutations, + [&](const auto& previous) { + return previous.life_id == life_id || + previous.successor_id == reservation.successor_identity; + }) || std::ranges::any_of(prepared.mutation_actions, [&](const auto& previous) { return previous.account == reservation.account && previous.action_id == reservation.action_id; @@ -123,17 +124,17 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick, return std::unexpected{CellularSessionBatchError::duplicate_mutation}; prepared.intents.mutations.push_back( {life_id, event_index, offer_tick, reservation.successor_identity, operator_id}); - prepared.mutation_actions.push_back( - {reservation.account, reservation.action_id, tick, - {life_id, event_index, offer_tick, operator_id}}); + prepared.mutation_actions.push_back({reservation.account, + reservation.action_id, + tick, + {life_id, event_index, offer_tick, operator_id}}); } std::ranges::sort(prepared.intents.mutations, {}, &CellularMutationSelection::life_id); - std::ranges::sort(prepared.mutation_actions, - [](const auto& left, const auto& right) { - if (left.account != right.account) - return left.account < right.account; - return left.action_id < right.action_id; - }); + std::ranges::sort(prepared.mutation_actions, [](const auto& left, const auto& right) { + if (left.account != right.account) + return left.account < right.account; + return left.action_id < right.action_id; + }); return prepared; } @@ -159,13 +160,11 @@ CellularSessionBatchBuilder::create(const CellularLives& committed_state, return builder; } -std::expected -CellularSessionBatchBuilder::append(std::uint64_t tick, - std::span baseline, - std::span actions, - std::span births, - std::span - mutations) { +std::expected CellularSessionBatchBuilder::append( + std::uint64_t tick, std::span baseline, + std::span actions, + std::span births, + std::span mutations) { if (batch_.ticks.size() >= max_cellular_batch_ticks) return std::unexpected{CellularSessionBatchError::batch_full}; if (actions_.size() + actions.size() > max_cellular_action_records) @@ -182,8 +181,7 @@ CellularSessionBatchBuilder::append(std::uint64_t tick, return std::unexpected{CellularSessionBatchError::duplicate_action}; for (const auto& action : prepared->mutation_actions) if (std::ranges::find_if(mutation_actions_, [&](const auto& previous) { - return previous.account == action.account && - previous.action_id == action.action_id; + return previous.account == action.account && previous.action_id == action.action_id; }) != mutation_actions_.end()) return std::unexpected{CellularSessionBatchError::duplicate_mutation}; if (births.size() > biology::max_cellular_tick_lives) @@ -210,8 +208,8 @@ CellularSessionBatchBuilder::append(std::uint64_t tick, auto next = CellularLives::restore(working_->snapshot(), working_->world(), working_->region(), working_->frame(), working_->tick()); - if (!next || !(*next)->advance_tick_with_mutations(prepared->intents.lives, - prepared->intents.mutations)) + if (!next || + !(*next)->advance_tick_with_mutations(prepared->intents.lives, prepared->intents.mutations)) return std::unexpected{CellularSessionBatchError::biology}; for (const auto& birth : prepared->intents.births) { @@ -235,9 +233,8 @@ CellularSessionBatchBuilder::append(std::uint64_t tick, prepared->mutation_actions.end()); return records; }(); - if (!encode_cellular_mutation_action_block(next_mutation_actions, - next_batch.header.begin_tick, - next_batch.header.end_tick)) + if (!encode_cellular_mutation_action_block(next_mutation_actions, next_batch.header.begin_tick, + next_batch.header.end_tick)) return std::unexpected{CellularSessionBatchError::mutation}; working_ = std::move(*next); batch_ = std::move(next_batch);