feat(ecology): make photosynthesis regions playable on DEV
Foundation / checks (ecs) (push) Successful in 2m19s
Foundation / checks (deploy) (push) Successful in 4m47s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 16m48s
Foundation / checks (network) (push) Canceled after 16m46s
Foundation / checks (postgres) (push) Canceled after 16m47s
Foundation / checks (client) (push) Canceled after 16m53s
Foundation / checks (tsan) (push) Canceled after 14m33s
Foundation / checks (ecs) (push) Successful in 2m19s
Foundation / checks (deploy) (push) Successful in 4m47s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 16m48s
Foundation / checks (network) (push) Canceled after 16m46s
Foundation / checks (postgres) (push) Canceled after 16m47s
Foundation / checks (client) (push) Canceled after 16m53s
Foundation / checks (tsan) (push) Canceled after 14m33s
ADR-0176 and schema 57 admit raw cellular bundle 13 (rules 11 on owner format 9) through parser-local normalization to bundle 12, and a fenced no-tick 12 -> 13 upgrade that declares the region's light; recovery reads the light from the target and re-derives the whole target from the source. The resumable cellular-v8 opening provisions a cellular-v7 genesis, one empty tick and the durable upgrades to bundle 13. Session v12 adds the owner's captured light and the producers it can see to its perception, and lets offers name photosynthesis; older sessions keep their layouts and never receive photosynthesis candidates. The client draws chloroplasts by efficiency, shows sunlight in the HUD and offers photosynthesis cards. DEV now provisions and serves region 9 with the trial light; region 8 stays stored but unserved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,11 @@ constexpr std::size_t cellular_perception_v9_prefix_bytes =
|
||||
constexpr std::size_t cellular_bud_cost_bytes = std::size_t{5} * 8;
|
||||
constexpr std::size_t cellular_perception_v10_prefix_bytes =
|
||||
cellular_perception_v9_prefix_bytes + cellular_bud_cost_bytes;
|
||||
// v12 (ADR-0176) appends the captured light, the producer count and 6 reserved bytes.
|
||||
constexpr std::size_t cellular_perception_v12_prefix_bytes =
|
||||
cellular_perception_v10_prefix_bytes + 8 + 2 + 6;
|
||||
// v12: organism, photosynthesis per thousand and 6 reserved bytes.
|
||||
constexpr std::size_t cellular_perceived_producer_bytes = 8 + 2 + 6;
|
||||
constexpr std::size_t cellular_perceived_patch_bytes = 8 + 8 + (4 * 8);
|
||||
// v11: id, centre, radius, shape, drained flag and five 16-bit amount codes.
|
||||
constexpr std::size_t cellular_perceived_deposit_bytes = 4 + 4 + 4 + 2 + 1 + 1 + (5 * 2);
|
||||
@@ -48,15 +53,17 @@ constexpr std::size_t life_receipt_bytes = 17;
|
||||
constexpr std::size_t life_outcome_bytes = 25;
|
||||
constexpr std::size_t life_query_bytes = 8;
|
||||
|
||||
// Seven capabilities and four effects (biology genome/mutation enums, frozen on the wire).
|
||||
bool valid_offer(const CellularMutationOffer& offer) {
|
||||
// Seven capabilities (eight from v12) and four effects (biology genome/mutation enums,
|
||||
// frozen on the wire per version).
|
||||
bool valid_offer(const CellularMutationOffer& offer, std::uint16_t version) {
|
||||
if (offer.tick == 0 || offer.candidates.size() > max_cellular_offered_candidates)
|
||||
return false;
|
||||
if (offer.candidates.empty())
|
||||
return offer.event_index == 0 && offer.offer_tick == 0;
|
||||
std::uint16_t previous = 0;
|
||||
for (const auto& candidate : offer.candidates) {
|
||||
if (candidate.operator_id <= previous || candidate.capability > 6 || candidate.effect > 3)
|
||||
if (candidate.operator_id <= previous ||
|
||||
candidate.capability > cellular_offer_capability_limit(version) || candidate.effect > 3)
|
||||
return false;
|
||||
previous = candidate.operator_id;
|
||||
}
|
||||
@@ -195,7 +202,7 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
if (!cellular_v10_family(version) && std::holds_alternative<CellularMutationAction>(message))
|
||||
return {};
|
||||
if (const auto* offer = std::get_if<CellularMutationOffer>(&message);
|
||||
offer && (!cellular_v10_family(version) || !valid_offer(*offer)))
|
||||
offer && (!cellular_v10_family(version) || !valid_offer(*offer, version)))
|
||||
return {};
|
||||
if (const auto* ended = std::get_if<CellularLifeEnded>(&message);
|
||||
ended && (!cellular_v10_family(version) || ended->tick == 0 || ended->life_identity == 0 ||
|
||||
@@ -220,9 +227,24 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
!cellular_v10_family(version) && std::holds_alternative<CellularPerception>(message))
|
||||
return {};
|
||||
if (const auto* perception = std::get_if<CellularPerception>(&message)) {
|
||||
// v12 alone carries captured light and producers (ADR-0176).
|
||||
const bool producers = version == session_protocol_v12;
|
||||
if ((!producers && (!perception->producers.empty() ||
|
||||
(perception->diagnostics && perception->diagnostics->light_pj))) ||
|
||||
perception->producers.size() > max_cellular_perceived_producers ||
|
||||
(!perception->life_identity && !perception->producers.empty()) ||
|
||||
std::ranges::adjacent_find(perception->producers,
|
||||
[](const auto& a, const auto& b) {
|
||||
return a.organism >= b.organism;
|
||||
}) != perception->producers.end() ||
|
||||
std::ranges::any_of(perception->producers, [](const auto& p) {
|
||||
return p.organism == 0 || p.photosynthesis_per_thousand == 0 ||
|
||||
p.photosynthesis_per_thousand > 1000;
|
||||
}))
|
||||
return {};
|
||||
// v11 (ADR-0136) lists deposits by ascending id, never patches; earlier versions the
|
||||
// reverse.
|
||||
if (version == session_protocol_v11
|
||||
if (cellular_deposit_version(version)
|
||||
? !perception->patches.empty() ||
|
||||
perception->deposits.size() > max_cellular_perceived_deposits ||
|
||||
(!perception->life_identity && !perception->deposits.empty()) ||
|
||||
@@ -364,15 +386,17 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
std::vector<std::uint8_t> operator()(const CellularPerception& m) const {
|
||||
auto out =
|
||||
header(SessionMessageType::cellular_perception,
|
||||
(cellular_v10_family(version) ? cellular_perception_v10_prefix_bytes
|
||||
(version == session_protocol_v12 ? cellular_perception_v12_prefix_bytes
|
||||
: cellular_v10_family(version) ? cellular_perception_v10_prefix_bytes
|
||||
: version == session_protocol_v9 ? cellular_perception_v9_prefix_bytes
|
||||
: cellular_perception_prefix_bytes) +
|
||||
m.patches.size() * cellular_perceived_patch_bytes +
|
||||
m.deposits.size() * cellular_perceived_deposit_bytes,
|
||||
m.deposits.size() * cellular_perceived_deposit_bytes +
|
||||
m.producers.size() * cellular_perceived_producer_bytes,
|
||||
version);
|
||||
put(out, m.tick, 8);
|
||||
put(out, m.life_identity, 8);
|
||||
put(out, version == session_protocol_v11 ? m.deposits.size() : m.patches.size(), 2);
|
||||
put(out, cellular_deposit_version(version) ? m.deposits.size() : m.patches.size(), 2);
|
||||
if (version == session_protocol_v9 || cellular_v10_family(version)) {
|
||||
const auto& d = m.diagnostics;
|
||||
put(out, d ? d->reserve_energy_pj : 0, 8);
|
||||
@@ -393,6 +417,11 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
for (const auto value :
|
||||
d ? d->bud_cost_matter_fg : std::array<std::uint64_t, 4>{})
|
||||
put(out, value, 8);
|
||||
if (version == session_protocol_v12) {
|
||||
put(out, d ? d->light_pj : 0, 8);
|
||||
put(out, m.producers.size(), 2);
|
||||
put(out, 0, 6);
|
||||
}
|
||||
} else {
|
||||
put(out, 0, 5);
|
||||
}
|
||||
@@ -414,6 +443,11 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
for (const auto code : deposit.amount_codes)
|
||||
put(out, code, 2);
|
||||
}
|
||||
for (const auto& producer : m.producers) {
|
||||
put(out, producer.organism, 8);
|
||||
put(out, producer.photosynthesis_per_thousand, 2);
|
||||
put(out, 0, 6);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const IntentionReceipt& m) const {
|
||||
@@ -727,7 +761,7 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
candidate.cost_matter_fg[channel] = get(payload, at + 32 + channel * 8, 8);
|
||||
m.candidates.push_back(candidate);
|
||||
}
|
||||
if (!valid_offer(m))
|
||||
if (!valid_offer(m, wire_version))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
return m;
|
||||
}
|
||||
@@ -744,17 +778,29 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
const bool without_bud_cost = wire_version == session_protocol_v10 &&
|
||||
payload.size() == cellular_perception_v9_prefix_bytes +
|
||||
count * cellular_perceived_patch_bytes;
|
||||
const auto prefix = cellular_v10_family(wire_version) && !without_bud_cost
|
||||
const bool lit = wire_version == session_protocol_v12;
|
||||
const auto prefix = lit ? cellular_perception_v12_prefix_bytes
|
||||
: cellular_v10_family(wire_version) && !without_bud_cost
|
||||
? cellular_perception_v10_prefix_bytes
|
||||
: wire_version == session_protocol_v9 || without_bud_cost
|
||||
? cellular_perception_v9_prefix_bytes
|
||||
: cellular_perception_prefix_bytes;
|
||||
const bool deposits = wire_version == session_protocol_v11;
|
||||
const bool deposits = cellular_deposit_version(wire_version);
|
||||
const auto entry =
|
||||
deposits ? cellular_perceived_deposit_bytes : cellular_perceived_patch_bytes;
|
||||
const auto producer_count = lit && payload.size() >= prefix
|
||||
? static_cast<std::size_t>(get(
|
||||
payload, cellular_perception_v10_prefix_bytes + 8, 2))
|
||||
: 0;
|
||||
if (count > (deposits ? max_cellular_perceived_deposits : max_cellular_perceived_patches) ||
|
||||
payload.size() != prefix + count * entry)
|
||||
producer_count > max_cellular_perceived_producers ||
|
||||
payload.size() !=
|
||||
prefix + count * entry + producer_count * cellular_perceived_producer_bytes)
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
if (lit &&
|
||||
std::ranges::any_of(payload.subspan(cellular_perception_v10_prefix_bytes + 10, 6),
|
||||
[](std::uint8_t value) { return value != 0; }))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
CellularPerception m;
|
||||
m.tick = get(payload, 0, 8);
|
||||
m.life_identity = get(payload, 8, 8);
|
||||
@@ -785,6 +831,8 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
for (std::size_t channel = 0; channel < d.bud_cost_matter_fg.size(); ++channel)
|
||||
d.bud_cost_matter_fg[channel] = get(payload, 90 + channel * 8, 8);
|
||||
}
|
||||
if (lit)
|
||||
d.light_pj = get(payload, cellular_perception_v10_prefix_bytes, 8);
|
||||
}
|
||||
d.movement = static_cast<CellularMovementResult>(payload[74]);
|
||||
d.intake = static_cast<CellularIntakeResult>(payload[75]);
|
||||
@@ -799,6 +847,7 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
d.intake != CellularIntakeResult::not_reported ||
|
||||
d.engulf != CellularEngulfResult::not_reported ||
|
||||
d.bud != CellularBudOutcome::not_reported || d.bud_cost_energy_pj ||
|
||||
d.light_pj ||
|
||||
std::ranges::any_of(d.bud_cost_matter_fg,
|
||||
[](std::uint64_t value) { return value != 0; }))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
@@ -831,6 +880,23 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
static_cast<std::uint16_t>(get(payload, offset + 16 + c * 2, 2));
|
||||
m.deposits.push_back(d);
|
||||
}
|
||||
if (!m.life_identity && producer_count)
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
m.producers.reserve(producer_count);
|
||||
for (std::size_t i = 0; i < producer_count;
|
||||
++i, offset += cellular_perceived_producer_bytes) {
|
||||
CellularPerceivedProducer p;
|
||||
p.organism = get(payload, offset, 8);
|
||||
p.photosynthesis_per_thousand =
|
||||
static_cast<std::uint16_t>(get(payload, offset + 8, 2));
|
||||
if (p.organism == 0 || p.photosynthesis_per_thousand == 0 ||
|
||||
p.photosynthesis_per_thousand > 1000 ||
|
||||
std::ranges::any_of(payload.subspan(offset + 10, 6),
|
||||
[](std::uint8_t value) { return value != 0; }) ||
|
||||
(!m.producers.empty() && m.producers.back().organism >= p.organism))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
m.producers.push_back(p);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
m.patches.reserve(count);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
@@ -96,7 +97,7 @@ bool prepared_mutations_are_canonical(const CellularPreparedCommit& prepared,
|
||||
prepared.mutations, manifest.begin_tick, manifest.end_tick);
|
||||
if (!decoded || decoded->size() != selections || prepared.results.size() != selections ||
|
||||
std::ranges::any_of(prepared.results, [&](std::uint8_t result) {
|
||||
return manifest.cellular_versions == cellular_v12_versions
|
||||
return cellular_plan_bundle(manifest.cellular_versions)
|
||||
? result != 1 && result != 3 && result != 4
|
||||
: result > 3;
|
||||
}))
|
||||
@@ -243,7 +244,7 @@ retry_cellular_profile_migration(Postgres& db, const CellularProfileMigrationPre
|
||||
!((manifest->profile == CheckpointProfile::cellular_lives_v1 &&
|
||||
(manifest->cellular_versions == cellular_v2_versions ||
|
||||
manifest->cellular_versions == cellular_v3_versions ||
|
||||
manifest->cellular_versions == cellular_v12_versions)) ||
|
||||
cellular_plan_bundle(manifest->cellular_versions))) ||
|
||||
((manifest->profile == CheckpointProfile::cellular_lives_v1 ||
|
||||
manifest->profile == CheckpointProfile::cellular_population_v1) &&
|
||||
(manifest->cellular_versions == cellular_v10_versions ||
|
||||
@@ -281,12 +282,13 @@ retry_cellular_profile_migration(Postgres& db, const CellularProfileMigrationPre
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::expected<CommittedCheckpoint, CellularProfileMigrationFailure>
|
||||
migrate_rules_profile(Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease,
|
||||
const CommittedCheckpoint& predecessor, Uuid commit,
|
||||
const Sha256Digest& build, milliseconds timeout, const PublishHooks& hooks,
|
||||
decltype(&cellular_maturation_upgrade_payload) upgrade_payload,
|
||||
decltype(&cellular_maturation_upgrade_manifest) derive) {
|
||||
std::expected<CommittedCheckpoint, CellularProfileMigrationFailure> migrate_rules_profile(
|
||||
Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease,
|
||||
const CommittedCheckpoint& predecessor, Uuid commit, const Sha256Digest& build,
|
||||
milliseconds timeout, const PublishHooks& hooks,
|
||||
const std::function<std::expected<std::vector<std::uint8_t>, CheckpointError>(
|
||||
std::span<const std::uint8_t>, const CheckpointManifest&)>& upgrade_payload,
|
||||
decltype(&cellular_maturation_upgrade_manifest) derive) {
|
||||
const auto previous = decode_manifest(predecessor.manifest);
|
||||
const auto previous_digest = sha256(predecessor.manifest);
|
||||
if (!previous || !previous_digest || predecessor.head.digest != *previous_digest ||
|
||||
@@ -347,6 +349,19 @@ migrate_cellular_inheritance_profile(Postgres& db, const FilesystemObjectStore&
|
||||
cellular_inheritance_upgrade_payload,
|
||||
cellular_inheritance_upgrade_manifest);
|
||||
}
|
||||
std::expected<CommittedCheckpoint, CellularProfileMigrationFailure>
|
||||
migrate_cellular_photosynthesis_profile(Postgres& db, const FilesystemObjectStore& objects,
|
||||
const LeaseGrant& lease,
|
||||
const CommittedCheckpoint& predecessor, Uuid commit,
|
||||
const Sha256Digest& build, server::CellularLight light,
|
||||
milliseconds timeout, const PublishHooks& hooks) {
|
||||
return migrate_rules_profile(
|
||||
db, objects, lease, predecessor, commit, build, timeout, hooks,
|
||||
[light](std::span<const std::uint8_t> payload, const CheckpointManifest& previous) {
|
||||
return cellular_photosynthesis_upgrade_payload(payload, previous, light);
|
||||
},
|
||||
cellular_photosynthesis_upgrade_manifest);
|
||||
}
|
||||
|
||||
std::expected<CommittedCheckpoint, CellularProfileMigrationFailure>
|
||||
migrate_cellular_profile_to_v2(Postgres& db, const FilesystemObjectStore& objects,
|
||||
@@ -634,10 +649,12 @@ verify_cellular_no_tick_checkpoint(Postgres& db, const FilesystemObjectStore& ob
|
||||
const bool boundary = m.cellular_versions == cellular_v10_versions;
|
||||
const bool maturation = m.cellular_versions == cellular_v11_versions;
|
||||
const bool inheritance = m.cellular_versions == cellular_v12_versions;
|
||||
const auto derive = inheritance ? cellular_inheritance_upgrade_manifest
|
||||
: maturation ? cellular_maturation_upgrade_manifest
|
||||
: boundary ? cellular_boundary_upgrade_manifest
|
||||
: cellular_profile_migration_manifest;
|
||||
const bool photosynthesis = m.cellular_versions == cellular_v13_versions;
|
||||
const auto derive = photosynthesis ? cellular_photosynthesis_upgrade_manifest
|
||||
: inheritance ? cellular_inheritance_upgrade_manifest
|
||||
: 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)
|
||||
@@ -645,7 +662,17 @@ verify_cellular_no_tick_checkpoint(Postgres& db, const FilesystemObjectStore& ob
|
||||
auto bytes = objects.get({source->payload_sha256, source->payload_bytes});
|
||||
if (!bytes)
|
||||
return fail(RecoveryError::tail);
|
||||
if (boundary || maturation || inheritance) {
|
||||
if (photosynthesis) {
|
||||
// The declared light is the upgrade's only input: read it from the target, then
|
||||
// require the source to re-derive the exact target bytes with it.
|
||||
auto target = restore_cellular_payload(payload, m);
|
||||
if (!target)
|
||||
return fail(RecoveryError::payload);
|
||||
auto upgraded =
|
||||
cellular_photosynthesis_upgrade_payload(*bytes, *source, (*target)->light());
|
||||
if (!upgraded || !std::ranges::equal(*upgraded, payload))
|
||||
return fail(RecoveryError::history);
|
||||
} else if (boundary || maturation || inheritance) {
|
||||
auto upgraded = inheritance ? cellular_inheritance_upgrade_payload(*bytes, *source)
|
||||
: maturation ? cellular_maturation_upgrade_payload(*bytes, *source)
|
||||
: cellular_boundary_upgrade_payload(*bytes, *source);
|
||||
|
||||
@@ -197,4 +197,31 @@ cellular_inheritance_upgrade_payload(std::span<const std::uint8_t> payload,
|
||||
return std::unexpected(CheckpointError::payload);
|
||||
return (*upgraded)->snapshot();
|
||||
}
|
||||
std::expected<CheckpointManifest, CheckpointError>
|
||||
cellular_photosynthesis_upgrade_manifest(const CheckpointManifest& previous,
|
||||
const Sha256Digest& previous_digest, Uuid commit,
|
||||
const LeaseGrant& lease, const Sha256Digest& build,
|
||||
std::uint64_t bytes, const Sha256Digest& digest) {
|
||||
if (previous.profile != CheckpointProfile::cellular_lives_v1)
|
||||
return std::unexpected(CheckpointError::unsupported);
|
||||
return upgrade_manifest(previous, previous_digest, commit, lease, build, bytes, digest,
|
||||
cellular_v12_versions, cellular_v13_versions);
|
||||
}
|
||||
std::expected<std::vector<std::uint8_t>, CheckpointError>
|
||||
cellular_photosynthesis_upgrade_payload(std::span<const std::uint8_t> payload,
|
||||
const CheckpointManifest& previous,
|
||||
const server::CellularLight& light) {
|
||||
if (!supported(previous) || previous.profile != CheckpointProfile::cellular_lives_v1 ||
|
||||
previous.cellular_versions != cellular_v12_versions)
|
||||
return std::unexpected(CheckpointError::unsupported);
|
||||
if (!encode_manifest(previous) || previous.sequence == 0 || previous.end_tick == 0)
|
||||
return std::unexpected(CheckpointError::chain);
|
||||
auto state = restore_cellular_payload(payload, previous);
|
||||
if (!state)
|
||||
return std::unexpected(state.error());
|
||||
auto upgraded = (*state)->photosynthesis_upgrade_candidate(light);
|
||||
if (!upgraded)
|
||||
return std::unexpected(CheckpointError::payload);
|
||||
return (*upgraded)->snapshot();
|
||||
}
|
||||
} // namespace evo::persistence
|
||||
|
||||
@@ -69,7 +69,7 @@ bool structural(const CheckpointManifest& m) noexcept {
|
||||
m.cellular_versions == cellular_v9_versions ||
|
||||
m.cellular_versions == cellular_v10_versions ||
|
||||
m.cellular_versions == cellular_v11_versions ||
|
||||
m.cellular_versions == cellular_v12_versions) &&
|
||||
cellular_plan_bundle(m.cellular_versions)) &&
|
||||
m.begin_tick == m.end_tick && m.end_tick > 0 &&
|
||||
b == BatchDigests{};
|
||||
const auto joint_min =
|
||||
@@ -99,7 +99,7 @@ bool structural(const CheckpointManifest& m) noexcept {
|
||||
m.cellular_versions != cellular_v9_versions &&
|
||||
m.cellular_versions != cellular_v10_versions &&
|
||||
m.cellular_versions != cellular_v11_versions &&
|
||||
m.cellular_versions != cellular_v12_versions) ||
|
||||
!cellular_plan_bundle(m.cellular_versions)) ||
|
||||
(cellular && m.versions != environmental_v1_versions))
|
||||
return false;
|
||||
if (primitive && (m.manifest_version != 2 || m.tick_microseconds != 50000 ||
|
||||
@@ -115,7 +115,7 @@ bool structural(const CheckpointManifest& m) noexcept {
|
||||
// upgrade. Provisioning cannot skip its original opening-stock history.
|
||||
if (cellular && (m.cellular_versions == cellular_v10_versions ||
|
||||
m.cellular_versions == cellular_v11_versions ||
|
||||
m.cellular_versions == cellular_v12_versions))
|
||||
cellular_plan_bundle(m.cellular_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);
|
||||
@@ -206,7 +206,7 @@ bool supported(const CheckpointManifest& m) noexcept {
|
||||
m.rng_streams == 0 && m.durability == DurabilityPolicy::single_volume_development;
|
||||
if (m.profile == CheckpointProfile::cellular_lives_v1) {
|
||||
const bool revision = cellular_revision_bundle(m.cellular_versions) ||
|
||||
m.cellular_versions == cellular_v12_versions;
|
||||
cellular_plan_bundle(m.cellular_versions);
|
||||
const bool history_matches =
|
||||
(!revision && m.history_profile == cellular_history_profile) ||
|
||||
(revision && m.history_profile == cellular_revision_history_profile);
|
||||
@@ -222,7 +222,7 @@ bool supported(const CheckpointManifest& m) noexcept {
|
||||
m.cellular_versions == cellular_v9_versions ||
|
||||
m.cellular_versions == cellular_v10_versions ||
|
||||
m.cellular_versions == cellular_v11_versions ||
|
||||
m.cellular_versions == cellular_v12_versions) &&
|
||||
cellular_plan_bundle(m.cellular_versions)) &&
|
||||
m.versions == environmental_v1_versions && m.tick_microseconds == 50000 &&
|
||||
m.rng_streams == 0 && m.durability == DurabilityPolicy::single_volume_development;
|
||||
}
|
||||
|
||||
@@ -2202,6 +2202,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
next->captured = state_->captured;
|
||||
// ADR-0175: light, from this tick's own intentions, credited to every active,
|
||||
// unfrozen photosynthetic survivor's reserve and to the boundary inflow together.
|
||||
std::vector<std::pair<std::uint64_t, std::uint64_t>> lit_lives;
|
||||
if (next->light.numerator != 0) {
|
||||
for (auto& life : next->lives) {
|
||||
const auto left = next->light.entitlement.value - next->captured.value;
|
||||
@@ -2240,6 +2241,8 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
next->boundary.incoming.energy.value += granted;
|
||||
next->current_total.energy.value += granted;
|
||||
next->captured.value += granted;
|
||||
if (granted != 0)
|
||||
lit_lives.emplace_back(life.identity.life, granted);
|
||||
}
|
||||
}
|
||||
std::vector<CellularLifeTickFeedback> feedback;
|
||||
@@ -2289,6 +2292,11 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
entry->resume_blocked =
|
||||
std::ranges::find(resume_blocked, life.identity.life) != resume_blocked.end();
|
||||
}
|
||||
for (const auto& [life, energy] : lit_lives) {
|
||||
const auto entry = std::ranges::find(feedback, life, &CellularLifeTickFeedback::life_id);
|
||||
if (entry != feedback.end())
|
||||
entry->light = {energy};
|
||||
}
|
||||
std::ranges::sort(feedback, {}, &CellularLifeTickFeedback::life_id);
|
||||
state_.swap(next);
|
||||
last_tick_feedback_ = std::move(feedback);
|
||||
|
||||
@@ -157,7 +157,15 @@ struct RegionSessions::Impl {
|
||||
if (c.state != State::established ||
|
||||
!network::cellular_v10_family(c.protocol_version) || c.account_id != account)
|
||||
continue;
|
||||
const auto bytes = network::encode_session(message, c.protocol_version);
|
||||
auto delivered = message;
|
||||
// ADR-0176: before v12 an offer cannot name photosynthesis; its other choices
|
||||
// stay valid, so those candidates alone are withheld.
|
||||
if (auto* offer = std::get_if<network::CellularMutationOffer>(&delivered))
|
||||
std::erase_if(offer->candidates, [&](const auto& candidate) {
|
||||
return candidate.capability >
|
||||
network::cellular_offer_capability_limit(c.protocol_version);
|
||||
});
|
||||
const auto bytes = network::encode_session(delivered, c.protocol_version);
|
||||
return !bytes.empty() && endpoint->send_message(c.id, bytes).has_value();
|
||||
}
|
||||
return false;
|
||||
@@ -620,7 +628,7 @@ struct RegionSessions::Impl {
|
||||
wire_version == network::session_protocol_v9 ||
|
||||
network::cellular_v10_family(wire_version)) &&
|
||||
!cellular_actions) ||
|
||||
wire_version > network::session_protocol_v11)
|
||||
wire_version > network::session_protocol_v12)
|
||||
return close(c, SessionCloseReason::unsupported_version, now);
|
||||
} else if (wire_version != c.protocol_version) {
|
||||
return close(c, SessionCloseReason::unsupported_version, now);
|
||||
@@ -941,11 +949,17 @@ bool RegionSessions::send_cellular_perception(const network::AccountId& account,
|
||||
continue;
|
||||
c.perceived_tick = perception.tick;
|
||||
auto delivered = perception;
|
||||
// v11 sees deposits (ADR-0136), earlier versions square patches; never both.
|
||||
if (c.protocol_version == network::session_protocol_v11)
|
||||
// v11+ see deposits (ADR-0136), earlier versions square patches; never both.
|
||||
if (network::cellular_deposit_version(c.protocol_version))
|
||||
delivered.patches.clear();
|
||||
else
|
||||
delivered.deposits.clear();
|
||||
// Only v12 carries captured light and visible producers (ADR-0176).
|
||||
if (c.protocol_version != network::session_protocol_v12) {
|
||||
delivered.producers.clear();
|
||||
if (delivered.diagnostics)
|
||||
delivered.diagnostics->light_pj = 0;
|
||||
}
|
||||
if (c.protocol_version == network::session_protocol_v8)
|
||||
delivered.diagnostics.reset();
|
||||
if (c.protocol_version == network::session_protocol_v9 && delivered.diagnostics) {
|
||||
|
||||
Reference in New Issue
Block a user