Show what a bud costs (ADR-0129 amendment)
Foundation / checks (ecs) (push) Successful in 2m20s
Foundation / checks (deploy) (push) Successful in 4m4s
Foundation / checks (tsan) (push) Successful in 9m59s
Foundation / checks (client) (push) Successful in 19m19s
Foundation / checks (network) (push) Successful in 19m24s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 32m13s
Foundation / checks (checks) (push) Canceled after 32m19s
Foundation / checks (ecs) (push) Successful in 2m20s
Foundation / checks (deploy) (push) Successful in 4m4s
Foundation / checks (tsan) (push) Successful in 9m59s
Foundation / checks (client) (push) Successful in 19m19s
Foundation / checks (network) (push) Successful in 19m24s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 32m13s
Foundation / checks (checks) (push) Canceled after 32m19s
The v10 cellular perception carries the bud cost after the diagnostics block: the energy (construction plus the bud's provision) and matter per channel one bud takes from a fully grown cell's reserve. biology::bud_cost reads it from fund_bud itself, so the shown cost is exactly the charge; the server caches it per genome. The client shows it and names the channels the reserve is short on. v10 clients must be rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "evo/client/organism_view.hpp"
|
#include "evo/client/organism_view.hpp"
|
||||||
#include "evo/network/session_protocol.hpp"
|
#include "evo/network/session_protocol.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -71,6 +72,16 @@ steer_cellular(const CellularControls& controls, client::Intention intention,
|
|||||||
result.intention.move_y = component(intention.move_y);
|
result.intention.move_y = component(intention.move_y);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
// ADR-0129 amendment: what one bud needs that the reserve lacks, per channel: energy
|
||||||
|
// first, then C, N, P and other matter. Nothing set when it can be paid; a genome that
|
||||||
|
// cannot bud reports a zero cost, which this treats as affordable (the button is the guide).
|
||||||
|
[[nodiscard]] inline std::array<bool, 5> bud_shortfall(const network::CellularLifeDiagnostics& d) {
|
||||||
|
std::array<bool, 5> short_on{};
|
||||||
|
short_on[0] = d.bud_cost_energy_pj > d.reserve_energy_pj;
|
||||||
|
for (std::size_t i = 0; i < d.bud_cost_matter_fg.size(); ++i)
|
||||||
|
short_on[i + 1] = d.bud_cost_matter_fg[i] > d.reserve_matter_fg[i];
|
||||||
|
return short_on;
|
||||||
|
}
|
||||||
[[nodiscard]] inline bool can_fund(const network::CellularOfferedCandidate& candidate,
|
[[nodiscard]] inline bool can_fund(const network::CellularOfferedCandidate& candidate,
|
||||||
const network::CellularLifeDiagnostics& reserve) {
|
const network::CellularLifeDiagnostics& reserve) {
|
||||||
if (candidate.cost_energy_pj > reserve.reserve_energy_pj)
|
if (candidate.cost_energy_pj > reserve.reserve_energy_pj)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "panels.hpp"
|
#include "panels.hpp"
|
||||||
#include "evo/client/labels.hpp"
|
#include "evo/client/labels.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
@@ -738,6 +739,32 @@ void cell_actions(const PanelView& v, PanelActions& a) {
|
|||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
disabled_wrapped("Engulf attempts nearby prey. Bud funds an independent descendant; you keep "
|
disabled_wrapped("Engulf attempts nearby prey. Bud funds an independent descendant; you keep "
|
||||||
"your cell. Automatic feeding resumes after the action tick.");
|
"your cell. Automatic feeding resumes after the action tick.");
|
||||||
|
// ADR-0129 amendment: what a bud takes from the reserve once the cell is fully grown.
|
||||||
|
if (const auto* perception = v.cellular_perception; perception && perception->diagnostics) {
|
||||||
|
const auto& d = *perception->diagnostics;
|
||||||
|
const bool can_bud = d.bud_cost_energy_pj != 0 ||
|
||||||
|
std::ranges::any_of(d.bud_cost_matter_fg,
|
||||||
|
[](std::uint64_t value) { return value != 0; });
|
||||||
|
if (!can_bud) {
|
||||||
|
disabled_wrapped("This cell's genome cannot bud.");
|
||||||
|
} else {
|
||||||
|
ImGui::TextWrapped("Bud needs: %llu pJ\nC %llu / N %llu / P %llu / other %llu fg",
|
||||||
|
static_cast<unsigned long long>(d.bud_cost_energy_pj),
|
||||||
|
static_cast<unsigned long long>(d.bud_cost_matter_fg[0]),
|
||||||
|
static_cast<unsigned long long>(d.bud_cost_matter_fg[1]),
|
||||||
|
static_cast<unsigned long long>(d.bud_cost_matter_fg[2]),
|
||||||
|
static_cast<unsigned long long>(d.bud_cost_matter_fg[3]));
|
||||||
|
constexpr std::array names{"energy", "carbon", "nitrogen", "phosphorus", "other"};
|
||||||
|
std::string missing;
|
||||||
|
const auto short_on = bud_shortfall(d);
|
||||||
|
for (std::size_t i = 0; i < short_on.size(); ++i)
|
||||||
|
if (short_on[i])
|
||||||
|
missing += std::string{missing.empty() ? "" : ", "} + names.at(i);
|
||||||
|
if (!missing.empty())
|
||||||
|
ImGui::TextColored(amber, "Short on %s", missing.c_str());
|
||||||
|
disabled_wrapped("A bud also needs the cell fully grown and undamaged.");
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!play)
|
if (!play)
|
||||||
return;
|
return;
|
||||||
if (const auto& pending = play->pending(); pending) {
|
if (const auto& pending = play->pending(); pending) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "evo/biology/budding.hpp"
|
||||||
#include "evo/client/organism_view.hpp"
|
#include "evo/client/organism_view.hpp"
|
||||||
#include "evo/network/session_grant.hpp"
|
#include "evo/network/session_grant.hpp"
|
||||||
#include "evo/server/cellular_region_host.hpp"
|
#include "evo/server/cellular_region_host.hpp"
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -209,6 +211,11 @@ class CellularBridge {
|
|||||||
diagnostics.reserve_energy_pj = life.reserve.energy.value;
|
diagnostics.reserve_energy_pj = life.reserve.energy.value;
|
||||||
for (std::size_t i = 0; i < diagnostics.reserve_matter_fg.size(); ++i)
|
for (std::size_t i = 0; i < diagnostics.reserve_matter_fg.size(); ++i)
|
||||||
diagnostics.reserve_matter_fg[i] = life.reserve.matter[i].value;
|
diagnostics.reserve_matter_fg[i] = life.reserve.matter[i].value;
|
||||||
|
if (const auto cost = bud_cost_for(state, life.identity.genome)) {
|
||||||
|
diagnostics.bud_cost_energy_pj = cost->energy.value;
|
||||||
|
for (std::size_t i = 0; i < diagnostics.bud_cost_matter_fg.size(); ++i)
|
||||||
|
diagnostics.bud_cost_matter_fg[i] = cost->matter[i].value;
|
||||||
|
}
|
||||||
const auto feedback =
|
const auto feedback =
|
||||||
std::ranges::lower_bound(state.last_tick_feedback(), life.identity.life, {},
|
std::ranges::lower_bound(state.last_tick_feedback(), life.identity.life, {},
|
||||||
&server::CellularLifeTickFeedback::life_id);
|
&server::CellularLifeTickFeedback::life_id);
|
||||||
@@ -356,6 +363,20 @@ class CellularBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// ADR-0129 amendment: a genome's bud cost is pure for this region's temperature, and
|
||||||
|
// deriving it scans up to a thousand bodies, so it is computed once per genome.
|
||||||
|
std::optional<accounting::Inventory> bud_cost_for(const server::CellularLives& state,
|
||||||
|
std::uint64_t genome_id) {
|
||||||
|
if (const auto known = bud_costs_.find(genome_id); known != bud_costs_.end())
|
||||||
|
return known->second;
|
||||||
|
const auto genome = state.archive().find(genome_id);
|
||||||
|
if (!genome)
|
||||||
|
return std::nullopt;
|
||||||
|
if (bud_costs_.size() >= 4096)
|
||||||
|
bud_costs_.clear(); // Bounded: recomputing is only slower.
|
||||||
|
return bud_costs_[genome_id] =
|
||||||
|
biology::bud_cost(*genome, state.ambient_temperature_millikelvin());
|
||||||
|
}
|
||||||
static std::uint64_t wall_seconds() {
|
static std::uint64_t wall_seconds() {
|
||||||
return static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::seconds>(
|
return static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::seconds>(
|
||||||
std::chrono::system_clock::now().time_since_epoch())
|
std::chrono::system_clock::now().time_since_epoch())
|
||||||
@@ -382,6 +403,7 @@ class CellularBridge {
|
|||||||
friend bool operator==(const SentOffer&, const SentOffer&) = default;
|
friend bool operator==(const SentOffer&, const SentOffer&) = default;
|
||||||
};
|
};
|
||||||
std::vector<SentOffer> offers_; // Last offer view sent to each owner.
|
std::vector<SentOffer> offers_; // Last offer view sent to each owner.
|
||||||
|
std::map<std::uint64_t, std::optional<accounting::Inventory>> bud_costs_; // By genome.
|
||||||
std::vector<std::pair<server::LifeAccount, std::uint64_t>> owned_; // At last replication.
|
std::vector<std::pair<server::LifeAccount, std::uint64_t>> owned_; // At last replication.
|
||||||
bool shutdown_{};
|
bool shutdown_{};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ spec:
|
|||||||
env:
|
env:
|
||||||
- {name: REGION_SESSION, value: "dev"}
|
- {name: REGION_SESSION, value: "dev"}
|
||||||
- {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"}
|
- {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"}
|
||||||
- {name: REGION_SESSION_WINDOW, value: "dev-20261015T213553-53423:1792110953"}
|
- {name: REGION_SESSION_WINDOW, value: "dev-20261015T231128-88134:1792116688"}
|
||||||
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
|
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
|
||||||
ports:
|
ports:
|
||||||
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
|
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
|
||||||
|
|||||||
@@ -45,3 +45,15 @@ inferring it from a vanished view. v1-v9 are unchanged.
|
|||||||
touching cell too large even with the thinnest membrane, 7 a touching cell small
|
touching cell too large even with the thinnest membrane, 7 a touching cell small
|
||||||
enough but defended by its membrane. Value 3 (no eligible prey) is no longer sent.
|
enough but defended by its membrane. Value 3 (no eligible prey) is no longer sent.
|
||||||
Who is engulfed is unchanged.
|
Who is engulfed is unchanged.
|
||||||
|
|
||||||
|
## Amendment (2026-10-15, bud cost)
|
||||||
|
|
||||||
|
A playtester could not tell why a bud failed or what it needed. The v10 cellular
|
||||||
|
perception now carries the bud cost after the diagnostics block: the energy
|
||||||
|
(construction plus the bud's 30 s provision) and matter per channel that one bud
|
||||||
|
takes from the reserve once the cell is fully grown and undamaged. It is computed by
|
||||||
|
the same `fund_bud` the owner uses, against an ample reserve (`biology::bud_cost`),
|
||||||
|
so a reserve covering the shown cost on every channel is exactly a reserve that can
|
||||||
|
bud. The server caches it per genome. It does not depend on tick effects; all zero
|
||||||
|
means the genome cannot bud. The client shows the cost and names the channels it is
|
||||||
|
short on. The v10 perception grows by 40 bytes, so v10 clients must be rebuilt.
|
||||||
|
|||||||
@@ -7675,3 +7675,18 @@ Tests: `client-auth` covers profile validation, the credential names, the refusa
|
|||||||
of an invalid profile, and `prompt=login` in the authorization URL. Executed
|
of an invalid profile, and `prompt=login` in the authorization URL. Executed
|
||||||
locally: WSL clang-19 `client-probe` with clang-tidy 14/14 plus the Xvfb X11
|
locally: WSL clang-19 `client-probe` with clang-tidy 14/14 plus the Xvfb X11
|
||||||
lifecycle check; MSVC `client-package` 18/18; clang-format 19.
|
lifecycle check; MSVC `client-package` 18/18; clang-format 19.
|
||||||
|
|
||||||
|
## 2026-10-15 — bud cost in v10 diagnostics (CI pending)
|
||||||
|
|
||||||
|
ADR-0129 amendment: the v10 cellular perception carries what one bud takes from a
|
||||||
|
fully grown cell's reserve (energy and matter per channel), from
|
||||||
|
`biology::bud_cost`, which reads `fund_bud`'s own charge. The client shows it and
|
||||||
|
names the channels the reserve is short on.
|
||||||
|
|
||||||
|
Tests: `budding_tests` checks that a reserve equal to the shown cost buds and one
|
||||||
|
unit short on any channel refuses, and that a non-reproducing genome has no cost.
|
||||||
|
`cellular_intent_protocol_tests` checks the 40-byte v10 extension: offsets, round
|
||||||
|
trip with and without tick effects, v9 refusal, and refusal of a cleared view with
|
||||||
|
a cost. Executed locally: those unit tests, the WSL PostgreSQL suite, clang-tidy-19
|
||||||
|
on the changed sources, WSL client 14/14 with clang-tidy plus the Xvfb check, MSVC
|
||||||
|
`client-package` 18/18, and clang-format 19.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <expected>
|
#include <expected>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
// M11.5 budding (ADR-0098 decision 1, ADR-0125): a funded proposal, detached from any
|
// M11.5 budding (ADR-0098 decision 1, ADR-0125): a funded proposal, detached from any
|
||||||
// owner. The parent pays its ADR-0032 reproduction investment and a starting provision
|
// owner. The parent pays its ADR-0032 reproduction investment and a starting provision
|
||||||
@@ -33,4 +34,10 @@ enum class BuddingError : std::uint8_t {
|
|||||||
[[nodiscard]] std::expected<BudTransition, BuddingError>
|
[[nodiscard]] std::expected<BudTransition, BuddingError>
|
||||||
fund_bud(const Genome& genome, GrowthState parent_growth,
|
fund_bud(const Genome& genome, GrowthState parent_growth,
|
||||||
const accounting::Inventory& parent_reserve, std::uint32_t temperature_millikelvin);
|
const accounting::Inventory& parent_reserve, std::uint32_t temperature_millikelvin);
|
||||||
|
// What one bud takes from a fully grown, undamaged parent of this genome at this temperature
|
||||||
|
// (ADR-0129 amendment): investment matter per channel, and construction energy plus the
|
||||||
|
// bud's provision; exactly what `fund_bud` charges such a parent. Nullopt when the genome
|
||||||
|
// cannot bud or cannot build a cell from its investment.
|
||||||
|
[[nodiscard]] std::optional<accounting::Inventory> bud_cost(const Genome& genome,
|
||||||
|
std::uint32_t temperature_millikelvin);
|
||||||
} // namespace evo::biology
|
} // namespace evo::biology
|
||||||
|
|||||||
@@ -280,6 +280,11 @@ struct CellularLifeDiagnostics {
|
|||||||
bool has_tick_effects{};
|
bool has_tick_effects{};
|
||||||
CellularEngulfResult engulf{CellularEngulfResult::not_reported}; // v10 only.
|
CellularEngulfResult engulf{CellularEngulfResult::not_reported}; // v10 only.
|
||||||
CellularBudOutcome bud{CellularBudOutcome::not_reported}; // v10 only.
|
CellularBudOutcome bud{CellularBudOutcome::not_reported}; // v10 only.
|
||||||
|
// v10 only (ADR-0129 amendment): what one bud takes from the reserve once the cell is
|
||||||
|
// fully grown: construction and provision energy plus matter per channel. All zero
|
||||||
|
// when this cell's genome cannot bud. Independent of tick effects.
|
||||||
|
std::uint64_t bud_cost_energy_pj{};
|
||||||
|
std::array<std::uint64_t, 4> bud_cost_matter_fg{};
|
||||||
friend bool operator==(const CellularLifeDiagnostics&,
|
friend bool operator==(const CellularLifeDiagnostics&,
|
||||||
const CellularLifeDiagnostics&) = default;
|
const CellularLifeDiagnostics&) = default;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -82,6 +82,19 @@ and byte 78 the bud result (0 not reported, 1 not requested,
|
|||||||
2 budded, 3 not able, 4 insufficient funding, 5 no placement); bytes 79-81 stay
|
2 budded, 3 not able, 4 insufficient funding, 5 no placement); bytes 79-81 stay
|
||||||
zero, and both results are zero without tick effects. v9 keeps bytes 77-81 zero.
|
zero, and both results are zero without tick effects. v9 keeps bytes 77-81 zero.
|
||||||
|
|
||||||
|
A v10 diagnostics block is followed by the bud cost (ADR-0129 amendment, 2026-10-15),
|
||||||
|
so v10 patch records start at payload offset 122:
|
||||||
|
|
||||||
|
| Payload offset | Size | Field |
|
||||||
|
|---:|---:|---|
|
||||||
|
| 82 | 8 | bud cost energy, pJ: construction plus the bud's provision |
|
||||||
|
| 90 | 32 | bud cost C, N, P, other, each fg: the investment matter |
|
||||||
|
|
||||||
|
It is what one bud takes from the reserve once the cell is fully grown and undamaged,
|
||||||
|
exactly as the owner funds it, and it does not depend on tick effects. All zero means
|
||||||
|
this genome cannot bud. A cleared zero-life view must carry an all-zero bud cost. v9
|
||||||
|
has no bud cost.
|
||||||
|
|
||||||
Type 27 (server to owner, reliable stream, v10 only) is exactly 24 bytes: the
|
Type 27 (server to owner, reliable stream, v10 only) is exactly 24 bytes: the
|
||||||
tick (u64, nonzero), the life identity (u64, nonzero), the cause (u8: 0 not
|
tick (u64, nonzero), the life identity (u64, nonzero), the cause (u8: 0 not
|
||||||
recorded, 1 starved, 2 engulfed) and seven zero bytes.
|
recorded, 1 starved, 2 engulfed) and seven zero bytes.
|
||||||
|
|||||||
@@ -77,4 +77,22 @@ std::expected<BudTransition, BuddingError> fund_bud(const Genome& genome, Growth
|
|||||||
}
|
}
|
||||||
return std::unexpected{BuddingError::insufficient_funding}; // Too little to build a cell.
|
return std::unexpected{BuddingError::insufficient_funding}; // Too little to build a cell.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<accounting::Inventory> bud_cost(const Genome& genome,
|
||||||
|
std::uint32_t temperature_millikelvin) {
|
||||||
|
// Fund against an ample reserve and read the charge: one code path decides both.
|
||||||
|
constexpr std::uint64_t ample = std::uint64_t{1} << 60U;
|
||||||
|
const accounting::Inventory unlimited{
|
||||||
|
{ample},
|
||||||
|
{accounting::Femtograms{ample}, accounting::Femtograms{ample},
|
||||||
|
accounting::Femtograms{ample}, accounting::Femtograms{ample}}};
|
||||||
|
const auto funded = fund_bud(genome, {1000, 0}, unlimited, temperature_millikelvin);
|
||||||
|
if (!funded)
|
||||||
|
return std::nullopt;
|
||||||
|
accounting::Inventory cost;
|
||||||
|
cost.energy.value = ample - funded->parent_reserve.energy.value;
|
||||||
|
for (std::size_t channel = 0; channel < cost.matter.size(); ++channel)
|
||||||
|
cost.matter[channel].value = ample - funded->parent_reserve.matter[channel].value;
|
||||||
|
return cost;
|
||||||
|
}
|
||||||
} // namespace evo::biology
|
} // namespace evo::biology
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ constexpr std::size_t cellular_perception_prefix_bytes = 8 + 8 + 2;
|
|||||||
constexpr std::size_t cellular_diagnostics_bytes = 64;
|
constexpr std::size_t cellular_diagnostics_bytes = 64;
|
||||||
constexpr std::size_t cellular_perception_v9_prefix_bytes =
|
constexpr std::size_t cellular_perception_v9_prefix_bytes =
|
||||||
cellular_perception_prefix_bytes + cellular_diagnostics_bytes;
|
cellular_perception_prefix_bytes + cellular_diagnostics_bytes;
|
||||||
|
// v10 appends the bud cost (energy and four matter channels, ADR-0129 amendment).
|
||||||
|
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;
|
||||||
constexpr std::size_t cellular_perceived_patch_bytes = 8 + 8 + (4 * 8);
|
constexpr std::size_t cellular_perceived_patch_bytes = 8 + 8 + (4 * 8);
|
||||||
constexpr std::size_t intention_receipt_bytes = 8 + 1 + 8;
|
constexpr std::size_t intention_receipt_bytes = 8 + 1 + 8;
|
||||||
constexpr std::size_t simulated_bytes = std::size_t{3} * 8;
|
constexpr std::size_t simulated_bytes = std::size_t{3} * 8;
|
||||||
@@ -195,11 +199,15 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
|||||||
ended && (version != session_protocol_v10 || ended->tick == 0 ||
|
ended && (version != session_protocol_v10 || ended->tick == 0 ||
|
||||||
ended->life_identity == 0 || ended->cause > CellularDeathReason::engulfed))
|
ended->life_identity == 0 || ended->cause > CellularDeathReason::engulfed))
|
||||||
return {};
|
return {};
|
||||||
// v9 has no room for engulf and bud effects; only v10 reports them (ADR-0129).
|
// v9 has no room for engulf and bud effects or the bud cost; only v10 reports them
|
||||||
|
// (ADR-0129).
|
||||||
if (const auto* perception = std::get_if<CellularPerception>(&message);
|
if (const auto* perception = std::get_if<CellularPerception>(&message);
|
||||||
perception && version != session_protocol_v10 && perception->diagnostics &&
|
perception && version != session_protocol_v10 && perception->diagnostics &&
|
||||||
(perception->diagnostics->engulf != CellularEngulfResult::not_reported ||
|
(perception->diagnostics->engulf != CellularEngulfResult::not_reported ||
|
||||||
perception->diagnostics->bud != CellularBudOutcome::not_reported))
|
perception->diagnostics->bud != CellularBudOutcome::not_reported ||
|
||||||
|
perception->diagnostics->bud_cost_energy_pj != 0 ||
|
||||||
|
std::ranges::any_of(perception->diagnostics->bud_cost_matter_fg,
|
||||||
|
[](std::uint64_t value) { return value != 0; })))
|
||||||
return {};
|
return {};
|
||||||
if (const auto* action = std::get_if<CellularAction>(&message);
|
if (const auto* action = std::get_if<CellularAction>(&message);
|
||||||
action && (action->engulf || action->bud) &&
|
action && (action->engulf || action->bud) &&
|
||||||
@@ -334,12 +342,13 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
std::vector<std::uint8_t> operator()(const CellularPerception& m) const {
|
std::vector<std::uint8_t> operator()(const CellularPerception& m) const {
|
||||||
auto out = header(SessionMessageType::cellular_perception,
|
auto out =
|
||||||
(version == session_protocol_v9 || version == session_protocol_v10
|
header(SessionMessageType::cellular_perception,
|
||||||
? cellular_perception_v9_prefix_bytes
|
(version == session_protocol_v10 ? cellular_perception_v10_prefix_bytes
|
||||||
: cellular_perception_prefix_bytes) +
|
: version == session_protocol_v9 ? cellular_perception_v9_prefix_bytes
|
||||||
m.patches.size() * cellular_perceived_patch_bytes,
|
: cellular_perception_prefix_bytes) +
|
||||||
version);
|
m.patches.size() * cellular_perceived_patch_bytes,
|
||||||
|
version);
|
||||||
put(out, m.tick, 8);
|
put(out, m.tick, 8);
|
||||||
put(out, m.life_identity, 8);
|
put(out, m.life_identity, 8);
|
||||||
put(out, m.patches.size(), 2);
|
put(out, m.patches.size(), 2);
|
||||||
@@ -359,6 +368,10 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
|||||||
out.push_back(d ? static_cast<std::uint8_t>(d->engulf) : 0);
|
out.push_back(d ? static_cast<std::uint8_t>(d->engulf) : 0);
|
||||||
out.push_back(d ? static_cast<std::uint8_t>(d->bud) : 0);
|
out.push_back(d ? static_cast<std::uint8_t>(d->bud) : 0);
|
||||||
put(out, 0, 3);
|
put(out, 0, 3);
|
||||||
|
put(out, d ? d->bud_cost_energy_pj : 0, 8);
|
||||||
|
for (const auto value :
|
||||||
|
d ? d->bud_cost_matter_fg : std::array<std::uint64_t, 4>{})
|
||||||
|
put(out, value, 8);
|
||||||
} else {
|
} else {
|
||||||
put(out, 0, 5);
|
put(out, 0, 5);
|
||||||
}
|
}
|
||||||
@@ -692,9 +705,9 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
|||||||
wire_version != session_protocol_v10)
|
wire_version != session_protocol_v10)
|
||||||
return std::unexpected(SessionCodecError::unsupported_version);
|
return std::unexpected(SessionCodecError::unsupported_version);
|
||||||
const auto prefix =
|
const auto prefix =
|
||||||
wire_version == session_protocol_v9 || wire_version == session_protocol_v10
|
wire_version == session_protocol_v10 ? cellular_perception_v10_prefix_bytes
|
||||||
? cellular_perception_v9_prefix_bytes
|
: wire_version == session_protocol_v9 ? cellular_perception_v9_prefix_bytes
|
||||||
: cellular_perception_prefix_bytes;
|
: cellular_perception_prefix_bytes;
|
||||||
if (payload.size() < prefix)
|
if (payload.size() < prefix)
|
||||||
return std::unexpected(SessionCodecError::wrong_length);
|
return std::unexpected(SessionCodecError::wrong_length);
|
||||||
const auto count = static_cast<std::size_t>(get(payload, 16, 2));
|
const auto count = static_cast<std::size_t>(get(payload, 16, 2));
|
||||||
@@ -726,6 +739,9 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
|||||||
if (wire_version == session_protocol_v10) {
|
if (wire_version == session_protocol_v10) {
|
||||||
d.engulf = static_cast<CellularEngulfResult>(payload[77]);
|
d.engulf = static_cast<CellularEngulfResult>(payload[77]);
|
||||||
d.bud = static_cast<CellularBudOutcome>(payload[78]);
|
d.bud = static_cast<CellularBudOutcome>(payload[78]);
|
||||||
|
d.bud_cost_energy_pj = get(payload, 82, 8);
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
d.movement = static_cast<CellularMovementResult>(payload[74]);
|
d.movement = static_cast<CellularMovementResult>(payload[74]);
|
||||||
d.intake = static_cast<CellularIntakeResult>(payload[75]);
|
d.intake = static_cast<CellularIntakeResult>(payload[75]);
|
||||||
@@ -739,7 +755,9 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
|||||||
d.movement != CellularMovementResult::not_reported ||
|
d.movement != CellularMovementResult::not_reported ||
|
||||||
d.intake != CellularIntakeResult::not_reported ||
|
d.intake != CellularIntakeResult::not_reported ||
|
||||||
d.engulf != CellularEngulfResult::not_reported ||
|
d.engulf != CellularEngulfResult::not_reported ||
|
||||||
d.bud != CellularBudOutcome::not_reported)
|
d.bud != CellularBudOutcome::not_reported || d.bud_cost_energy_pj ||
|
||||||
|
std::ranges::any_of(d.bud_cost_matter_fg,
|
||||||
|
[](std::uint64_t value) { return value != 0; }))
|
||||||
return std::unexpected(SessionCodecError::invalid_value);
|
return std::unexpected(SessionCodecError::invalid_value);
|
||||||
}
|
}
|
||||||
if ((wire_version == session_protocol_v9 || wire_version == session_protocol_v10) &&
|
if ((wire_version == session_protocol_v9 || wire_version == session_protocol_v10) &&
|
||||||
|
|||||||
@@ -113,6 +113,36 @@ void only_a_grown_undamaged_reproducing_parent_buds() {
|
|||||||
CHECK(barren);
|
CHECK(barren);
|
||||||
CHECK(fund_bud(*barren, {1000, 0}, plenty(), temperate).error() == BuddingError::no_capability);
|
CHECK(fund_bud(*barren, {1000, 0}, plenty(), temperate).error() == BuddingError::no_capability);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ADR-0129 amendment: the shown bud cost is exactly the charge. A reserve equal to it buds;
|
||||||
|
// one unit short on any channel refuses.
|
||||||
|
void the_shown_bud_cost_is_exactly_what_funding_takes() {
|
||||||
|
const auto genome = founder();
|
||||||
|
const auto shown = bud_cost(genome, temperate);
|
||||||
|
if (!shown)
|
||||||
|
throw std::runtime_error("budding: founder has no bud cost");
|
||||||
|
const Inventory cost = *shown;
|
||||||
|
CHECK(cost.energy.value != 0);
|
||||||
|
const auto exact = fund_bud(genome, {1000, 0}, cost, temperate);
|
||||||
|
CHECK(exact && exact->parent_reserve == Inventory{});
|
||||||
|
for (std::size_t c = 0; c <= cost.matter.size(); ++c) {
|
||||||
|
auto short_one = cost;
|
||||||
|
auto& unit = c == 0 ? short_one.energy.value : short_one.matter[c - 1].value;
|
||||||
|
if (unit == 0)
|
||||||
|
continue;
|
||||||
|
--unit;
|
||||||
|
CHECK(fund_bud(genome, {1000, 0}, short_one, temperate).error() ==
|
||||||
|
BuddingError::insufficient_funding);
|
||||||
|
}
|
||||||
|
const auto barren = Genome::create({9,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
{},
|
||||||
|
{{Capability::energy_conversion, 400, 0},
|
||||||
|
{Capability::membrane, 1, 0},
|
||||||
|
{Capability::target_size, 8'000'000, 0}}});
|
||||||
|
CHECK(barren && !bud_cost(*barren, temperate));
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@@ -120,6 +150,7 @@ int main() {
|
|||||||
a_grown_parent_funds_the_largest_bud_its_investment_builds();
|
a_grown_parent_funds_the_largest_bud_its_investment_builds();
|
||||||
every_short_channel_refuses_and_spends_nothing();
|
every_short_channel_refuses_and_spends_nothing();
|
||||||
only_a_grown_undamaged_reproducing_parent_buds();
|
only_a_grown_undamaged_reproducing_parent_buds();
|
||||||
|
the_shown_bud_cost_is_exactly_what_funding_takes();
|
||||||
} catch (const std::exception& error) {
|
} catch (const std::exception& error) {
|
||||||
std::cerr << error.what() << '\n';
|
std::cerr << error.what() << '\n';
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -316,6 +316,39 @@ void v10_effects_and_life_end_are_owner_only() {
|
|||||||
idle.diagnostics->bud = CellularBudOutcome::budded; // Effects need tick effects.
|
idle.diagnostics->bud = CellularBudOutcome::budded; // Effects need tick effects.
|
||||||
CHECK(encode_session(SessionMessage{idle}, session_protocol_v10).empty());
|
CHECK(encode_session(SessionMessage{idle}, session_protocol_v10).empty());
|
||||||
|
|
||||||
|
// ADR-0129 amendment: v10 appends the bud cost (payload 82..121), with or without
|
||||||
|
// tick effects; v9 cannot carry it, and a cleared view carries none.
|
||||||
|
auto costed = perception;
|
||||||
|
costed.diagnostics->bud_cost_energy_pj = 0x0102030405060708;
|
||||||
|
costed.diagnostics->bud_cost_matter_fg = {11, 22, 33, 44};
|
||||||
|
const auto costed_bytes = encode_session(SessionMessage{costed}, session_protocol_v10);
|
||||||
|
CHECK(costed_bytes.size() == bytes.size() && costed_bytes[session_header_bytes + 82] == 0x08 &&
|
||||||
|
costed_bytes[session_header_bytes + 89] == 0x01 &&
|
||||||
|
costed_bytes[session_header_bytes + 90] == 11 &&
|
||||||
|
costed_bytes[session_header_bytes + 114] == 44);
|
||||||
|
CHECK(std::get<CellularPerception>(*decode_session(costed_bytes)) == costed);
|
||||||
|
CHECK(bytes.size() == session_header_bytes + 18 + 64 + 40);
|
||||||
|
auto resting = costed;
|
||||||
|
resting.diagnostics->has_tick_effects = false;
|
||||||
|
resting.diagnostics->maintenance_cost_pj = 0;
|
||||||
|
resting.diagnostics->movement = CellularMovementResult::not_reported;
|
||||||
|
resting.diagnostics->intake = CellularIntakeResult::not_reported;
|
||||||
|
resting.diagnostics->engulf = CellularEngulfResult::not_reported;
|
||||||
|
resting.diagnostics->bud = CellularBudOutcome::not_reported;
|
||||||
|
CHECK(std::get<CellularPerception>(*decode_session(
|
||||||
|
encode_session(SessionMessage{resting}, session_protocol_v10))) == resting);
|
||||||
|
auto v9_costed = resting;
|
||||||
|
v9_costed.diagnostics->engulf = CellularEngulfResult::not_reported;
|
||||||
|
CHECK(encode_session(SessionMessage{v9_costed}, session_protocol_v9).empty());
|
||||||
|
v9_costed.diagnostics->bud_cost_energy_pj = 0;
|
||||||
|
v9_costed.diagnostics->bud_cost_matter_fg = {};
|
||||||
|
CHECK(!encode_session(SessionMessage{v9_costed}, session_protocol_v9).empty());
|
||||||
|
auto cleared = encode_session(SessionMessage{CellularPerception{40, 0, {}, std::nullopt}},
|
||||||
|
session_protocol_v10);
|
||||||
|
CHECK(!cleared.empty() && decode_session(cleared));
|
||||||
|
cleared[session_header_bytes + 90] = 1; // A cleared view with a bud cost.
|
||||||
|
CHECK(!decode_session(cleared));
|
||||||
|
|
||||||
const CellularLifeEnded ended{41, 7, CellularDeathReason::engulfed};
|
const CellularLifeEnded ended{41, 7, CellularDeathReason::engulfed};
|
||||||
const auto ended_bytes = encode_session(SessionMessage{ended});
|
const auto ended_bytes = encode_session(SessionMessage{ended});
|
||||||
std::uint16_t version{};
|
std::uint16_t version{};
|
||||||
|
|||||||
Reference in New Issue
Block a user