Add cellular profile region serving
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (ecs) (push) Successful in 1m57s
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 (client) (push) Canceled after 2m58s
Foundation / checks (postgres) (push) Canceled after 52s
Foundation / checks (network) (push) Canceled after 2m23s

This commit is contained in:
dingo
2026-10-11 01:03:05 -04:00
parent ad6f0ff78a
commit 10b042309e
8 changed files with 423 additions and 3 deletions
+198 -2
View File
@@ -54,6 +54,7 @@
// provisioning remain disabled.
#include "evo/biology/founder.hpp"
#include "evo/processes/development_opening.hpp"
#include "evo/server/cellular_session_batch.hpp"
#include "evo/server/lifecycle/primitive_lives.hpp"
#include "evo/server/ops_http.hpp"
#include "evo/server/primitive_region_host.hpp"
@@ -61,6 +62,7 @@
#include "m10_bridge.hpp"
#include "session_bridge.hpp"
#ifdef EVO_SERVER_M10
#include "cellular_bridge.hpp"
#include "evo/server/pg_slot.hpp"
#include "evo/server/postgres_control_ledger.hpp"
#include "evo/server/region_sessions.hpp"
@@ -170,7 +172,8 @@ std::optional<Options> parse(int argc, char** argv) {
const std::string_view value = argv[++i];
const auto n = number(value);
if (flag == "--profile" &&
(value == "lineage" || value == "environmental" || value == "primitive"))
(value == "lineage" || value == "environmental" || value == "primitive" ||
value == "cellular"))
o.profile = value;
else if (flag == "--world" && n)
o.host.key.world = *n;
@@ -316,6 +319,13 @@ std::optional<Options> parse(int argc, char** argv) {
(o.synthetic || !o.crash_point.empty() || o.session.any() || o.m10.any() ||
o.host.flush_interval != 1000ms || o.drain != 10000ms))
return std::nullopt;
if (o.profile == "cellular" &&
(!server_app::m10_available || !o.m10.complete() || o.primitive_session.any() ||
o.synthetic || !o.crash_point.empty() || o.session.any() ||
!o.m10.area.empty() || !o.m10.handoff_key.empty() || !o.m10.neighbours.empty() ||
o.m10.max_grant_lifetime != 0 || !o.m10.load_governor ||
o.host.flush_interval != 1000ms || o.drain != 10000ms))
return std::nullopt;
if (std::ranges::find(o.host.retained_builds, o.host.build) == o.host.retained_builds.end())
o.host.retained_builds.push_back(o.host.build);
return o;
@@ -870,13 +880,195 @@ int serve_primitive(Options& o) {
std::this_thread::sleep_for(5ms);
}
}
#ifdef EVO_SERVER_M10
int serve_cellular(Options& o) {
auto objects = persistence::FilesystemObjectStore::open(
o.objects, o.host.key, server::max_cellular_lives_bytes, nullptr,
o.objects_reserve_mib * 1024 * 1024);
if (!objects) {
std::puts("error objects");
return 2;
}
const auto pg = o.pg;
auto made = server::CellularRegionHost::create(
{o.host.key, o.host.frame, o.host.lease, o.host.build, o.host.retained_builds},
[pg] { return persistence::Postgres::connect(pg, 2s); }, std::move(*objects));
if (!made) {
std::puts("error config");
return 2;
}
auto& host = **made;
auto bridge = server_app::CellularBridge::open(o.m10, host, o.host.key, o.host.frame, o.pg);
if (!bridge)
return 2;
std::unique_ptr<server::OpsServer> ops;
if (!o.ops_listen.empty()) {
auto listening = server::OpsServer::listen(o.ops_listen);
if (!listening) {
std::puts("error ops-listen");
return 2;
}
ops = std::move(*listening);
std::printf("ops listening %u\n", static_cast<unsigned>(ops->port()));
}
bool ready = false;
std::optional<server::HostPhase> phase;
std::optional<std::chrono::steady_clock::time_point> next_tick;
std::vector<network::CarriedAction> awaiting_outcomes;
const auto set_ready = [&](bool now) {
if (ready != now) {
ready = now;
std::printf("ready %d\n", ready ? 1 : 0);
}
if (!o.ready_file.empty()) {
std::error_code ignored;
if (ready)
std::ofstream(o.ready_file) << "ready\n";
else
std::filesystem::remove(o.ready_file, ignored);
}
};
const auto deliver_finalized = [&] {
for (const auto& finalized : host.take_finalized_actions()) {
const auto pending = std::ranges::find_if(awaiting_outcomes, [&](const auto& action) {
return action.account.bytes == finalized.action.account &&
action.action_id == finalized.action.action_id;
});
if (pending == awaiting_outcomes.end())
continue;
const std::array committed{*pending};
bridge->committed(committed, finalized.commit_sequence);
awaiting_outcomes.erase(pending);
}
};
const auto finish = [&](int code) {
set_ready(false);
const auto& status = host.status();
std::printf("phase %s epoch=%llu committed=%llu simulated=%llu\n",
server::phase_name(status.phase),
static_cast<unsigned long long>(status.epoch),
static_cast<unsigned long long>(status.committed_tick),
static_cast<unsigned long long>(status.simulated_tick));
std::printf("stats commits=%llu store_failures=%llu\n",
static_cast<unsigned long long>(status.commits),
static_cast<unsigned long long>(status.store_failures));
std::printf("exit %d\n", code);
std::fflush(stdout);
return code;
};
for (;;) {
if (stop_requested) {
bridge->shutdown();
host.drain();
return finish(0);
}
const auto& status = host.step();
const auto wall = static_cast<std::uint64_t>(
std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
static_cast<void>(bridge->accepting(wall));
bridge->poll(status, wall);
deliver_finalized();
set_ready(status.ready);
if (!phase || *phase != status.phase) {
phase = status.phase;
std::printf("phase %s epoch=%llu committed=%llu simulated=%llu\n",
server::phase_name(status.phase),
static_cast<unsigned long long>(status.epoch),
static_cast<unsigned long long>(status.committed_tick),
static_cast<unsigned long long>(status.simulated_tick));
}
if (ops) {
const auto handler = [&](std::string_view path) -> server::OpsResponse {
const auto& current = host.status();
if (path == "/livez")
return {200, "live\n"};
if (path == "/readyz")
return current.ready ? server::OpsResponse{200, "ready\n"}
: server::OpsResponse{
503, std::string("not ready: ") +
server::phase_name(current.phase) + "\n"};
if (path == "/metrics")
return {200, server::render_metrics(current, {})};
return {404, "not found\n"};
};
ops->serve(handler);
}
if (status.phase == server::HostPhase::quarantined)
return finish(4);
const auto* state = host.state();
bool player_present = false;
if (status.ready && state) {
for (const auto& life : state->lives()) {
network::AccountId account;
account.bytes = life.account;
if (bridge->sessions().holder(account)) {
player_present = true;
break;
}
}
}
const bool birth_waiting = !host.queued_births().empty();
if (status.ready && state && (player_present || birth_waiting)) {
const auto now = std::chrono::steady_clock::now();
if (!next_tick)
next_tick = now + std::chrono::milliseconds{50};
if (now >= *next_tick && state->tick() != UINT64_MAX) {
const auto tick = state->tick() + 1;
std::vector<server::CellularLifeIntent> baseline;
baseline.reserve(state->lives().size());
for (const auto& life : state->lives())
baseline.push_back({life.identity.life, {}});
std::ranges::sort(baseline, {}, &server::CellularLifeIntent::life_id);
auto actions = bridge->carry(tick);
auto builder = server::CellularSessionBatchBuilder::create(
*state, host.committed()->head);
if (!builder) {
bridge->dropped(actions, true);
} else {
const auto births = host.queued_births().first(
std::min(host.queued_births().size(), biology::max_cellular_tick_lives));
const auto appended = builder->append(tick, baseline, actions, births);
if (!appended) {
bridge->dropped(actions, true);
} else {
awaiting_outcomes.insert(awaiting_outcomes.end(), actions.begin(),
actions.end());
auto published = host.publish(builder->batch(), builder->actions());
if (!published && host.status().phase != server::HostPhase::resolving) {
bridge->dropped(actions, true);
std::erase_if(awaiting_outcomes, [&](const auto& action) {
return std::ranges::find(actions, action) != actions.end();
});
}
deliver_finalized();
}
}
*next_tick = std::chrono::steady_clock::now() + std::chrono::microseconds{
static_cast<std::chrono::microseconds::rep>(
biology::cellular_motion_tick_microseconds)};
}
} else {
next_tick.reset(); // A disconnected life does not accumulate offline ticks.
}
if (const auto* committed_state = host.state(); committed_state)
bridge->replicate(*committed_state);
std::fflush(stdout);
std::this_thread::sleep_for(2ms);
}
}
#endif
} // namespace
int main(int argc, char** argv) {
auto options = parse(argc, argv);
if (!options) {
std::fputs(
"usage: evo-server --profile lineage|environmental|primitive --world N --region N "
"usage: evo-server --profile lineage|environmental|primitive|"
"cellular --world N --region N "
"--frame N --pg-host H --pg-port P --pg-database D --pg-user U "
"--objects DIR --build HEX64 [--retained HEX64]... [--pg-hostaddr A "
"--pg-passfile F --pg-ca F] [--flush-ms N] [--drain-ms N] "
@@ -904,6 +1096,10 @@ int main(int argc, char** argv) {
std::signal(SIGPIPE, SIG_IGN);
if (options->profile == "primitive")
return serve_primitive(*options);
#ifdef EVO_SERVER_M10
if (options->profile == "cellular")
return serve_cellular(*options);
#endif
return options->profile == "lineage" ? serve<processes::LineageRegion>(*options)
: serve<processes::EnvironmentalCommunity>(*options);
}