Add explicit primitive genesis provisioning
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (client) (push) Canceled after 3m38s
Foundation / checks (checks) (push) Canceled after 3m44s
Foundation / checks (network) (push) Canceled after 1m39s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (client) (push) Canceled after 3m38s
Foundation / checks (checks) (push) Canceled after 3m44s
Foundation / checks (network) (push) Canceled after 1m39s
This commit is contained in:
+127
-17
@@ -9,8 +9,10 @@
|
||||
// [--max-commits N]
|
||||
// evo-world-clone check-store --world W --region R --pg-* ... --objects DIR
|
||||
// [--reserve-mib N]
|
||||
// evo-world-clone provision --world W --region R --opening development-v1 --pg-* ...
|
||||
// --objects DIR --build HEX [--retain-build]
|
||||
// evo-world-clone provision --world W --region R --opening development-v1|primitive-v1
|
||||
// --pg-* ... --objects DIR --build HEX [--retain-build]
|
||||
// primitive-v1 also requires --frame N --source-id N, every --funding-*-* channel,
|
||||
// and one or more ordered --site X,Y values.
|
||||
// evo-world-clone compare --world A --region R --other-world B --pg-* ...
|
||||
// --objects DIR [--other-objects DIR] --retained HEX... [--max-commits N]
|
||||
//
|
||||
@@ -40,6 +42,8 @@
|
||||
// records the build identity (the server image digest) in retained_builds. The only
|
||||
// opening is development-v1 (evo/processes/development_opening.hpp), for dev and
|
||||
// stage; World0's opening is a separate, reviewed decision.
|
||||
// primitive-v1 requires operator-supplied frame/source IDs, all five finite source inventory
|
||||
// channels, and ordered habitat sites; no channel, site or profile is inferred.
|
||||
// Output: provisioned|already-provisioned world=W region=R sequence=S tick=T
|
||||
//
|
||||
// compare (M8.9, ADR-0076) fully audits both regions of one database, then requires
|
||||
@@ -53,7 +57,9 @@
|
||||
#include "evo/persistence/region_clone.hpp"
|
||||
#include "evo/persistence/sha256.hpp"
|
||||
#include "evo/processes/development_opening.hpp"
|
||||
#include "evo/server/lifecycle/primitive_lives.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
#include <csignal>
|
||||
@@ -84,6 +90,9 @@ struct Options {
|
||||
std::optional<persistence::Uuid> commit;
|
||||
std::uint64_t audit_max{}, max_commits{1u << 20U}, reserve_mib{1024};
|
||||
std::string opening;
|
||||
std::optional<std::uint64_t> primitive_frame, primitive_source;
|
||||
std::array<std::optional<std::uint64_t>, 5> primitive_funding;
|
||||
std::vector<server::SpawnSite> primitive_sites;
|
||||
std::optional<persistence::Sha256Digest> build;
|
||||
bool retain_build{};
|
||||
bool crash{};
|
||||
@@ -96,6 +105,19 @@ std::optional<std::uint64_t> number(std::string_view text) {
|
||||
return std::nullopt;
|
||||
return value;
|
||||
}
|
||||
std::optional<server::SpawnSite> site(std::string_view text) {
|
||||
const auto comma = text.find(',');
|
||||
if (comma == std::string_view::npos || text.find(',', comma + 1) != std::string_view::npos)
|
||||
return std::nullopt;
|
||||
std::int32_t x{}, y{};
|
||||
const auto [x_end, x_error] = std::from_chars(text.data(), text.data() + comma, x);
|
||||
const auto [y_end, y_error] =
|
||||
std::from_chars(text.data() + comma + 1, text.data() + text.size(), y);
|
||||
if (x_error != std::errc{} || x_end != text.data() + comma || y_error != std::errc{} ||
|
||||
y_end != text.data() + text.size())
|
||||
return std::nullopt;
|
||||
return server::SpawnSite{x, y};
|
||||
}
|
||||
template <std::size_t N> std::optional<std::array<std::uint8_t, N>> hex(std::string_view text) {
|
||||
if (text.size() != N * 2)
|
||||
return std::nullopt;
|
||||
@@ -204,9 +226,29 @@ std::optional<Options> parse(int argc, char** argv) {
|
||||
o.max_commits = *n;
|
||||
else if (o.command == "check-store" && flag == "--reserve-mib" && n && *n <= 1048576)
|
||||
o.reserve_mib = *n;
|
||||
else if (o.command == "provision" && flag == "--opening" && value == "development-v1")
|
||||
else if (o.command == "provision" && flag == "--opening" &&
|
||||
(value == "development-v1" || value == "primitive-v1"))
|
||||
o.opening = value;
|
||||
else if (o.command == "provision" && flag == "--build" && hex<32>(value))
|
||||
else if (o.command == "provision" && flag == "--frame" && n)
|
||||
o.primitive_frame = *n;
|
||||
else if (o.command == "provision" && flag == "--source-id" && n)
|
||||
o.primitive_source = *n;
|
||||
else if (o.command == "provision" && flag == "--funding-energy-pj" && n)
|
||||
o.primitive_funding[0] = *n;
|
||||
else if (o.command == "provision" && flag == "--funding-carbon-fg" && n)
|
||||
o.primitive_funding[1] = *n;
|
||||
else if (o.command == "provision" && flag == "--funding-nitrogen-fg" && n)
|
||||
o.primitive_funding[2] = *n;
|
||||
else if (o.command == "provision" && flag == "--funding-phosphorus-fg" && n)
|
||||
o.primitive_funding[3] = *n;
|
||||
else if (o.command == "provision" && flag == "--funding-other-fg" && n)
|
||||
o.primitive_funding[4] = *n;
|
||||
else if (o.command == "provision" && flag == "--site") {
|
||||
const auto parsed = site(value);
|
||||
if (!parsed || o.primitive_sites.size() == server::max_primitive_lives)
|
||||
return std::nullopt;
|
||||
o.primitive_sites.push_back(*parsed);
|
||||
} else if (o.command == "provision" && flag == "--build" && hex<32>(value))
|
||||
o.build = hex<32>(value);
|
||||
else if (o.command == "provision" && flag == "--retain-build" && value == "true")
|
||||
o.retain_build = true;
|
||||
@@ -224,8 +266,23 @@ std::optional<Options> parse(int argc, char** argv) {
|
||||
o.target.objects = o.source.objects;
|
||||
}
|
||||
const bool needs_builds = o.command != "check-store" && o.command != "provision";
|
||||
if (o.command == "provision" && (o.opening.empty() || !o.build))
|
||||
return std::nullopt;
|
||||
if (o.command == "provision") {
|
||||
if (o.opening.empty() || !o.build)
|
||||
return std::nullopt;
|
||||
const bool primitive_options =
|
||||
o.primitive_frame || o.primitive_source ||
|
||||
std::ranges::any_of(o.primitive_funding, [](const auto& v) { return v.has_value(); }) ||
|
||||
!o.primitive_sites.empty();
|
||||
if (o.opening == "primitive-v1") {
|
||||
if (!o.primitive_frame || *o.primitive_frame == 0 || !o.primitive_source ||
|
||||
*o.primitive_source == 0 || o.primitive_sites.empty() ||
|
||||
!std::ranges::all_of(o.primitive_funding,
|
||||
[](const auto& v) { return v.has_value(); }))
|
||||
return std::nullopt;
|
||||
} else if (primitive_options) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
if (!complete(o.source) || (needs_builds && o.retained.empty()) ||
|
||||
(clone && !complete(o.target)))
|
||||
return std::nullopt;
|
||||
@@ -292,9 +349,9 @@ const char* name(persistence::CloneError e) {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
std::unique_ptr<persistence::FilesystemObjectStore> open_objects(const Side& s) {
|
||||
auto store = persistence::FilesystemObjectStore::open(s.objects, s.key,
|
||||
persistence::max_lineage_payload_bytes);
|
||||
std::unique_ptr<persistence::FilesystemObjectStore>
|
||||
open_objects(const Side& s, std::size_t max_payload = persistence::max_lineage_payload_bytes) {
|
||||
auto store = persistence::FilesystemObjectStore::open(s.objects, s.key, max_payload);
|
||||
if (!store)
|
||||
return nullptr;
|
||||
return std::move(*store);
|
||||
@@ -317,7 +374,10 @@ std::vector<std::uint8_t> probe_bytes() {
|
||||
}
|
||||
|
||||
int provision(const Options& o) {
|
||||
auto store = open_objects(o.source);
|
||||
const bool primitive = o.opening == "primitive-v1";
|
||||
const auto payload_limit =
|
||||
primitive ? server::max_primitive_lives_bytes : persistence::max_lineage_payload_bytes;
|
||||
auto store = open_objects(o.source, payload_limit);
|
||||
if (!store) {
|
||||
std::puts("objects refused");
|
||||
return 4;
|
||||
@@ -339,6 +399,24 @@ int provision(const Options& o) {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
std::unique_ptr<server::PrimitiveLives> primitive_opening;
|
||||
if (primitive) {
|
||||
server::NurseryConfig config{};
|
||||
config.world = o.source.key.world;
|
||||
config.region = o.source.key.region;
|
||||
config.frame = *o.primitive_frame;
|
||||
config.source = *o.primitive_source;
|
||||
config.funding.energy.value = *o.primitive_funding[0];
|
||||
for (std::size_t i = 0; i < 4; ++i)
|
||||
config.funding.matter[i].value = *o.primitive_funding[i + 1];
|
||||
config.sites = o.primitive_sites;
|
||||
auto opening = server::PrimitiveLives::create(std::move(config));
|
||||
if (!opening) {
|
||||
std::printf("primitive opening refused %u\n", static_cast<unsigned>(opening.error()));
|
||||
return 4;
|
||||
}
|
||||
primitive_opening = std::move(*opening);
|
||||
}
|
||||
const auto report = [&](const char* what, const persistence::RegionHead& head) {
|
||||
std::printf("%s world=%llu region=%llu sequence=%llu tick=%llu\n", what,
|
||||
static_cast<unsigned long long>(o.source.key.world),
|
||||
@@ -347,18 +425,50 @@ int provision(const Options& o) {
|
||||
static_cast<unsigned long long>(head.end_tick));
|
||||
return 0;
|
||||
};
|
||||
// Never re-provision: an existing region, whatever its state, is left alone.
|
||||
auto existing = persistence::load_region_head(*db, o.source.key, timeout);
|
||||
if (existing)
|
||||
return report("already-provisioned", *existing);
|
||||
// Never re-provision or report success for a different profile/frame.
|
||||
auto existing = persistence::load_region_checkpoint(*db, o.source.key, timeout);
|
||||
if (existing) {
|
||||
const auto manifest = persistence::decode_manifest(existing->manifest);
|
||||
const auto expected_profile =
|
||||
primitive ? persistence::CheckpointProfile::primitive_lives_v1
|
||||
: persistence::CheckpointProfile::environmental_lineage_v1;
|
||||
const auto expected_frame =
|
||||
primitive ? *o.primitive_frame : processes::development_opening_frame;
|
||||
if (!manifest || manifest->profile != expected_profile ||
|
||||
manifest->frame != expected_frame) {
|
||||
std::puts("provision refused existing profile/frame mismatch");
|
||||
return 4;
|
||||
}
|
||||
if (primitive) {
|
||||
const std::array retained{manifest->build};
|
||||
auto recovered = persistence::recover_primitive_checkpoint(*db, *store, o.source.key,
|
||||
retained, timeout);
|
||||
if (!recovered || recovered->state->snapshot() != primitive_opening->snapshot()) {
|
||||
std::puts("provision refused existing opening mismatch");
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
return report("already-provisioned", existing->head);
|
||||
}
|
||||
if (existing.error().kind != persistence::LeaseStoreError::not_provisioned) {
|
||||
std::puts("database refused");
|
||||
return 3;
|
||||
}
|
||||
auto opening = processes::development_opening(o.source.key.world);
|
||||
persistence::Uuid commit{};
|
||||
if (!opening ||
|
||||
::getrandom(commit.data(), commit.size(), 0) != static_cast<ssize_t>(commit.size()))
|
||||
if (::getrandom(commit.data(), commit.size(), 0) != static_cast<ssize_t>(commit.size()))
|
||||
return 4;
|
||||
if (primitive) {
|
||||
auto made =
|
||||
persistence::provision_primitive_region(*db, *store, o.source.key, *o.primitive_frame,
|
||||
*primitive_opening, commit, build, timeout);
|
||||
if (!made) {
|
||||
std::printf("provision refused %u\n", static_cast<unsigned>(made.error().kind));
|
||||
return 4;
|
||||
}
|
||||
return report("provisioned", made->head);
|
||||
}
|
||||
auto opening = processes::development_opening(o.source.key.world);
|
||||
if (!opening)
|
||||
return 4;
|
||||
auto made = persistence::provision_lineage_region(
|
||||
*db, *store, o.source.key, processes::development_opening_frame, **opening, commit, build,
|
||||
|
||||
Reference in New Issue
Block a user