Deliver cellular tick diagnostics to owners
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (ecs) (push) Successful in 1m55s
Foundation / checks (postgres) (push) Failing after 52s
Foundation / checks (tsan) (push) Failing after 33s
Foundation / checks (network) (push) Failing after 3m1s
Foundation / checks (client) (push) Failing after 4m30s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-11 02:04:55 -04:00
parent fe03a0f8e4
commit ab9fbdec8f
16 changed files with 408 additions and 188 deletions
+47 -1
View File
@@ -125,7 +125,7 @@ void launcher(const PanelView& v, FormBuffers& form, PanelActions& a) {
ImGui::InputText("Dev CA file", form.authority.data(), form.authority.size()); ImGui::InputText("Dev CA file", form.authority.data(), form.authority.size());
ImGui::InputText("Grant bundle file", form.grants.data(), form.grants.size()); ImGui::InputText("Grant bundle file", form.grants.data(), form.grants.size());
bool cellular_trial = v.cellular_trial; bool cellular_trial = v.cellular_trial;
if (ImGui::Checkbox("Cellular trial (v8)", &cellular_trial)) if (ImGui::Checkbox("Cellular trial (v9)", &cellular_trial))
a.cellular_trial = cellular_trial; a.cellular_trial = cellular_trial;
const bool start = phase == LaunchPhase::choosing && ImGui::Button("Connect", {px(160), 0}); const bool start = phase == LaunchPhase::choosing && ImGui::Button("Connect", {px(160), 0});
ImGui::EndDisabled(); ImGui::EndDisabled();
@@ -411,6 +411,52 @@ void session(const PanelView& v, PanelActions& a) {
ImGui::Text("Life %llu, tick %llu", ImGui::Text("Life %llu, tick %llu",
static_cast<unsigned long long>(v.cellular_perception->life_identity), static_cast<unsigned long long>(v.cellular_perception->life_identity),
static_cast<unsigned long long>(v.cellular_perception->tick)); static_cast<unsigned long long>(v.cellular_perception->tick));
if (const auto& diagnostics = v.cellular_perception->diagnostics) {
const auto& matter = diagnostics->reserve_matter_fg;
ImGui::TextWrapped("Reserve %llu pJ | C %llu N %llu P %llu O %llu fg",
static_cast<unsigned long long>(diagnostics->reserve_energy_pj),
static_cast<unsigned long long>(matter[0]),
static_cast<unsigned long long>(matter[1]),
static_cast<unsigned long long>(matter[2]),
static_cast<unsigned long long>(matter[3]));
const auto movement_name = [&] {
switch (diagnostics->movement) {
case network::CellularMovementResult::not_reported:
return "unavailable";
case network::CellularMovementResult::no_movement:
return "no movement";
case network::CellularMovementResult::moved:
return "moved";
case network::CellularMovementResult::blocked:
return "blocked";
case network::CellularMovementResult::insufficient_energy:
return "insufficient reserve";
}
return "unknown";
};
const auto intake_name = [&] {
switch (diagnostics->intake) {
case network::CellularIntakeResult::not_reported:
return "unavailable";
case network::CellularIntakeResult::not_requested:
return "not feeding";
case network::CellularIntakeResult::acquired:
return "acquired";
case network::CellularIntakeResult::missing_patch:
return "patch missing";
case network::CellularIntakeResult::out_of_contact:
return "out of contact";
}
return "unknown";
};
ImGui::TextWrapped(
"Last tick: maintenance %llu pJ, movement %llu pJ; %s; feeding %s",
static_cast<unsigned long long>(diagnostics->maintenance_cost_pj),
static_cast<unsigned long long>(diagnostics->movement_cost_pj), movement_name(),
intake_name());
if (!diagnostics->has_tick_effects)
ImGui::TextDisabled("Tick effects unavailable after recovery.");
}
ImGui::TextDisabled("Steer with movement keys. Feeding continues until stopped."); ImGui::TextDisabled("Steer with movement keys. Feeding continues until stopped.");
if (v.cellular_feed_target && ImGui::SmallButton("Stop feeding")) if (v.cellular_feed_target && ImGui::SmallButton("Stop feeding"))
a.stop_feeding = true; a.stop_feeding = true;
+2 -2
View File
@@ -2,7 +2,7 @@
// M10.5c remote dev session for the engineering client (ADR-0093, over ADR-0091/0092 // M10.5c remote dev session for the engineering client (ADR-0093, over ADR-0091/0092
// sessions). Without EVO_CLIENT_NETWORK (a build without EVO_BUILD_QUIC) remote mode is // sessions). Without EVO_CLIENT_NETWORK (a build without EVO_BUILD_QUIC) remote mode is
// unavailable. The client only presents copies of replicated snapshots and sends bounded // unavailable. The client only presents copies of replicated snapshots and sends bounded
// bounded intentions; the explicit cellular trial uses reliable v8 actions and its // bounded intentions; the explicit cellular trial uses reliable v9 actions and its
// owner-filtered perception view. Grant bytes stay inside the session: each is handed to one // owner-filtered perception view. Grant bytes stay inside the session: each is handed to one
// connection and wiped here; never printed, shown or persisted. // connection and wiped here; never printed, shown or persisted.
// //
@@ -413,7 +413,7 @@ class RemoteSession {
return false; return false;
client::RegionSessionClientConfig config; client::RegionSessionClientConfig config;
if (cellular_trial_) if (cellular_trial_)
config.protocol_version = network::session_protocol_v8; config.protocol_version = network::session_protocol_v9;
const auto route = routes_.find(target_region_); const auto route = routes_.find(target_region_);
config.transport = route != routes_.end() ? route->second : transport_; config.transport = route != routes_.end() ? route->second : transport_;
if (ticket_) { // A handoff: the ticket replaces a grant, once. if (ticket_) { // A handoff: the ticket replaces a grant, once.
+44 -2
View File
@@ -25,8 +25,8 @@
namespace evo::server_app { namespace evo::server_app {
// Profile-4 network boundary. Biology and persistence remain owned by the cellular host; // Profile-4 network boundary. Biology and persistence remain owned by the cellular host;
// this bridge handles admission, v7/v8 action receipts, public cell replication and // this bridge handles admission, v7-v9 action receipts, public cell replication and
// owner-filtered v8 perception. // owner-filtered v8/v9 perception.
class CellularBridge { class CellularBridge {
public: public:
static std::optional<CellularBridge> open(const M10Options& options, static std::optional<CellularBridge> open(const M10Options& options,
@@ -177,6 +177,48 @@ class CellularBridge {
network::CellularPerception view; network::CellularPerception view;
view.tick = tick; view.tick = tick;
view.life_identity = life.identity.life; view.life_identity = life.identity.life;
network::CellularLifeDiagnostics diagnostics;
diagnostics.reserve_energy_pj = life.reserve.energy.value;
for (std::size_t i = 0; i < diagnostics.reserve_matter_fg.size(); ++i)
diagnostics.reserve_matter_fg[i] = life.reserve.matter[i].value;
const auto feedback =
std::ranges::lower_bound(state.last_tick_feedback(), life.identity.life, {},
&server::CellularLifeTickFeedback::life_id);
if (feedback != state.last_tick_feedback().end() &&
feedback->life_id == life.identity.life && feedback->tick == tick) {
diagnostics.has_tick_effects = true;
diagnostics.maintenance_cost_pj = feedback->maintenance_cost.value;
diagnostics.movement_cost_pj = feedback->movement_cost.value;
switch (feedback->movement) {
case biology::CellularMovementStatus::not_requested:
diagnostics.movement = network::CellularMovementResult::no_movement;
break;
case biology::CellularMovementStatus::moved:
diagnostics.movement = network::CellularMovementResult::moved;
break;
case biology::CellularMovementStatus::blocked:
diagnostics.movement = network::CellularMovementResult::blocked;
break;
case biology::CellularMovementStatus::insufficient_reserve:
diagnostics.movement = network::CellularMovementResult::insufficient_energy;
break;
}
switch (feedback->intake) {
case biology::CellularIntakeStatus::not_requested:
diagnostics.intake = network::CellularIntakeResult::not_requested;
break;
case biology::CellularIntakeStatus::acquired:
diagnostics.intake = network::CellularIntakeResult::acquired;
break;
case biology::CellularIntakeStatus::missing:
diagnostics.intake = network::CellularIntakeResult::missing_patch;
break;
case biology::CellularIntakeStatus::out_of_contact:
diagnostics.intake = network::CellularIntakeResult::out_of_contact;
break;
}
}
view.diagnostics = diagnostics;
view.patches.reserve(perceived->size()); view.patches.reserve(perceived->size());
for (const auto& patch : *perceived) { for (const auto& patch : *perceived) {
network::CellularPerceivedPatch visible; network::CellularPerceivedPatch visible;
+13 -4
View File
@@ -377,7 +377,7 @@ scoped change before starting the next segment.
after CI confirms the v8 server/client build. after CI confirms the v8 server/client build.
- Readiness update (2026-10-11): the maintainer reports that the Git checks - Readiness update (2026-10-11): the maintainer reports that the Git checks
passed, `evo-region` is running, and the client connects. This is operator passed, `evo-region` is running, and the client connects. This is operator
confirmation of checks and connectivity; it does not establish that the v8 confirmation of checks and connectivity; it does not establish that the
cellular path was selected or that life creation, movement, feeding and the cellular path was selected or that life creation, movement, feeding and the
on-screen perception work in a hands-on session. Those outcomes and the on-screen perception work in a hands-on session. Those outcomes and the
exploratory notes remain the 11.3e exit evidence. The 11.4 mutation expansion exploratory notes remain the 11.3e exit evidence. The 11.4 mutation expansion
@@ -391,12 +391,21 @@ scoped change before starting the next segment.
- 11.3e-6a: ADR-0117 defines owner-only protocol v9 diagnostics for current - 11.3e-6a: ADR-0117 defines owner-only protocol v9 diagnostics for current
reserve and the latest committed tick's maintenance, movement and intake result. reserve and the latest committed tick's maintenance, movement and intake result.
The v9 codec keeps v8 bytes frozen and rejects malformed status combinations; The v9 codec keeps v8 bytes frozen and rejects malformed status combinations;
standalone MSVC `NDEBUG` protocol tests pass. Server report projection and the standalone MSVC `NDEBUG` protocol tests pass.
client display remain the next parts of this subsection, with CI still pending. - 11.3e-6b: tick results now expose transient authoritative life feedback from
the committed cellular candidate. The profile bridge includes it only in the
authenticated owner's v9 perception; v8 owner sessions continue to receive
their frozen v8 payload. Recovery clears this non-persistent presentation
feedback. Focused biology, lifecycle and QUIC tests cover these paths; CI is
still pending.
- 11.3e-6c: the cellular trial selects v9 and shows reserve inventories,
maintenance and movement energy costs, movement outcome and feeding outcome.
Recovery is identified when tick effects are unavailable. The playtest remains
exploratory; the probe checklist needs a human run before 11.3 closes.
## Exit boundary ## Exit boundary
11.3 closes only when all five segments have evidence and the player-facing 11.3 closes only when the documented segments have evidence and the player-facing
single-region probe works against the authoritative server. 11.2 owner routing single-region probe works against the authoritative server. 11.2 owner routing
must also be closed before M11 claims persistent control across regions. Mutation, must also be closed before M11 claims persistent control across regions. Mutation,
funded budding, complete permadeath, logout/resume and repeated-life playtesting funded budding, complete permadeath, logout/resume and repeated-life playtesting
+17
View File
@@ -6629,3 +6629,20 @@ libraries predate v8, first missing the new client methods and then failing
during old server-session setup. The full remote-session test, fresh client during old server-session setup. The full remote-session test, fresh client
link, and CI run remain pending; no cellular runtime or playtest success is link, and CI run remain pending; no cellular runtime or playtest success is
claimed. claimed.
## 2026-10-11 — M11.3e-6b/c v9 diagnostics delivery (CI pending)
The committed cellular tick now exposes transient per-life feedback, the
cellular server bridge sends it only to the authenticated life owner over v9,
and the client displays reserve inventory, the last tick's maintenance and
movement costs, movement outcome and feeding outcome. v8 owner sessions still
receive the byte-compatible v8 perception; restart clears transient tick
effects. The QUIC test covers v9 owner filtering and v8 compatibility.
MSVC 19.44 compiled the changed biology, lifecycle, client-session and
server-session translation units, the cellular step/lifecycle tests, the QUIC
session test, the client panel and remote-session test with `/W4 /WX /DNDEBUG`.
Visual Studio LLVM `clang-format --dry-run --Werror` and `git diff --check`
passed. The configured CMake/Ninja build remained at `Re-checking globbed
directories...` for 60 seconds and was stopped; the QUIC test executable,
cellular runtime test executables, CI run and live-region probe have not run.
+2 -2
View File
@@ -2,7 +2,7 @@
This is the first hands-on check of the cellular stage. It is a one-player, This is the first hands-on check of the cellular stage. It is a one-player,
single-region engineering trial, not a balance sign-off or a claim that M11 is single-region engineering trial, not a balance sign-off or a claim that M11 is
complete. Run it after CI is green for the v8 server and client changes. complete. Run it after CI is green for the v9 server and client changes.
## Start ## Start
@@ -20,7 +20,7 @@ development CA:
Replace the endpoint and certificate name with the values for the running dev Replace the endpoint and certificate name with the values for the running dev
region. The launcher can do the same: fill in endpoint, server name, CA and region. The launcher can do the same: fill in endpoint, server name, CA and
grant bundle, check **Cellular trial (v8)**, then connect. Do not select the grant bundle, check **Cellular trial (v9)**, then connect. Do not select the
load-test grant bundle for an interactive session. load-test grant bundle for an interactive session.
On first successful login, the client submits a stable first-life request. The On first successful login, the client submits a stable first-life request. The
+7
View File
@@ -20,6 +20,12 @@ enum class CellularStepError : std::uint8_t {
motion motion
}; };
enum class CellularIntakeStatus : std::uint8_t { not_requested, acquired, missing, out_of_contact }; enum class CellularIntakeStatus : std::uint8_t { not_requested, acquired, missing, out_of_contact };
enum class CellularMovementStatus : std::uint8_t {
not_requested,
moved,
blocked,
insufficient_reserve
};
// Complete detached candidate for one 50 ms life tick. Maintenance is charged // Complete detached candidate for one 50 ms life tick. Maintenance is charged
// first; unaffordable motion leaves the cell stationary, then one targeted patch // first; unaffordable motion leaves the cell stationary, then one targeted patch
@@ -30,6 +36,7 @@ struct CellularStepCandidate {
accounting::Inventory reserve_after; accounting::Inventory reserve_after;
accounting::Inventory heat_after; accounting::Inventory heat_after;
accounting::Picojoules maintenance_cost{}, movement_cost{}; accounting::Picojoules maintenance_cost{}, movement_cost{};
CellularMovementStatus movement_status{CellularMovementStatus::not_requested};
CellularIntakeStatus intake_status{CellularIntakeStatus::not_requested}; CellularIntakeStatus intake_status{CellularIntakeStatus::not_requested};
std::optional<CellularPatchUptakeProposal> intake; std::optional<CellularPatchUptakeProposal> intake;
auto operator<=>(const CellularStepCandidate&) const = default; auto operator<=>(const CellularStepCandidate&) const = default;
@@ -41,6 +41,14 @@ struct CellularLifeIntent {
biology::CellularStepIntent intent{}; biology::CellularStepIntent intent{};
auto operator<=>(const CellularLifeIntent&) const = default; auto operator<=>(const CellularLifeIntent&) const = default;
}; };
struct CellularLifeTickFeedback {
std::uint64_t life_id{}, tick{};
accounting::Inventory reserve;
accounting::Picojoules maintenance_cost{}, movement_cost{};
biology::CellularMovementStatus movement{biology::CellularMovementStatus::not_requested};
biology::CellularIntakeStatus intake{biology::CellularIntakeStatus::not_requested};
auto operator<=>(const CellularLifeTickFeedback&) const = default;
};
struct CellularLivesConfig { struct CellularLivesConfig {
biology::CellularArea area{}; biology::CellularArea area{};
std::uint64_t tick{}; std::uint64_t tick{};
@@ -95,11 +103,12 @@ class CellularLives {
[[nodiscard]] accounting::Inventory heat() const noexcept; [[nodiscard]] accounting::Inventory heat() const noexcept;
[[nodiscard]] accounting::Inventory opening_total() const noexcept; [[nodiscard]] accounting::Inventory opening_total() const noexcept;
[[nodiscard]] accounting::Inventory current_total() const noexcept; [[nodiscard]] accounting::Inventory current_total() const noexcept;
// Latest successful in-memory step report; omitted from snapshots and empty after restore.
[[nodiscard]] std::span<const CellularLifeTickFeedback> last_tick_feedback() const noexcept;
[[nodiscard]] std::vector<std::uint8_t> snapshot() const; [[nodiscard]] std::vector<std::uint8_t> snapshot() const;
// Exact stock view for one live cell, filtered by its authoritative footprint and the // Exact stock view for one live cell, filtered by its authoritative footprint and the
// M11.3 perception radius. Patch provenance and out-of-range stock are never returned. // M11.3 perception radius. Patch provenance and out-of-range stock are never returned.
[[nodiscard]] std::expected<std::vector<biology::CellularPatchPerception>, [[nodiscard]] std::expected<std::vector<biology::CellularPatchPerception>, CellularLivesError>
CellularLivesError>
perceive(std::uint64_t life_id) const; perceive(std::uint64_t life_id) const;
// Returns a detached post-birth candidate for an allocator-reserved request. // Returns a detached post-birth candidate for an allocator-reserved request.
@@ -123,5 +132,6 @@ class CellularLives {
struct State; struct State;
explicit CellularLives(std::unique_ptr<State> state); explicit CellularLives(std::unique_ptr<State> state);
std::unique_ptr<State> state_; std::unique_ptr<State> state_;
std::vector<CellularLifeTickFeedback> last_tick_feedback_;
}; };
} // namespace evo::server } // namespace evo::server
+2 -2
View File
@@ -100,7 +100,7 @@ struct RegionSessionsConfig {
// M10.8d recovery: this often, open outgoing transfers prepared more than ticket_lifetime // M10.8d recovery: this often, open outgoing transfers prepared more than ticket_lifetime
// + 10 s ago (by the store's clock, e.g. by a process that died) are aborted. // + 10 s ago (by the store's clock, e.g. by a process that died) are aborted.
std::chrono::milliseconds overdue_poll{5000}; std::chrono::milliseconds overdue_poll{5000};
// v5/v8 are accepted only when both primitive-life handlers are supplied. Callbacks // v5/v8/v9 are accepted only when both primitive-life handlers are supplied. Callbacks
// receive the authenticated account and durable control generation for this session. // receive the authenticated account and durable control generation for this session.
// A cellular host may enable v5 together with the v7 cellular action path; each // A cellular host may enable v5 together with the v7 cellular action path; each
// connection remains fixed to its negotiated protocol. // connection remains fixed to its negotiated protocol.
@@ -112,7 +112,7 @@ struct RegionSessionsConfig {
query_primitive_life; query_primitive_life;
// M11.3 v6 cellular intentions. Opt-in until a cellular state owner consumes them. // M11.3 v6 cellular intentions. Opt-in until a cellular state owner consumes them.
bool accept_cellular_intentions{}; bool accept_cellular_intentions{};
// M11.3 v7 durable cellular actions and v8 owner-filtered perception. Requires durable // M11.3 v7 durable cellular actions and v8/v9 owner-filtered perception. Requires durable
// control and action ledgers; the caller forwards carried inputs to profile 4. // control and action ledgers; the caller forwards carried inputs to profile 4.
bool accept_cellular_actions{}; bool accept_cellular_actions{};
}; };
+22 -4
View File
@@ -39,6 +39,8 @@ propose_cellular_step(std::uint64_t begin_tick, CellularArea area, CellularPosit
return std::unexpected{CellularStepError::overflow}; return std::unexpected{CellularStepError::overflow};
reserve.energy.value -= *maintenance; reserve.energy.value -= *maintenance;
const auto original_position = position;
const bool movement_requested = intent.movement.x != 0 || intent.movement.y != 0;
const auto movement = propose_funded_cellular_motion(area, position, extent_um, intent.movement, const auto movement = propose_funded_cellular_motion(area, position, extent_um, intent.movement,
budget, reserve, heat); budget, reserve, heat);
if (!movement && movement.error() != CellularMotionError::insufficient_reserve) if (!movement && movement.error() != CellularMotionError::insufficient_reserve)
@@ -49,12 +51,28 @@ propose_cellular_step(std::uint64_t begin_tick, CellularArea area, CellularPosit
heat = movement->heat_after; heat = movement->heat_after;
} }
CellularStepCandidate candidate{ CellularStepCandidate candidate{begin_tick,
begin_tick, begin_tick + 1, position, reserve, begin_tick + 1,
heat, {*maintenance}, {}, CellularIntakeStatus::not_requested, position,
reserve,
heat,
{*maintenance},
{},
CellularMovementStatus::not_requested,
CellularIntakeStatus::not_requested,
{}}; {}};
if (movement) if (!movement_requested) {
candidate.movement_status = CellularMovementStatus::not_requested;
} else if (!movement) {
candidate.movement_status = CellularMovementStatus::insufficient_reserve;
} else if (movement->position == original_position) {
candidate.movement_status = CellularMovementStatus::blocked;
} else {
candidate.movement_status = CellularMovementStatus::moved;
}
if (movement) {
candidate.movement_cost = movement->movement_cost; candidate.movement_cost = movement->movement_cost;
}
if (!intent.intake_target) if (!intent.intake_target)
return candidate; return candidate;
+12 -6
View File
@@ -159,7 +159,8 @@ RegionSessionClient::connect(RegionSessionClientConfig config, Clock::time_point
config.protocol_version != network::session_protocol_v5 && config.protocol_version != network::session_protocol_v5 &&
config.protocol_version != network::session_protocol_v6 && config.protocol_version != network::session_protocol_v6 &&
config.protocol_version != network::session_protocol_v7 && config.protocol_version != network::session_protocol_v7 &&
config.protocol_version != network::session_protocol_v8) config.protocol_version != network::session_protocol_v8 &&
config.protocol_version != network::session_protocol_v9)
return std::unexpected(network::quic::EndpointError::configuration); return std::unexpected(network::quic::EndpointError::configuration);
auto endpoint = network::quic::Endpoint::connect(config.transport); auto endpoint = network::quic::Endpoint::connect(config.transport);
if (!endpoint) if (!endpoint)
@@ -265,7 +266,8 @@ bool RegionSessionClient::send_cellular_action(
std::optional<std::pair<std::uint32_t, std::uint32_t>> intake_target) { std::optional<std::pair<std::uint32_t, std::uint32_t>> intake_target) {
auto& m = *impl_; auto& m = *impl_;
return (m.protocol_version == network::session_protocol_v7 || return (m.protocol_version == network::session_protocol_v7 ||
m.protocol_version == network::session_protocol_v8) && m.protocol_version == network::session_protocol_v8 ||
m.protocol_version == network::session_protocol_v9) &&
m.state == RegionSessionState::established && m.welcome && action_id != 0 && tick != 0 && m.state == RegionSessionState::established && m.welcome && action_id != 0 && tick != 0 &&
m.send(network::CellularAction{m.welcome->session, m.welcome->epoch, action_id, tick, m.send(network::CellularAction{m.welcome->session, m.welcome->epoch, action_id, tick,
move_x, move_y, intake_target.has_value(), move_x, move_y, intake_target.has_value(),
@@ -277,14 +279,16 @@ bool RegionSessionClient::query_action(std::uint64_t action_id) {
auto& m = *impl_; auto& m = *impl_;
return (m.protocol_version == network::session_protocol_version || return (m.protocol_version == network::session_protocol_version ||
m.protocol_version == network::session_protocol_v7 || m.protocol_version == network::session_protocol_v7 ||
m.protocol_version == network::session_protocol_v8) && m.protocol_version == network::session_protocol_v8 ||
m.protocol_version == network::session_protocol_v9) &&
m.state == RegionSessionState::established && m.send(network::ActionQuery{action_id}); m.state == RegionSessionState::established && m.send(network::ActionQuery{action_id});
} }
bool RegionSessionClient::request_primitive_life(std::uint64_t request_id) { bool RegionSessionClient::request_primitive_life(std::uint64_t request_id) {
auto& m = *impl_; auto& m = *impl_;
return (m.protocol_version == network::session_protocol_v5 || return (m.protocol_version == network::session_protocol_v5 ||
m.protocol_version == network::session_protocol_v8) && m.protocol_version == network::session_protocol_v8 ||
m.protocol_version == network::session_protocol_v9) &&
m.state == RegionSessionState::established && m.welcome && request_id != 0 && m.state == RegionSessionState::established && m.welcome && request_id != 0 &&
m.send(network::PrimitiveLifeRequest{m.welcome->session, m.welcome->epoch, request_id}); m.send(network::PrimitiveLifeRequest{m.welcome->session, m.welcome->epoch, request_id});
} }
@@ -292,7 +296,8 @@ bool RegionSessionClient::request_primitive_life(std::uint64_t request_id) {
bool RegionSessionClient::query_primitive_life(std::uint64_t request_id) { bool RegionSessionClient::query_primitive_life(std::uint64_t request_id) {
auto& m = *impl_; auto& m = *impl_;
return (m.protocol_version == network::session_protocol_v5 || return (m.protocol_version == network::session_protocol_v5 ||
m.protocol_version == network::session_protocol_v8) && m.protocol_version == network::session_protocol_v8 ||
m.protocol_version == network::session_protocol_v9) &&
m.state == RegionSessionState::established && request_id != 0 && m.state == RegionSessionState::established && request_id != 0 &&
m.send(network::PrimitiveLifeQuery{request_id}); m.send(network::PrimitiveLifeQuery{request_id});
} }
@@ -329,7 +334,8 @@ bool RegionSessionClient::set_interest(const network::SessionInterest& interest)
auto& m = *impl_; auto& m = *impl_;
return (m.protocol_version == network::session_protocol_version || return (m.protocol_version == network::session_protocol_version ||
m.protocol_version == network::session_protocol_v7 || m.protocol_version == network::session_protocol_v7 ||
m.protocol_version == network::session_protocol_v8) && m.protocol_version == network::session_protocol_v8 ||
m.protocol_version == network::session_protocol_v9) &&
m.state == RegionSessionState::established && m.send(interest); m.state == RegionSessionState::established && m.send(interest);
} }
+128 -107
View File
@@ -101,8 +101,7 @@ bool add_inventory(accounting::Inventory& total, const accounting::Inventory& va
return true; return true;
} }
bool subtract_inventory(accounting::Inventory& total, bool subtract_inventory(accounting::Inventory& total, const accounting::Inventory& value) noexcept {
const accounting::Inventory& value) noexcept {
if (value.energy.value > total.energy.value) if (value.energy.value > total.energy.value)
return false; return false;
for (std::size_t channel = 0; channel < total.matter.size(); ++channel) for (std::size_t channel = 0; channel < total.matter.size(); ++channel)
@@ -147,34 +146,31 @@ sum_state(accounting::Inventory nursery, accounting::Inventory heat,
std::expected<accounting::Inventory, CellularLivesError> std::expected<accounting::Inventory, CellularLivesError>
validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame, validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
const CellularLivesConfig& config, const NurseryConfig& nursery_config, const CellularLivesConfig& config, const NurseryConfig& nursery_config,
const biology::CellularHabitat& habitat, const biology::CellularHabitat& habitat, std::span<const CellularOwnedLife> lives,
std::span<const CellularOwnedLife> lives, std::span<const CellularOwnedCorpse> corpses, const biology::LineageArchive& archive,
std::span<const CellularOwnedCorpse> corpses, accounting::Inventory nursery, accounting::Inventory heat,
const biology::LineageArchive& archive, accounting::Inventory nursery, accounting::Inventory opening_total) {
accounting::Inventory heat, accounting::Inventory opening_total) {
const auto& map = habitat.config(); const auto& map = habitat.config();
if (world == 0 || region == 0 || frame == 0 || nursery_config.world != world || if (world == 0 || region == 0 || frame == 0 || nursery_config.world != world ||
nursery_config.region != region || nursery_config.frame != frame || nursery_config.region != region || nursery_config.frame != frame ||
nursery_config.source == 0 || nursery_config.funding != nursery || nursery_config.source == 0 || nursery_config.funding != nursery || map.world != world ||
map.world != world || map.region != region || map.frame != frame || map.region != region || map.frame != frame || config.area.width_um == 0 ||
config.area.width_um == 0 || config.area.height_um == 0 || config.area.height_um == 0 || map.width_um != config.area.width_um ||
map.width_um != config.area.width_um || map.height_um != config.area.height_um || map.height_um != config.area.height_um || config.ambient_temperature_millikelvin == 0 ||
config.ambient_temperature_millikelvin == 0 ||
nursery_config.sites.empty() || nursery_config.sites.size() > max_primitive_lives || nursery_config.sites.empty() || nursery_config.sites.size() > max_primitive_lives ||
!std::ranges::is_sorted(nursery_config.sites) || !std::ranges::is_sorted(nursery_config.sites) ||
lives.size() > biology::max_cellular_tick_lives || lives.size() > biology::max_cellular_tick_lives ||
corpses.size() > biology::max_archived_organisms || corpses.size() > biology::max_archived_organisms ||
archive.recorded() != lives.size() + corpses.size()) archive.recorded() != lives.size() + corpses.size())
return std::unexpected{CellularLivesError::invalid_config}; return std::unexpected{CellularLivesError::invalid_config};
if (std::ranges::any_of(heat.matter, if (std::ranges::any_of(heat.matter, [](const auto& value) { return value.value != 0; }))
[](const auto& value) { return value.value != 0; }))
return std::unexpected{CellularLivesError::conservation}; return std::unexpected{CellularLivesError::conservation};
const auto founder = biology::primitive_founder(1, 1); const auto founder = biology::primitive_founder(1, 1);
if (!founder) if (!founder)
return std::unexpected{CellularLivesError::biology}; return std::unexpected{CellularLivesError::biology};
const auto founder_budget = const auto founder_budget = biology::metabolic_budget(
biology::metabolic_budget(*founder, {1000, 0}, {config.ambient_temperature_millikelvin, {}}); *founder, {1000, 0}, {config.ambient_temperature_millikelvin, {}});
if (!founder_budget) if (!founder_budget)
return std::unexpected{CellularLivesError::biology}; return std::unexpected{CellularLivesError::biology};
const auto spawn_extent = founder_budget->phenotype.extent; const auto spawn_extent = founder_budget->phenotype.extent;
@@ -202,10 +198,9 @@ validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
for (std::size_t i = 0; i < lives.size(); ++i) { for (std::size_t i = 0; i < lives.size(); ++i) {
const auto& life = lives[i]; const auto& life = lives[i];
if (life.account == LifeAccount{} || life.identity.life == 0 || if (life.account == LifeAccount{} || life.identity.life == 0 ||
life.identity.organism == 0 || life.identity.genome == 0 || life.identity.organism == 0 || life.identity.genome == 0 || life.identity.event == 0 ||
life.identity.event == 0 || life.identity.born.value == 0 || life.identity.born.value == 0 || life.identity.born.value > config.tick ||
life.identity.born.value > config.tick || life.source == 0 || life.source == 0 || (i != 0 && lives[i - 1].identity.life >= life.identity.life))
(i != 0 && lives[i - 1].identity.life >= life.identity.life))
return std::unexpected{CellularLivesError::invalid_life}; return std::unexpected{CellularLivesError::invalid_life};
for (std::size_t j = 0; j < i; ++j) for (std::size_t j = 0; j < i; ++j)
if (lives[j].account == life.account || if (lives[j].account == life.account ||
@@ -217,8 +212,7 @@ validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
return std::unexpected{CellularLivesError::archive}; return std::unexpected{CellularLivesError::archive};
const auto budget = budget_for(archive, life, config.ambient_temperature_millikelvin); const auto budget = budget_for(archive, life, config.ambient_temperature_millikelvin);
if (!budget || budget->body != life.body || life.body.energy.value != 0 || if (!budget || budget->body != life.body || life.body.energy.value != 0 ||
budget->phenotype.extent == 0 || budget->phenotype.extent == 0 || budget->phenotype.extent > config.area.width_um ||
budget->phenotype.extent > config.area.width_um ||
budget->phenotype.extent > config.area.height_um || budget->phenotype.extent > config.area.height_um ||
life.position.x_um > config.area.width_um - budget->phenotype.extent || life.position.x_um > config.area.width_um - budget->phenotype.extent ||
life.position.y_um > config.area.height_um - budget->phenotype.extent) life.position.y_um > config.area.height_um - budget->phenotype.extent)
@@ -242,8 +236,8 @@ validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
const auto genome = archive.find(record->genome); const auto genome = archive.find(record->genome);
if (!genome) if (!genome)
return std::unexpected{CellularLivesError::archive}; return std::unexpected{CellularLivesError::archive};
const auto budget = biology::metabolic_budget( const auto budget = biology::metabolic_budget(*genome, corpse.growth,
*genome, corpse.growth, {config.ambient_temperature_millikelvin, {}}); {config.ambient_temperature_millikelvin, {}});
if (!budget || budget->phenotype.extent != corpse.extent_um || if (!budget || budget->phenotype.extent != corpse.extent_um ||
corpse.extent_um > config.area.width_um || corpse.extent_um > config.area.height_um || corpse.extent_um > config.area.width_um || corpse.extent_um > config.area.height_um ||
corpse.position.x_um > config.area.width_um - corpse.extent_um || corpse.position.x_um > config.area.width_um - corpse.extent_um ||
@@ -282,16 +276,14 @@ struct CellularLives::State {
State(std::uint64_t world_id, std::uint64_t region_id, std::uint64_t frame_id, State(std::uint64_t world_id, std::uint64_t region_id, std::uint64_t frame_id,
CellularLivesConfig cfg, NurseryConfig nursery_definition, CellularLivesConfig cfg, NurseryConfig nursery_definition,
std::unique_ptr<biology::CellularHabitat> map, std::unique_ptr<biology::CellularHabitat> map, std::vector<CellularOwnedLife> living,
std::vector<CellularOwnedLife> living, std::vector<CellularOwnedCorpse> dead, std::vector<CellularOwnedCorpse> dead, const biology::LineageArchive& history,
const biology::LineageArchive& history, accounting::Inventory source, accounting::Inventory source, accounting::Inventory accumulated_heat,
accounting::Inventory accumulated_heat, accounting::Inventory initial, accounting::Inventory initial, accounting::Inventory current)
accounting::Inventory current)
: world{world_id}, region{region_id}, frame{frame_id}, config{cfg}, : world{world_id}, region{region_id}, frame{frame_id}, config{cfg},
nursery_config{std::move(nursery_definition)}, nursery_config{std::move(nursery_definition)}, habitat{std::move(map)},
habitat{std::move(map)}, lives{std::move(living)}, corpses{std::move(dead)}, lives{std::move(living)}, corpses{std::move(dead)}, archive{history}, nursery{source},
archive{history}, nursery{source}, heat{accumulated_heat}, opening_total{initial}, heat{accumulated_heat}, opening_total{initial}, current_total{current} {}
current_total{current} {}
}; };
CellularLives::CellularLives(std::unique_ptr<State> state) : state_{std::move(state)} {} CellularLives::CellularLives(std::unique_ptr<State> state) : state_{std::move(state)} {}
@@ -319,8 +311,8 @@ CellularLives::create(const PrimitiveLives& opening,
for (const auto& primitive : opening.lives()) { for (const auto& primitive : opening.lives()) {
if (primitive.identity.born.value == 0 || primitive.identity.born.value > config.tick || if (primitive.identity.born.value == 0 || primitive.identity.born.value > config.tick ||
primitive.identity.life == 0 || primitive.identity.organism == 0 || primitive.identity.life == 0 || primitive.identity.organism == 0 ||
primitive.identity.genome == 0 || primitive.source == 0 || primitive.identity.genome == 0 || primitive.source == 0 || primitive.site.x_um < 0 ||
primitive.site.x_um < 0 || primitive.site.y_um < 0) primitive.site.y_um < 0)
return std::unexpected{CellularLivesError::invalid_life}; return std::unexpected{CellularLivesError::invalid_life};
if (primitive.body.value == 0 || primitive.reserve.value == 0) if (primitive.body.value == 0 || primitive.reserve.value == 0)
return std::unexpected{CellularLivesError::invalid_life}; return std::unexpected{CellularLivesError::invalid_life};
@@ -342,8 +334,8 @@ CellularLives::create(const PrimitiveLives& opening,
const auto& life = lives[i]; const auto& life = lives[i];
if (i != 0 && lives[i - 1].identity.life == life.identity.life) if (i != 0 && lives[i - 1].identity.life == life.identity.life)
return std::unexpected{CellularLivesError::duplicate_life}; return std::unexpected{CellularLivesError::duplicate_life};
const auto budget = budget_for(opening.archive(), life, const auto budget =
config.ambient_temperature_millikelvin); budget_for(opening.archive(), life, config.ambient_temperature_millikelvin);
if (!budget || budget->phenotype.extent == 0 || if (!budget || budget->phenotype.extent == 0 ||
budget->phenotype.extent > config.area.width_um || budget->phenotype.extent > config.area.width_um ||
budget->phenotype.extent > config.area.height_um || life.body.energy.value != 0 || budget->phenotype.extent > config.area.height_um || life.body.energy.value != 0 ||
@@ -367,36 +359,58 @@ CellularLives::create(const PrimitiveLives& opening,
const auto world = nursery_config.world; const auto world = nursery_config.world;
const auto region = nursery_config.region; const auto region = nursery_config.region;
const auto frame = nursery_config.frame; const auto frame = nursery_config.frame;
auto state = std::make_unique<State>( auto state = std::make_unique<State>(world, region, frame, config, std::move(nursery_config),
world, region, frame, config, std::move(habitat), std::move(lives),
std::move(nursery_config), std::vector<CellularOwnedCorpse>{}, opening.archive(),
std::move(habitat), std::move(lives), std::vector<CellularOwnedCorpse>{}, nursery, heat, opening_total, *current);
opening.archive(), nursery, heat, opening_total, *current);
return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}}; return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}};
} }
std::uint64_t CellularLives::world() const noexcept { return state_->world; } std::uint64_t CellularLives::world() const noexcept {
std::uint64_t CellularLives::region() const noexcept { return state_->region; } return state_->world;
std::uint64_t CellularLives::frame() const noexcept { return state_->frame; } }
std::uint64_t CellularLives::tick() const noexcept { return state_->config.tick; } std::uint64_t CellularLives::region() const noexcept {
return state_->region;
}
std::uint64_t CellularLives::frame() const noexcept {
return state_->frame;
}
std::uint64_t CellularLives::tick() const noexcept {
return state_->config.tick;
}
std::uint32_t CellularLives::ambient_temperature_millikelvin() const noexcept { std::uint32_t CellularLives::ambient_temperature_millikelvin() const noexcept {
return state_->config.ambient_temperature_millikelvin; return state_->config.ambient_temperature_millikelvin;
} }
biology::CellularArea CellularLives::area() const noexcept { return state_->config.area; } biology::CellularArea CellularLives::area() const noexcept {
std::span<const CellularOwnedLife> CellularLives::lives() const noexcept { return state_->lives; } return state_->config.area;
}
std::span<const CellularOwnedLife> CellularLives::lives() const noexcept {
return state_->lives;
}
std::span<const CellularOwnedCorpse> CellularLives::corpses() const noexcept { std::span<const CellularOwnedCorpse> CellularLives::corpses() const noexcept {
return state_->corpses; return state_->corpses;
} }
const biology::CellularHabitat& CellularLives::habitat() const noexcept { return *state_->habitat; } const biology::CellularHabitat& CellularLives::habitat() const noexcept {
const biology::LineageArchive& CellularLives::archive() const noexcept { return state_->archive; } return *state_->habitat;
accounting::Inventory CellularLives::nursery() const noexcept { return state_->nursery; } }
accounting::Inventory CellularLives::heat() const noexcept { return state_->heat; } const biology::LineageArchive& CellularLives::archive() const noexcept {
return state_->archive;
}
accounting::Inventory CellularLives::nursery() const noexcept {
return state_->nursery;
}
accounting::Inventory CellularLives::heat() const noexcept {
return state_->heat;
}
accounting::Inventory CellularLives::opening_total() const noexcept { accounting::Inventory CellularLives::opening_total() const noexcept {
return state_->opening_total; return state_->opening_total;
} }
accounting::Inventory CellularLives::current_total() const noexcept { accounting::Inventory CellularLives::current_total() const noexcept {
return state_->current_total; return state_->current_total;
} }
std::span<const CellularLifeTickFeedback> CellularLives::last_tick_feedback() const noexcept {
return last_tick_feedback_;
}
std::vector<std::uint8_t> CellularLives::snapshot() const { std::vector<std::uint8_t> CellularLives::snapshot() const {
const auto habitat = state_->habitat->snapshot(); const auto habitat = state_->habitat->snapshot();
@@ -408,7 +422,8 @@ std::vector<std::uint8_t> CellularLives::snapshot() const {
cellular_life_bytes * life_count + cellular_life_bytes * life_count +
cellular_corpse_bytes * corpse_count + habitat.size() + cellular_corpse_bytes * corpse_count + habitat.size() +
archive.size() + 8; archive.size() + 8;
if (total_bytes > max_cellular_lives_bytes || habitat.size() > biology::max_cellular_habitat_bytes || if (total_bytes > max_cellular_lives_bytes ||
habitat.size() > biology::max_cellular_habitat_bytes ||
archive.size() > biology::max_archive_bytes || site_count > max_primitive_lives || archive.size() > biology::max_archive_bytes || site_count > max_primitive_lives ||
life_count > biology::max_cellular_tick_lives || life_count > biology::max_cellular_tick_lives ||
corpse_count > biology::max_archived_organisms) corpse_count > biology::max_archived_organisms)
@@ -476,13 +491,12 @@ std::vector<std::uint8_t> CellularLives::snapshot() const {
std::expected<std::vector<biology::CellularPatchPerception>, CellularLivesError> std::expected<std::vector<biology::CellularPatchPerception>, CellularLivesError>
CellularLives::perceive(std::uint64_t life_id) const { CellularLives::perceive(std::uint64_t life_id) const {
const auto life = std::ranges::find(state_->lives, life_id, [](const auto& owned) { const auto life = std::ranges::find(state_->lives, life_id,
return owned.identity.life; [](const auto& owned) { return owned.identity.life; });
});
if (life == state_->lives.end()) if (life == state_->lives.end())
return std::unexpected{CellularLivesError::invalid_life}; return std::unexpected{CellularLivesError::invalid_life};
const auto budget = budget_for(state_->archive, *life, const auto budget =
state_->config.ambient_temperature_millikelvin); budget_for(state_->archive, *life, state_->config.ambient_temperature_millikelvin);
if (!budget) if (!budget)
return std::unexpected{budget.error()}; return std::unexpected{budget.error()};
auto view = state_->habitat->perceive(life->position, budget->phenotype.extent); auto view = state_->habitat->perceive(life->position, budget->phenotype.extent);
@@ -507,15 +521,19 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
return life.account == request.account; return life.account == request.account;
})) }))
return std::unexpected{CellularLivesError::life_exists}; return std::unexpected{CellularLivesError::life_exists};
if (std::ranges::any_of(state_->lives, [&](const CellularOwnedLife& life) { if (std::ranges::any_of(state_->lives,
[&](const CellularOwnedLife& life) {
return life.identity.life == allocation.life || return life.identity.life == allocation.life ||
life.identity.organism == allocation.organism || life.identity.organism == allocation.organism ||
life.identity.genome == allocation.genome || life.identity.genome == allocation.genome ||
life.identity.event == allocation.event; life.identity.event == allocation.event;
}) || }) ||
std::ranges::any_of(state_->corpses, [&](const CellularOwnedCorpse& corpse) { std::ranges::any_of(state_->corpses,
return corpse.life_id == allocation.life || corpse.organism == allocation.organism; [&](const CellularOwnedCorpse& corpse) {
}) || state_->archive.find(allocation.genome) || state_->archive.organism(allocation.organism)) return corpse.life_id == allocation.life ||
corpse.organism == allocation.organism;
}) ||
state_->archive.find(allocation.genome) || state_->archive.organism(allocation.organism))
return std::unexpected{CellularLivesError::duplicate_life}; return std::unexpected{CellularLivesError::duplicate_life};
const auto endowed = biology::primitive_endowment(); const auto endowed = biology::primitive_endowment();
@@ -523,8 +541,7 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
if (!endowed || !genome) if (!endowed || !genome)
return std::unexpected{CellularLivesError::biology}; return std::unexpected{CellularLivesError::biology};
const auto budget = biology::metabolic_budget( const auto budget = biology::metabolic_budget(
*genome, endowed->growth, *genome, endowed->growth, {state_->config.ambient_temperature_millikelvin, {}});
{state_->config.ambient_temperature_millikelvin, {}});
if (!budget || budget->body != endowed->body) if (!budget || budget->body != endowed->body)
return std::unexpected{CellularLivesError::biology}; return std::unexpected{CellularLivesError::biology};
@@ -536,8 +553,8 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
static_cast<std::uint64_t>(site.y_um)}; static_cast<std::uint64_t>(site.y_um)};
bool occupied = false; bool occupied = false;
for (const auto& living : state_->lives) { for (const auto& living : state_->lives) {
const auto living_budget = budget_for( const auto living_budget =
state_->archive, living, state_->config.ambient_temperature_millikelvin); budget_for(state_->archive, living, state_->config.ambient_temperature_millikelvin);
if (!living_budget) if (!living_budget)
return std::unexpected{living_budget.error()}; return std::unexpected{living_budget.error()};
const auto separated = [](std::uint64_t left, std::uint64_t right, const auto separated = [](std::uint64_t left, std::uint64_t right,
@@ -568,8 +585,7 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
return std::unexpected{CellularLivesError::insufficient_funding}; return std::unexpected{CellularLivesError::insufficient_funding};
nursery.energy.value -= endowed->construction.value; nursery.energy.value -= endowed->construction.value;
auto heat = state_->heat; auto heat = state_->heat;
if (endowed->construction.value > if (endowed->construction.value > std::numeric_limits<std::uint64_t>::max() - heat.energy.value)
std::numeric_limits<std::uint64_t>::max() - heat.energy.value)
return std::unexpected{CellularLivesError::overflow}; return std::unexpected{CellularLivesError::overflow};
heat.energy.value += endowed->construction.value; heat.energy.value += endowed->construction.value;
@@ -580,9 +596,7 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
auto lives = state_->lives; auto lives = state_->lives;
lives.push_back({request.account, allocation, state_->nursery_config.source, endowed->growth, lives.push_back({request.account, allocation, state_->nursery_config.source, endowed->growth,
*position, endowed->body, endowed->reserve}); *position, endowed->body, endowed->reserve});
std::ranges::sort(lives, {}, [](const CellularOwnedLife& life) { std::ranges::sort(lives, {}, [](const CellularOwnedLife& life) { return life.identity.life; });
return life.identity.life;
});
auto nursery_config = state_->nursery_config; auto nursery_config = state_->nursery_config;
nursery_config.funding = nursery; nursery_config.funding = nursery;
@@ -590,17 +604,17 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
state_->region, state_->frame); state_->region, state_->frame);
if (!habitat) if (!habitat)
return std::unexpected{CellularLivesError::habitat}; return std::unexpected{CellularLivesError::habitat};
const auto current = validate_state(state_->world, state_->region, state_->frame, const auto current = validate_state(
state_->config, nursery_config, **habitat, lives, state_->world, state_->region, state_->frame, state_->config, nursery_config, **habitat,
state_->corpses, archive, nursery, heat, lives, state_->corpses, archive, nursery, heat, state_->opening_total);
state_->opening_total);
if (!current) if (!current)
return std::unexpected{current.error()}; return std::unexpected{current.error()};
auto candidate = std::unique_ptr<CellularLives>{new CellularLives{std::make_unique<State>( auto candidate = std::unique_ptr<CellularLives>{new CellularLives{std::make_unique<State>(
state_->world, state_->region, state_->frame, state_->config, state_->world, state_->region, state_->frame, state_->config, std::move(nursery_config),
std::move(nursery_config), std::move(*habitat), std::move(lives), state_->corpses, std::move(*habitat), std::move(lives), state_->corpses, archive, nursery, heat,
archive, nursery, heat, state_->opening_total, *current)}}; state_->opening_total, *current)}};
candidate->last_tick_feedback_ = last_tick_feedback_;
return candidate; return candidate;
} }
@@ -696,8 +710,8 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
const auto habitat_payload = in.raw(static_cast<std::size_t>(habitat_size)); const auto habitat_payload = in.raw(static_cast<std::size_t>(habitat_size));
const auto archive_payload = in.raw(static_cast<std::size_t>(archive_size)); const auto archive_payload = in.raw(static_cast<std::size_t>(archive_size));
auto habitat = biology::CellularHabitat::restore(habitat_payload, saved_world, saved_region, auto habitat =
saved_frame); biology::CellularHabitat::restore(habitat_payload, saved_world, saved_region, saved_frame);
if (!habitat) { if (!habitat) {
if (habitat.error() == biology::CellularHabitatError::version) if (habitat.error() == biology::CellularHabitatError::version)
return std::unexpected{CellularLivesError::version}; return std::unexpected{CellularLivesError::version};
@@ -715,9 +729,9 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
return std::unexpected{CellularLivesError::noncanonical}; return std::unexpected{CellularLivesError::noncanonical};
return std::unexpected{CellularLivesError::archive}; return std::unexpected{CellularLivesError::archive};
} }
const auto current = validate_state(saved_world, saved_region, saved_frame, config, const auto current =
nursery_config, **habitat, lives, corpses, *archive, validate_state(saved_world, saved_region, saved_frame, config, nursery_config, **habitat,
nursery, heat, opening_total); lives, corpses, *archive, nursery, heat, opening_total);
if (!current) if (!current)
return std::unexpected{current.error()}; return std::unexpected{current.error()};
@@ -747,8 +761,8 @@ CellularLives::advance_tick(std::span<const CellularLifeIntent> intents) {
inputs.reserve(state_->lives.size()); inputs.reserve(state_->lives.size());
for (std::size_t i = 0; i < state_->lives.size(); ++i) { for (std::size_t i = 0; i < state_->lives.size(); ++i) {
const auto& life = state_->lives[i]; const auto& life = state_->lives[i];
const auto budget = budget_for(state_->archive, life, const auto budget =
state_->config.ambient_temperature_millikelvin); budget_for(state_->archive, life, state_->config.ambient_temperature_millikelvin);
if (!budget) if (!budget)
return std::unexpected{budget.error()}; return std::unexpected{budget.error()};
inputs.push_back({life.identity.life, inputs.push_back({life.identity.life,
@@ -786,18 +800,13 @@ CellularLives::advance_tick(std::span<const CellularLifeIntent> intents) {
if (found == next_lives.end() || found->identity.life != dead.life_id || if (found == next_lives.end() || found->identity.life != dead.life_id ||
!next_archive.record_death(found->identity.organism, {proposal->end_tick})) !next_archive.record_death(found->identity.organism, {proposal->end_tick}))
return std::unexpected{CellularLivesError::archive}; return std::unexpected{CellularLivesError::archive};
const auto corpse_budget = budget_for( const auto corpse_budget =
next_archive, *found, state_->config.ambient_temperature_millikelvin); budget_for(next_archive, *found, state_->config.ambient_temperature_millikelvin);
if (!corpse_budget) if (!corpse_budget)
return std::unexpected{corpse_budget.error()}; return std::unexpected{corpse_budget.error()};
next_corpses.push_back({found->identity.life, next_corpses.push_back({found->identity.life, found->identity.organism, found->source,
found->identity.organism, proposal->end_tick, dead.position, found->growth,
found->source, corpse_budget->phenotype.extent, dead.inventory});
proposal->end_tick,
dead.position,
found->growth,
corpse_budget->phenotype.extent,
dead.inventory});
next_lives.erase(found); next_lives.erase(found);
} }
std::ranges::sort(next_corpses, {}, &CellularOwnedCorpse::organism); std::ranges::sort(next_corpses, {}, &CellularOwnedCorpse::organism);
@@ -806,10 +815,9 @@ CellularLives::advance_tick(std::span<const CellularLifeIntent> intents) {
return std::unexpected{CellularLivesError::overflow}; return std::unexpected{CellularLivesError::overflow};
next_heat.energy.value += proposal->heat_released.value; next_heat.energy.value += proposal->heat_released.value;
for (const auto& update : proposal->patches) { for (const auto& update : proposal->patches) {
const auto found = std::ranges::lower_bound( const auto found =
habitat_config.patches, update.address, {}, [](const auto& patch) { std::ranges::lower_bound(habitat_config.patches, update.address, {},
return patch.address; [](const auto& patch) { return patch.address; });
});
if (found == habitat_config.patches.end() || found->address != update.address) if (found == habitat_config.patches.end() || found->address != update.address)
return std::unexpected{CellularLivesError::habitat}; return std::unexpected{CellularLivesError::habitat};
found->stock = update.stock; found->stock = update.stock;
@@ -817,23 +825,36 @@ CellularLives::advance_tick(std::span<const CellularLifeIntent> intents) {
auto next_habitat = biology::CellularHabitat::create(std::move(habitat_config)); auto next_habitat = biology::CellularHabitat::create(std::move(habitat_config));
if (!next_habitat) if (!next_habitat)
return std::unexpected{CellularLivesError::habitat}; return std::unexpected{CellularLivesError::habitat};
const auto total = validate_state( const auto total =
state_->world, state_->region, state_->frame, validate_state(state_->world, state_->region, state_->frame,
CellularLivesConfig{state_->config.area, proposal->end_tick, CellularLivesConfig{state_->config.area, proposal->end_tick,
state_->config.ambient_temperature_millikelvin}, state_->config.ambient_temperature_millikelvin},
state_->nursery_config, **next_habitat, next_lives, next_corpses, next_archive, state_->nursery_config, **next_habitat, next_lives, next_corpses,
state_->nursery, next_heat, state_->opening_total); next_archive, state_->nursery, next_heat, state_->opening_total);
if (!total) if (!total)
return std::unexpected{total.error()}; return std::unexpected{total.error()};
auto next = std::make_unique<State>( auto next =
state_->world, state_->region, state_->frame, std::make_unique<State>(state_->world, state_->region, state_->frame,
CellularLivesConfig{state_->config.area, proposal->end_tick, CellularLivesConfig{state_->config.area, proposal->end_tick,
state_->config.ambient_temperature_millikelvin}, state_->config.ambient_temperature_millikelvin},
state_->nursery_config, state_->nursery_config, std::move(*next_habitat),
std::move(*next_habitat), std::move(next_lives), std::move(next_corpses), next_archive, std::move(next_lives), std::move(next_corpses), next_archive,
state_->nursery, next_heat, state_->opening_total, *total); state_->nursery, next_heat, state_->opening_total, *total);
std::vector<CellularLifeTickFeedback> feedback;
feedback.reserve(proposal->lives.size());
for (const auto& result : proposal->lives) {
const auto input =
std::ranges::lower_bound(ordered, result.life_id, {},
[](const CellularLifeIntent& value) { return value.life_id; });
feedback.push_back({result.life_id, proposal->end_tick, result.candidate.reserve_after,
result.candidate.maintenance_cost, result.candidate.movement_cost,
result.candidate.movement_status, result.candidate.intake_status});
if (input == ordered.end() || input->life_id != result.life_id)
return std::unexpected{CellularLivesError::invalid_intents};
}
state_.swap(next); state_.swap(next);
last_tick_feedback_ = std::move(feedback);
return std::move(*proposal); return std::move(*proposal);
} }
} // namespace evo::server } // namespace evo::server
+16 -7
View File
@@ -422,7 +422,8 @@ struct RegionSessions::Impl {
c.protocol_version == network::session_protocol_v6) || c.protocol_version == network::session_protocol_v6) ||
(config.accept_cellular_actions && (config.accept_cellular_actions &&
(c.protocol_version == network::session_protocol_v7 || (c.protocol_version == network::session_protocol_v7 ||
c.protocol_version == network::session_protocol_v8))))) c.protocol_version == network::session_protocol_v8 ||
c.protocol_version == network::session_protocol_v9)))))
return close(c, SessionCloseReason::protocol, now); return close(c, SessionCloseReason::protocol, now);
if (const auto* ack = std::get_if<network::SnapshotAck>(&*decoded)) if (const auto* ack = std::get_if<network::SnapshotAck>(&*decoded))
return replication.acknowledge(c.session, *ack); return replication.acknowledge(c.session, *ack);
@@ -589,9 +590,10 @@ struct RegionSessions::Impl {
(wire_version == network::session_protocol_v5 && !primitive_v5) || (wire_version == network::session_protocol_v5 && !primitive_v5) ||
(wire_version == network::session_protocol_v6 && !cellular_v6) || (wire_version == network::session_protocol_v6 && !cellular_v6) ||
((wire_version == network::session_protocol_v7 || ((wire_version == network::session_protocol_v7 ||
wire_version == network::session_protocol_v8) && wire_version == network::session_protocol_v8 ||
wire_version == network::session_protocol_v9) &&
!cellular_actions) || !cellular_actions) ||
wire_version > network::session_protocol_v8) wire_version > network::session_protocol_v9)
return close(c, SessionCloseReason::unsupported_version, now); return close(c, SessionCloseReason::unsupported_version, now);
} else if (wire_version != c.protocol_version) { } else if (wire_version != c.protocol_version) {
return close(c, SessionCloseReason::unsupported_version, now); return close(c, SessionCloseReason::unsupported_version, now);
@@ -615,7 +617,8 @@ struct RegionSessions::Impl {
} }
if (const auto* m = std::get_if<network::CellularAction>(&*decoded)) { if (const auto* m = std::get_if<network::CellularAction>(&*decoded)) {
if (c.protocol_version != network::session_protocol_v7 && if (c.protocol_version != network::session_protocol_v7 &&
c.protocol_version != network::session_protocol_v8) c.protocol_version != network::session_protocol_v8 &&
c.protocol_version != network::session_protocol_v9)
return close(c, SessionCloseReason::protocol, now); return close(c, SessionCloseReason::protocol, now);
if (const auto receipt = intents.admit(c.session, *m, admission())) if (const auto receipt = intents.admit(c.session, *m, admission()))
answer(c, *receipt); answer(c, *receipt);
@@ -881,10 +884,15 @@ bool RegionSessions::send_cellular_perception(const network::AccountId& account,
auto& m = *impl_; auto& m = *impl_;
for (const auto& c : m.connections) { for (const auto& c : m.connections) {
if (c.state != Impl::State::established || if (c.state != Impl::State::established ||
c.protocol_version != network::session_protocol_v8 || c.account_id != account) (c.protocol_version != network::session_protocol_v8 &&
c.protocol_version != network::session_protocol_v9) ||
c.account_id != account)
continue; continue;
auto delivered = perception;
if (c.protocol_version == network::session_protocol_v8)
delivered.diagnostics.reset();
return m.endpoint return m.endpoint
->send_message(c.id, network::encode_session(perception, c.protocol_version)) ->send_message(c.id, network::encode_session(delivered, c.protocol_version))
.has_value(); .has_value();
} }
return false; return false;
@@ -897,7 +905,8 @@ void RegionSessions::clear_cellular_perceptions(std::uint64_t tick) {
const network::CellularPerception cleared{tick, 0, {}}; const network::CellularPerception cleared{tick, 0, {}};
for (const auto& c : m.connections) for (const auto& c : m.connections)
if (c.state == Impl::State::established && if (c.state == Impl::State::established &&
c.protocol_version == network::session_protocol_v8) (c.protocol_version == network::session_protocol_v8 ||
c.protocol_version == network::session_protocol_v9))
m.send(c, cleared); m.send(c, cleared);
} }
+27 -19
View File
@@ -1,12 +1,12 @@
#include "evo/server/lifecycle/cellular_lives.hpp"
#include "evo/server/lifecycle/cellular_batch.hpp" #include "evo/server/lifecycle/cellular_batch.hpp"
#include "evo/server/lifecycle/cellular_lives.hpp"
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <span>
#include <source_location> #include <source_location>
#include <span>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -51,7 +51,8 @@ std::unique_ptr<CellularLives> empty_cellular_owner(Inventory funding,
CHECK(primitive); CHECK(primitive);
auto habitat = evo::biology::CellularHabitat::create({91, 1, 1, 1'000, 1'000, {}}); auto habitat = evo::biology::CellularHabitat::create({91, 1, 1, 1'000, 1'000, {}});
CHECK(habitat); CHECK(habitat);
auto owner = CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 0, 293'150}); auto owner =
CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 0, 293'150});
CHECK(owner); CHECK(owner);
CHECK((*owner)->ambient_temperature_millikelvin() == 293'150); CHECK((*owner)->ambient_temperature_millikelvin() == 293'150);
return std::move(*owner); return std::move(*owner);
@@ -92,8 +93,7 @@ void reserved_birth_is_funded_and_detached() {
CHECK(opening->birth_candidate(request, {502, 502, 502, 502, {2}}).error() == CHECK(opening->birth_candidate(request, {502, 502, 502, 502, {2}}).error() ==
CellularLivesError::invalid_tick); CellularLivesError::invalid_tick);
const std::array next_tick{CellularLifeIntent{allocation.life, {}}}; const std::array next_tick{CellularLifeIntent{allocation.life, {}}};
CHECK((*born)->advance_tick(next_tick) && (*born)->tick() == 2 && CHECK((*born)->advance_tick(next_tick) && (*born)->tick() == 2 && (*born)->lives().size() == 1);
(*born)->lives().size() == 1);
auto trace_base = empty_cellular_owner(founder_price(1), {{0, 0}}); auto trace_base = empty_cellular_owner(founder_price(1), {{0, 0}});
CellularBatch birth_batch; CellularBatch birth_batch;
@@ -134,15 +134,13 @@ void reserved_birth_is_funded_and_detached() {
CellularLivesError::insufficient_funding); CellularLivesError::insufficient_funding);
CHECK(unfunded->snapshot() == unfunded_snapshot && unfunded->lives().empty()); CHECK(unfunded->snapshot() == unfunded_snapshot && unfunded->lives().empty());
auto occupied_primitive = auto occupied_primitive = PrimitiveLives::create({92, 1, 1, 17, founder_price(2), {{0, 0}}});
PrimitiveLives::create({92, 1, 1, 17, founder_price(2), {{0, 0}}});
CHECK(occupied_primitive); CHECK(occupied_primitive);
LifeRequest existing{}; LifeRequest existing{};
existing.account.back() = 11; existing.account.back() = 11;
existing.action = 1; existing.action = 1;
CHECK((*occupied_primitive)->spawn(existing, {701, 701, 701, 701, {1}})); CHECK((*occupied_primitive)->spawn(existing, {701, 701, 701, 701, {1}}));
auto occupied_habitat = auto occupied_habitat = evo::biology::CellularHabitat::create({92, 1, 1, 1'000, 1'000, {}});
evo::biology::CellularHabitat::create({92, 1, 1, 1'000, 1'000, {}});
CHECK(occupied_habitat); CHECK(occupied_habitat);
auto occupied = CellularLives::create(**occupied_primitive, std::move(*occupied_habitat), auto occupied = CellularLives::create(**occupied_primitive, std::move(*occupied_habitat),
{{1'000, 1'000}, 1, 293'150}); {{1'000, 1'000}, 1, 293'150});
@@ -168,8 +166,8 @@ void owner_advances_and_closes_death_atomically() {
90, 1, 7, 3'000, 2'000, {{{0, 0}, 29, {{10}, {{{10}, {10}, {10}, {10}}}}}}}; 90, 1, 7, 3'000, 2'000, {{{0, 0}, 29, {{10}, {{{10}, {10}, {10}, {10}}}}}}};
auto habitat = evo::biology::CellularHabitat::create(std::move(habitat_config)); auto habitat = evo::biology::CellularHabitat::create(std::move(habitat_config));
CHECK(habitat); CHECK(habitat);
auto created = CellularLives::create( auto created =
**primitive, std::move(*habitat), {{3'000, 2'000}, 1, 293'150}); CellularLives::create(**primitive, std::move(*habitat), {{3'000, 2'000}, 1, 293'150});
CHECK(created); CHECK(created);
auto& owner = **created; auto& owner = **created;
CHECK(owner.world() == 90 && owner.region() == 1 && owner.frame() == 7); CHECK(owner.world() == 90 && owner.region() == 1 && owner.frame() == 7);
@@ -187,8 +185,7 @@ void owner_advances_and_closes_death_atomically() {
visible_patches->front().address == (evo::biology::CellularPatchAddress{0, 0}) && visible_patches->front().address == (evo::biology::CellularPatchAddress{0, 0}) &&
visible_patches->front().available == owner.habitat().patches()[0].stock); visible_patches->front().available == owner.habitat().patches()[0].stock);
CHECK(owner.perceive(0).error() == CellularLivesError::invalid_life); CHECK(owner.perceive(0).error() == CellularLivesError::invalid_life);
const std::array invalid_motion{ const std::array invalid_motion{CellularLifeIntent{first_life_id, {}},
CellularLifeIntent{first_life_id, {}},
CellularLifeIntent{second_life_id, {{1'001, 0}, std::nullopt}}}; CellularLifeIntent{second_life_id, {{1'001, 0}, std::nullopt}}};
const auto partial = owner.advance_tick(invalid_motion); const auto partial = owner.advance_tick(invalid_motion);
CHECK(!partial && partial.error() == CellularLivesError::region_step && owner.tick() == 1 && CHECK(!partial && partial.error() == CellularLivesError::region_step && owner.tick() == 1 &&
@@ -200,6 +197,15 @@ void owner_advances_and_closes_death_atomically() {
CHECK(fed && owner.tick() == 2 && owner.lives().size() == 2); CHECK(fed && owner.tick() == 2 && owner.lives().size() == 2);
CHECK(fed->lives.size() == 2 && CHECK(fed->lives.size() == 2 &&
fed->lives[0].candidate.intake_status == evo::biology::CellularIntakeStatus::acquired); fed->lives[0].candidate.intake_status == evo::biology::CellularIntakeStatus::acquired);
CHECK(owner.last_tick_feedback().size() == 2 &&
owner.last_tick_feedback()[0].tick == owner.tick() &&
owner.last_tick_feedback()[0].life_id == owner.lives()[0].identity.life &&
owner.last_tick_feedback()[0].reserve == fed->lives[0].candidate.reserve_after &&
owner.last_tick_feedback()[0].maintenance_cost ==
fed->lives[0].candidate.maintenance_cost &&
owner.last_tick_feedback()[0].movement ==
evo::biology::CellularMovementStatus::not_requested &&
owner.last_tick_feedback()[0].intake == evo::biology::CellularIntakeStatus::acquired);
CHECK(owner.habitat().patches()[0].stock == (Inventory{{0}, {}})); CHECK(owner.habitat().patches()[0].stock == (Inventory{{0}, {}}));
CHECK(owner.current_total() == owner.opening_total()); CHECK(owner.current_total() == owner.opening_total());
@@ -207,6 +213,7 @@ void owner_advances_and_closes_death_atomically() {
CHECK(saved.size() <= max_cellular_lives_bytes); CHECK(saved.size() <= max_cellular_lives_bytes);
auto recovered = CellularLives::restore(saved, 90, 1, 7, owner.tick()); auto recovered = CellularLives::restore(saved, 90, 1, 7, owner.tick());
CHECK(recovered && (*recovered)->snapshot() == saved); CHECK(recovered && (*recovered)->snapshot() == saved);
CHECK((*recovered)->last_tick_feedback().empty()); // Transient presentation is not restored.
CHECK(!CellularLives::restore(saved, 91, 1, 7, owner.tick())); CHECK(!CellularLives::restore(saved, 91, 1, 7, owner.tick()));
CHECK(!CellularLives::restore(saved, 90, 1, 7, owner.tick() + 1)); CHECK(!CellularLives::restore(saved, 90, 1, 7, owner.tick() + 1));
auto damaged = saved; auto damaged = saved;
@@ -216,8 +223,7 @@ void owner_advances_and_closes_death_atomically() {
auto unsupported = saved; auto unsupported = saved;
unsupported[8] = static_cast<std::uint8_t>(cellular_lives_format + 1); unsupported[8] = static_cast<std::uint8_t>(cellular_lives_format + 1);
refresh_checksum(unsupported); refresh_checksum(unsupported);
const auto unsupported_result = const auto unsupported_result = CellularLives::restore(unsupported, 90, 1, 7, owner.tick());
CellularLives::restore(unsupported, 90, 1, 7, owner.tick());
CHECK(!unsupported_result && unsupported_result.error() == CellularLivesError::version); CHECK(!unsupported_result && unsupported_result.error() == CellularLivesError::version);
auto outside = saved; auto outside = saved;
std::fill(outside.begin() + 300, outside.begin() + 308, uint8_t{0xff}); std::fill(outside.begin() + 300, outside.begin() + 308, uint8_t{0xff});
@@ -225,8 +231,8 @@ void owner_advances_and_closes_death_atomically() {
CHECK(!CellularLives::restore(outside, 90, 1, 7, owner.tick())); CHECK(!CellularLives::restore(outside, 90, 1, 7, owner.tick()));
CellularBatch replay_batch; CellularBatch replay_batch;
replay_batch.header = {owner.world(), owner.region(), owner.frame(), {}, {}, owner.tick(), replay_batch.header = {owner.world(), owner.region(), owner.frame(), {}, {},
owner.tick() + 2}; owner.tick(), owner.tick() + 2};
replay_batch.header.predecessor.fill(0x31); replay_batch.header.predecessor.fill(0x31);
replay_batch.header.predecessor_digest.fill(0x41); replay_batch.header.predecessor_digest.fill(0x41);
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
@@ -246,8 +252,8 @@ void owner_advances_and_closes_death_atomically() {
const std::array actions{action}; const std::array actions{action};
const auto action_bytes = encode_cellular_action_block(actions, owner.tick(), owner.tick() + 2); const auto action_bytes = encode_cellular_action_block(actions, owner.tick(), owner.tick() + 2);
CHECK(action_bytes && action_bytes->size() == cellular_action_record_bytes); CHECK(action_bytes && action_bytes->size() == cellular_action_record_bytes);
const auto decoded_actions = decode_cellular_action_block( const auto decoded_actions =
*action_bytes, owner.tick(), owner.tick() + 2); decode_cellular_action_block(*action_bytes, owner.tick(), owner.tick() + 2);
CHECK(decoded_actions && *decoded_actions == std::vector<CellularActionRecord>{action}); CHECK(decoded_actions && *decoded_actions == std::vector<CellularActionRecord>{action});
CHECK(match_cellular_actions_to_trace(owner, *decoded_batch, *decoded_actions)); CHECK(match_cellular_actions_to_trace(owner, *decoded_batch, *decoded_actions));
auto changed_action = action; auto changed_action = action;
@@ -257,6 +263,8 @@ void owner_advances_and_closes_death_atomically() {
CellularActionBlockError::mismatch); CellularActionBlockError::mismatch);
const auto replayed_batch = replay_cellular_batch(owner, *decoded_batch); const auto replayed_batch = replay_cellular_batch(owner, *decoded_batch);
CHECK(replayed_batch && (*replayed_batch)->tick() == owner.tick() + 2); CHECK(replayed_batch && (*replayed_batch)->tick() == owner.tick() + 2);
CHECK((*replayed_batch)->last_tick_feedback().size() == owner.lives().size() &&
(*replayed_batch)->last_tick_feedback()[0].tick == (*replayed_batch)->tick());
CHECK((*replayed_batch)->current_total() == owner.opening_total()); CHECK((*replayed_batch)->current_total() == owner.opening_total());
auto short_batch = *batch_bytes; auto short_batch = *batch_bytes;
short_batch.pop_back(); short_batch.pop_back();
+2
View File
@@ -45,6 +45,7 @@ void maintenance_motion_and_intake_conserve_one_tick() {
CHECK(step->begin_tick == 12 && step->end_tick == 13); CHECK(step->begin_tick == 12 && step->end_tick == 13);
CHECK(step->position == CellularPosition{10, 0}); CHECK(step->position == CellularPosition{10, 0});
CHECK(step->maintenance_cost.value == 5 && step->movement_cost.value == 50); CHECK(step->maintenance_cost.value == 5 && step->movement_cost.value == 50);
CHECK(step->movement_status == CellularMovementStatus::moved);
CHECK(step->heat_after.energy.value == 55); CHECK(step->heat_after.energy.value == 55);
CHECK(step->reserve_after == Inventory{{195}, {{{5}, {2}, {1}, {0}}}}); CHECK(step->reserve_after == Inventory{{195}, {{{5}, {2}, {1}, {0}}}});
if (step->intake_status != CellularIntakeStatus::acquired || !step->intake) if (step->intake_status != CellularIntakeStatus::acquired || !step->intake)
@@ -73,6 +74,7 @@ void maintenance_precedes_motion_and_intake() {
CHECK(step); CHECK(step);
CHECK(step->position == CellularPosition{0, 0}); CHECK(step->position == CellularPosition{0, 0});
CHECK(step->movement_cost.value == 0); CHECK(step->movement_cost.value == 0);
CHECK(step->movement_status == CellularMovementStatus::insufficient_reserve);
CHECK(step->maintenance_cost.value == 5 && step->heat_after.energy.value == 5); CHECK(step->maintenance_cost.value == 5 && step->heat_after.energy.value == 5);
CHECK(step->intake_status == CellularIntakeStatus::acquired); CHECK(step->intake_status == CellularIntakeStatus::acquired);
CHECK(step->reserve_after.energy.value == 99); // Intake cannot fund this tick's move. CHECK(step->reserve_after.energy.value == 99); // Intake cannot fund this tick's move.
+30 -5
View File
@@ -611,7 +611,7 @@ void cellular_v5_spawn_and_v7_action_share_region_sessions(const Files& f) {
} actions; } actions;
FakeLedger control; FakeLedger control;
Harness h{ Harness h{
f, 4, 64, &control, [&](server::RegionSessionsConfig& c) { f, 5, 64, &control, [&](server::RegionSessionsConfig& c) {
c.actions = &actions; c.actions = &actions;
c.accept_cellular_actions = true; c.accept_cellular_actions = true;
c.create_primitive_life = [](const AccountId&, std::uint64_t, std::uint64_t request) { c.create_primitive_life = [](const AccountId&, std::uint64_t, std::uint64_t request) {
@@ -624,13 +624,16 @@ void cellular_v5_spawn_and_v7_action_share_region_sessions(const Files& f) {
auto spawn_client = h.connect(h.issuer.grant(account(0xB5), 1), session_protocol_v5); auto spawn_client = h.connect(h.issuer.grant(account(0xB5), 1), session_protocol_v5);
auto action_client = h.connect(h.issuer.grant(account(0xB7), 1), session_protocol_v7); auto action_client = h.connect(h.issuer.grant(account(0xB7), 1), session_protocol_v7);
const auto owner_account = account(0xB8); const auto owner_account = account(0xB8);
auto perception_owner = h.connect(h.issuer.grant(owner_account, 1), session_protocol_v8); auto perception_owner = h.connect(h.issuer.grant(owner_account, 1), session_protocol_v9);
auto other_owner = h.connect(h.issuer.grant(account(0xB9), 1), session_protocol_v8); auto other_owner = h.connect(h.issuer.grant(account(0xB9), 1), session_protocol_v9);
const auto legacy_account = account(0xBA);
auto legacy_owner = h.connect(h.issuer.grant(legacy_account, 1), session_protocol_v8);
CHECK(h.settled(*spawn_client) && spawn_client->state() == RegionSessionState::established); CHECK(h.settled(*spawn_client) && spawn_client->state() == RegionSessionState::established);
CHECK(h.settled(*action_client) && action_client->state() == RegionSessionState::established); CHECK(h.settled(*action_client) && action_client->state() == RegionSessionState::established);
CHECK(h.settled(*perception_owner) && CHECK(h.settled(*perception_owner) &&
perception_owner->state() == RegionSessionState::established); perception_owner->state() == RegionSessionState::established);
CHECK(h.settled(*other_owner) && other_owner->state() == RegionSessionState::established); CHECK(h.settled(*other_owner) && other_owner->state() == RegionSessionState::established);
CHECK(h.settled(*legacy_owner) && legacy_owner->state() == RegionSessionState::established);
CHECK(spawn_client->request_primitive_life(44)); CHECK(spawn_client->request_primitive_life(44));
std::vector<PrimitiveLifeOutcome> birth_outcomes; std::vector<PrimitiveLifeOutcome> birth_outcomes;
@@ -665,19 +668,41 @@ void cellular_v5_spawn_and_v7_action_share_region_sessions(const Files& f) {
action_client->view()->organisms.front().id == 901); action_client->view()->organisms.front().id == 901);
CHECK(action_client->set_interest({1, 0, 0, 2})); CHECK(action_client->set_interest({1, 0, 0, 2}));
const CellularPerception perception{101, 901, {{1'000, 2'000, 3, {4, 5, 6, 7}}}}; CellularPerception perception{101, 901, {{1'000, 2'000, 3, {4, 5, 6, 7}}}};
CellularLifeDiagnostics diagnostics;
diagnostics.reserve_energy_pj = 88;
diagnostics.reserve_matter_fg = {9, 10, 11, 12};
diagnostics.maintenance_cost_pj = 3;
diagnostics.movement_cost_pj = 2;
diagnostics.movement = CellularMovementResult::moved;
diagnostics.intake = CellularIntakeResult::acquired;
diagnostics.has_tick_effects = true;
perception.diagnostics = diagnostics;
CHECK(h.server->send_cellular_perception(owner_account, perception)); CHECK(h.server->send_cellular_perception(owner_account, perception));
CHECK(h.until([&] { CHECK(h.until([&] {
return perception_owner->cellular_perception() && return perception_owner->cellular_perception() &&
perception_owner->cellular_perception()->tick == perception.tick; perception_owner->cellular_perception()->tick == perception.tick;
})); }));
CHECK(*perception_owner->cellular_perception() == perception); CHECK(*perception_owner->cellular_perception() == perception);
CHECK(!other_owner->cellular_perception() && !action_client->cellular_perception()); CHECK(!other_owner->cellular_perception() && !legacy_owner->cellular_perception() &&
!action_client->cellular_perception());
CHECK(h.server->send_cellular_perception(legacy_account, perception));
CHECK(h.until([&] {
return legacy_owner->cellular_perception() &&
legacy_owner->cellular_perception()->tick == perception.tick;
}));
auto legacy_perception = perception;
legacy_perception.diagnostics.reset();
CHECK(*legacy_owner->cellular_perception() == legacy_perception);
h.server->clear_cellular_perceptions(102); h.server->clear_cellular_perceptions(102);
CHECK(h.until([&] { CHECK(h.until([&] {
return perception_owner->cellular_perception() && return perception_owner->cellular_perception() &&
perception_owner->cellular_perception()->tick == 102; perception_owner->cellular_perception()->tick == 102;
})); }));
CHECK(h.until([&] {
return legacy_owner->cellular_perception() &&
legacy_owner->cellular_perception()->tick == 102;
}));
CHECK(perception_owner->cellular_perception()->life_identity == 0 && CHECK(perception_owner->cellular_perception()->life_identity == 0 &&
perception_owner->cellular_perception()->patches.empty()); perception_owner->cellular_perception()->patches.empty());
} }