feat(persistence): admit durable funded maturation upgrades
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 2m24s
Foundation / checks (network) (push) Successful in 20m40s
Foundation / checks (client) (push) Successful in 21m57s
Foundation / checks (tsan) (push) Successful in 26m32s
Foundation / checks (postgres) (push) Successful in 1h3m17s
Foundation / checks (checks) (push) Successful in 1h14m29s
Foundation / postgres-tools (push) Successful in 34s
Foundation / server-image (push) Successful in 4m6s
Foundation / image (push) Successful in 4m52s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 2m24s
Foundation / checks (network) (push) Successful in 20m40s
Foundation / checks (client) (push) Successful in 21m57s
Foundation / checks (tsan) (push) Successful in 26m32s
Foundation / checks (postgres) (push) Successful in 1h3m17s
Foundation / checks (checks) (push) Successful in 1h14m29s
Foundation / postgres-tools (push) Successful in 34s
Foundation / server-image (push) Successful in 4m6s
Foundation / image (push) Successful in 4m52s
This commit is contained in:
@@ -243,7 +243,8 @@ retry_cellular_profile_migration(Postgres& db, const CellularProfileMigrationPre
|
||||
manifest->cellular_versions == cellular_v3_versions)) ||
|
||||
((manifest->profile == CheckpointProfile::cellular_lives_v1 ||
|
||||
manifest->profile == CheckpointProfile::cellular_population_v1) &&
|
||||
manifest->cellular_versions == cellular_v10_versions)) ||
|
||||
(manifest->cellular_versions == cellular_v10_versions ||
|
||||
manifest->cellular_versions == cellular_v11_versions))) ||
|
||||
manifest->begin_tick != manifest->end_tick || manifest->batch != BatchDigests{})
|
||||
return std::unexpected{migration_failure(PublicationError::candidate, {}, {}, prepared)};
|
||||
|
||||
@@ -276,11 +277,12 @@ retry_cellular_profile_migration(Postgres& db, const CellularProfileMigrationPre
|
||||
migration_failure(PublicationError::rejected, {}, published.error(), prepared)};
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::expected<CommittedCheckpoint, CellularProfileMigrationFailure>
|
||||
migrate_cellular_boundary_profile(Postgres& db, const FilesystemObjectStore& objects,
|
||||
const LeaseGrant& lease, const CommittedCheckpoint& predecessor,
|
||||
Uuid commit, const Sha256Digest& build, milliseconds timeout,
|
||||
const PublishHooks& hooks) {
|
||||
migrate_rules_profile(Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease,
|
||||
const CommittedCheckpoint& predecessor, Uuid commit,
|
||||
const Sha256Digest& build, milliseconds timeout, const PublishHooks& hooks,
|
||||
bool maturation) {
|
||||
const auto previous = decode_manifest(predecessor.manifest);
|
||||
const auto previous_digest = sha256(predecessor.manifest);
|
||||
if (!previous || !previous_digest || predecessor.head.digest != *previous_digest ||
|
||||
@@ -292,14 +294,17 @@ migrate_cellular_boundary_profile(Postgres& db, const FilesystemObjectStore& obj
|
||||
auto source = objects.get({previous->payload_sha256, previous->payload_bytes});
|
||||
if (!source)
|
||||
return std::unexpected(migration_failure(PublicationError::predecessor, source.error()));
|
||||
auto payload = cellular_boundary_upgrade_payload(*source, *previous);
|
||||
auto payload = maturation ? cellular_maturation_upgrade_payload(*source, *previous)
|
||||
: cellular_boundary_upgrade_payload(*source, *previous);
|
||||
if (!payload)
|
||||
return std::unexpected(migration_failure(PublicationError::candidate));
|
||||
const auto digest = sha256(*payload);
|
||||
if (!digest)
|
||||
return std::unexpected(migration_failure(PublicationError::digest));
|
||||
auto manifest = cellular_boundary_upgrade_manifest(*previous, *previous_digest, commit, lease,
|
||||
build, payload->size(), *digest);
|
||||
const auto derive =
|
||||
maturation ? cellular_maturation_upgrade_manifest : cellular_boundary_upgrade_manifest;
|
||||
auto manifest =
|
||||
derive(*previous, *previous_digest, commit, lease, build, payload->size(), *digest);
|
||||
if (!manifest)
|
||||
return std::unexpected(migration_failure(PublicationError::candidate));
|
||||
auto encoded = encode_manifest(*manifest);
|
||||
@@ -312,6 +317,23 @@ migrate_cellular_boundary_profile(Postgres& db, const FilesystemObjectStore& obj
|
||||
return retry_cellular_profile_migration(db, {previous->key, commit, std::move(*encoded)},
|
||||
timeout);
|
||||
}
|
||||
} // namespace
|
||||
std::expected<CommittedCheckpoint, CellularProfileMigrationFailure>
|
||||
migrate_cellular_boundary_profile(Postgres& db, const FilesystemObjectStore& objects,
|
||||
const LeaseGrant& lease, const CommittedCheckpoint& predecessor,
|
||||
Uuid commit, const Sha256Digest& build, milliseconds timeout,
|
||||
const PublishHooks& hooks) {
|
||||
return migrate_rules_profile(db, objects, lease, predecessor, commit, build, timeout, hooks,
|
||||
false);
|
||||
}
|
||||
std::expected<CommittedCheckpoint, CellularProfileMigrationFailure>
|
||||
migrate_cellular_maturation_profile(Postgres& db, const FilesystemObjectStore& objects,
|
||||
const LeaseGrant& lease, const CommittedCheckpoint& predecessor,
|
||||
Uuid commit, const Sha256Digest& build, milliseconds timeout,
|
||||
const PublishHooks& hooks) {
|
||||
return migrate_rules_profile(db, objects, lease, predecessor, commit, build, timeout, hooks,
|
||||
true);
|
||||
}
|
||||
|
||||
std::expected<CommittedCheckpoint, CellularProfileMigrationFailure>
|
||||
migrate_cellular_profile_to_v2(Postgres& db, const FilesystemObjectStore& objects,
|
||||
@@ -597,18 +619,20 @@ verify_cellular_no_tick_checkpoint(Postgres& db, const FilesystemObjectStore& ob
|
||||
// evidence above is fenced by the CURRENT lease, which may be a newer epoch.
|
||||
const LeaseGrant recorded{m.holder, m.epoch, m.frame, milliseconds{0}};
|
||||
const bool boundary = m.cellular_versions == cellular_v10_versions;
|
||||
auto expected =
|
||||
boundary ? cellular_boundary_upgrade_manifest(*source, *source_digest, m.commit, recorded,
|
||||
m.build, m.payload_bytes, m.payload_sha256)
|
||||
: cellular_profile_migration_manifest(*source, *source_digest, m.commit, recorded,
|
||||
m.build, m.payload_bytes, m.payload_sha256);
|
||||
const bool maturation = m.cellular_versions == cellular_v11_versions;
|
||||
const auto derive = maturation ? cellular_maturation_upgrade_manifest
|
||||
: boundary ? cellular_boundary_upgrade_manifest
|
||||
: cellular_profile_migration_manifest;
|
||||
auto expected = derive(*source, *source_digest, m.commit, recorded, m.build, m.payload_bytes,
|
||||
m.payload_sha256);
|
||||
if (!expected || *expected != m)
|
||||
return fail(RecoveryError::history);
|
||||
auto bytes = objects.get({source->payload_sha256, source->payload_bytes});
|
||||
if (!bytes)
|
||||
return fail(RecoveryError::tail);
|
||||
if (boundary) {
|
||||
auto upgraded = cellular_boundary_upgrade_payload(*bytes, *source);
|
||||
if (boundary || maturation) {
|
||||
auto upgraded = maturation ? cellular_maturation_upgrade_payload(*bytes, *source)
|
||||
: cellular_boundary_upgrade_payload(*bytes, *source);
|
||||
if (!upgraded || !std::ranges::equal(*upgraded, payload))
|
||||
return fail(RecoveryError::history);
|
||||
} else {
|
||||
|
||||
@@ -80,23 +80,24 @@ restore_population_payload(std::span<const std::uint8_t> payload, const Checkpoi
|
||||
return std::move(*state);
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::expected<CheckpointManifest, CheckpointError>
|
||||
cellular_boundary_upgrade_manifest(const CheckpointManifest& previous,
|
||||
const Sha256Digest& previous_digest, Uuid commit,
|
||||
const LeaseGrant& lease, const Sha256Digest& build,
|
||||
std::uint64_t bytes, const Sha256Digest& digest) {
|
||||
upgrade_manifest(const CheckpointManifest& previous, const Sha256Digest& previous_digest,
|
||||
Uuid commit, const LeaseGrant& lease, const Sha256Digest& build,
|
||||
std::uint64_t bytes, const Sha256Digest& digest, const CellularVersionBundle& from,
|
||||
const CellularVersionBundle& to) {
|
||||
if (!supported(previous))
|
||||
return std::unexpected(CheckpointError::unsupported);
|
||||
if (!encode_manifest(previous) || previous.sequence == 0 ||
|
||||
previous.sequence == ~std::uint64_t{0} || previous.end_tick == 0 ||
|
||||
previous.cellular_versions != cellular_v9_versions ||
|
||||
previous.cellular_versions != from ||
|
||||
(previous.profile != CheckpointProfile::cellular_lives_v1 &&
|
||||
previous.profile != CheckpointProfile::cellular_population_v1) ||
|
||||
previous_digest == Sha256Digest{} || commit == Uuid{} || commit == previous.commit ||
|
||||
lease.frame != previous.frame || lease.epoch == 0 || lease.holder == Uuid{})
|
||||
return std::unexpected(CheckpointError::chain);
|
||||
auto next = previous;
|
||||
next.cellular_versions = cellular_v10_versions;
|
||||
next.cellular_versions = to;
|
||||
next.commit = commit;
|
||||
++next.sequence;
|
||||
next.predecessor_commit = previous.commit;
|
||||
@@ -114,9 +115,10 @@ cellular_boundary_upgrade_manifest(const CheckpointManifest& previous,
|
||||
}
|
||||
|
||||
std::expected<std::vector<std::uint8_t>, CheckpointError>
|
||||
cellular_boundary_upgrade_payload(std::span<const std::uint8_t> payload,
|
||||
const CheckpointManifest& previous) {
|
||||
if (!supported(previous) || previous.cellular_versions != cellular_v9_versions)
|
||||
upgrade_payload(std::span<const std::uint8_t> payload, const CheckpointManifest& previous,
|
||||
bool maturation) {
|
||||
if (!supported(previous) ||
|
||||
previous.cellular_versions != (maturation ? cellular_v10_versions : cellular_v9_versions))
|
||||
return std::unexpected(CheckpointError::unsupported);
|
||||
if (!encode_manifest(previous) || previous.sequence == 0 || previous.end_tick == 0)
|
||||
return std::unexpected(CheckpointError::chain);
|
||||
@@ -124,7 +126,8 @@ cellular_boundary_upgrade_payload(std::span<const std::uint8_t> payload,
|
||||
auto state = restore_cellular_payload(payload, previous);
|
||||
if (!state)
|
||||
return std::unexpected(state.error());
|
||||
auto upgraded = (*state)->migration_upgrade_candidate();
|
||||
auto upgraded = maturation ? (*state)->maturation_upgrade_candidate()
|
||||
: (*state)->migration_upgrade_candidate();
|
||||
if (!upgraded)
|
||||
return std::unexpected(CheckpointError::payload);
|
||||
return (*upgraded)->snapshot();
|
||||
@@ -133,11 +136,39 @@ cellular_boundary_upgrade_payload(std::span<const std::uint8_t> payload,
|
||||
auto state = restore_population_payload(payload, previous);
|
||||
if (!state)
|
||||
return std::unexpected(state.error());
|
||||
auto upgraded = (*state)->migration_upgrade_candidate();
|
||||
auto upgraded = maturation ? (*state)->maturation_upgrade_candidate()
|
||||
: (*state)->migration_upgrade_candidate();
|
||||
if (!upgraded)
|
||||
return std::unexpected(CheckpointError::payload);
|
||||
return (*upgraded)->snapshot();
|
||||
}
|
||||
return std::unexpected(CheckpointError::unsupported);
|
||||
}
|
||||
} // namespace
|
||||
std::expected<CheckpointManifest, CheckpointError>
|
||||
cellular_boundary_upgrade_manifest(const CheckpointManifest& previous,
|
||||
const Sha256Digest& previous_digest, Uuid commit,
|
||||
const LeaseGrant& lease, const Sha256Digest& build,
|
||||
std::uint64_t bytes, const Sha256Digest& digest) {
|
||||
return upgrade_manifest(previous, previous_digest, commit, lease, build, bytes, digest,
|
||||
cellular_v9_versions, cellular_v10_versions);
|
||||
}
|
||||
std::expected<CheckpointManifest, CheckpointError>
|
||||
cellular_maturation_upgrade_manifest(const CheckpointManifest& previous,
|
||||
const Sha256Digest& previous_digest, Uuid commit,
|
||||
const LeaseGrant& lease, const Sha256Digest& build,
|
||||
std::uint64_t bytes, const Sha256Digest& digest) {
|
||||
return upgrade_manifest(previous, previous_digest, commit, lease, build, bytes, digest,
|
||||
cellular_v10_versions, cellular_v11_versions);
|
||||
}
|
||||
std::expected<std::vector<std::uint8_t>, CheckpointError>
|
||||
cellular_boundary_upgrade_payload(std::span<const std::uint8_t> payload,
|
||||
const CheckpointManifest& previous) {
|
||||
return upgrade_payload(payload, previous, false);
|
||||
}
|
||||
std::expected<std::vector<std::uint8_t>, CheckpointError>
|
||||
cellular_maturation_upgrade_payload(std::span<const std::uint8_t> payload,
|
||||
const CheckpointManifest& previous) {
|
||||
return upgrade_payload(payload, previous, true);
|
||||
}
|
||||
} // namespace evo::persistence
|
||||
|
||||
@@ -66,7 +66,8 @@ bool structural(const CheckpointManifest& m) noexcept {
|
||||
(m.cellular_versions == cellular_v2_versions ||
|
||||
m.cellular_versions == cellular_v3_versions ||
|
||||
m.cellular_versions == cellular_v9_versions ||
|
||||
m.cellular_versions == cellular_v10_versions) &&
|
||||
m.cellular_versions == cellular_v10_versions ||
|
||||
m.cellular_versions == cellular_v11_versions) &&
|
||||
m.begin_tick == m.end_tick && m.end_tick > 0 &&
|
||||
b == BatchDigests{};
|
||||
const bool population_conversion = population && m.begin_tick == m.end_tick && m.end_tick > 0 &&
|
||||
@@ -85,7 +86,8 @@ bool structural(const CheckpointManifest& m) noexcept {
|
||||
m.cellular_versions != cellular_v7_versions &&
|
||||
m.cellular_versions != cellular_v8_versions &&
|
||||
m.cellular_versions != cellular_v9_versions &&
|
||||
m.cellular_versions != cellular_v10_versions) ||
|
||||
m.cellular_versions != cellular_v10_versions &&
|
||||
m.cellular_versions != cellular_v11_versions) ||
|
||||
(cellular && m.versions != environmental_v1_versions))
|
||||
return false;
|
||||
if (primitive && (m.manifest_version != 2 || m.tick_microseconds != 50000 ||
|
||||
@@ -99,7 +101,8 @@ bool structural(const CheckpointManifest& m) noexcept {
|
||||
if (m.sequence == 0) {
|
||||
// Boundary accounting is admitted only by an explicit retained-source
|
||||
// upgrade. Provisioning cannot skip its original opening-stock history.
|
||||
if (cellular && m.cellular_versions == cellular_v10_versions)
|
||||
if (cellular && (m.cellular_versions == cellular_v10_versions ||
|
||||
m.cellular_versions == cellular_v11_versions))
|
||||
return false;
|
||||
const bool genesis = zero(m.holder) && m.epoch == 0 && m.begin_tick == m.end_tick &&
|
||||
b.trace_bytes == 0 && zero(b.trace_sha256);
|
||||
@@ -196,7 +199,8 @@ bool supported(const CheckpointManifest& m) noexcept {
|
||||
m.cellular_versions == cellular_v7_versions ||
|
||||
m.cellular_versions == cellular_v8_versions ||
|
||||
m.cellular_versions == cellular_v9_versions ||
|
||||
m.cellular_versions == cellular_v10_versions) &&
|
||||
m.cellular_versions == cellular_v10_versions ||
|
||||
m.cellular_versions == cellular_v11_versions) &&
|
||||
m.versions == environmental_v1_versions && m.tick_microseconds == 50000 &&
|
||||
m.rng_streams == 0 && m.durability == DurabilityPolicy::single_volume_development;
|
||||
}
|
||||
|
||||
@@ -1173,7 +1173,8 @@ std::expected<void, CellularPublishFailure> CellularRegionHost::set_population_m
|
||||
return {};
|
||||
if (enabled &&
|
||||
(!config_.population_policy || !queued_mutations_.empty() || !pending_endings_.empty() ||
|
||||
state_->rules_version() != cellular_lives_foraging_rules))
|
||||
(state_->rules_version() != cellular_lives_foraging_rules &&
|
||||
state_->rules_version() != cellular_lives_maturation_rules)))
|
||||
return std::unexpected(CellularPublishFailure{CellularHostError::not_ready, {}, {}, {}});
|
||||
if (enabled && !population_interval_safe(*state_))
|
||||
return std::unexpected(CellularPublishFailure{CellularHostError::not_ready, {}, {}, {}});
|
||||
|
||||
Reference in New Issue
Block a user