Carry bud actions and the v5 bundle through protocol and persistence
Foundation / checks (ecs) (push) Successful in 2m30s
Foundation / checks (deploy) (push) Successful in 4m0s
Foundation / checks (tsan) (push) Successful in 10m37s
Foundation / checks (client) (push) Failing after 13m56s
Foundation / checks (network) (push) Successful in 19m9s
Foundation / checks (checks) (push) Successful in 42m54s
Foundation / checks (postgres) (push) Successful in 44m9s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Foundation / checks (ecs) (push) Successful in 2m30s
Foundation / checks (deploy) (push) Successful in 4m0s
Foundation / checks (tsan) (push) Successful in 10m37s
Foundation / checks (client) (push) Failing after 13m56s
Foundation / checks (network) (push) Successful in 19m9s
Foundation / checks (checks) (push) Successful in 42m54s
Foundation / checks (postgres) (push) Successful in 44m9s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
M11.5c (ADR-0125): v10 cellular actions, the canonical input and the trace carry target kind 3 (bud), matched to durable actions; below rules 4 the owner ignores it. The v5 version bundle is admitted in C++ and by schema v36, which also admits kind 3 in SQL action inputs; the provisioner offers cellular-v3. A PostgreSQL test publishes a bud from a fed founder and recovers it after a host restart. The publication tests now use commit ids no other suite produces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,14 +10,15 @@
|
||||
// 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|primitive-v1|cellular-v1|cellular-v2
|
||||
// development-v1|primitive-v1|cellular-v1|cellular-v2|cellular-v3
|
||||
// --pg-* ... --objects DIR --build HEX [--commit HEX32] [--retain-build]
|
||||
// primitive-v1 also requires --frame N --source-id N, every --funding-*-* channel,
|
||||
// and one or more ordered --site X,Y values.
|
||||
// cellular-v1 and cellular-v2 also require --width-um N --height-um N
|
||||
// cellular-v1, cellular-v2 and cellular-v3 also require --width-um N --height-um N
|
||||
// --ambient-temperature-mk N and one or more ordered --patch X,Y,SOURCE,ENERGY,C,N,P,O values
|
||||
// plus a stable --commit HEX32. cellular-v2 is the same opening on rules 3 (ADR-0124:
|
||||
// engulfment, detritus). primitive-v1 and cellular-v1/v2 accept --life-allocator-start N
|
||||
// engulfment, detritus); cellular-v3 is it on rules 4 (ADR-0125: budding wildlife).
|
||||
// primitive-v1 and cellular-v1/v2/v3 accept --life-allocator-start N
|
||||
// (ADR-0123): the world's life-identity allocator is created once at the operator-audited
|
||||
// start N; a later run leaves it untouched and refuses one that is below N.
|
||||
// evo-world-clone compare --world A --region R --other-world B --pg-* ...
|
||||
@@ -272,7 +273,7 @@ std::optional<Options> parse(int argc, char** argv) {
|
||||
o.reserve_mib = *n;
|
||||
else if (o.command == "provision" && flag == "--opening" &&
|
||||
(value == "development-v1" || value == "primitive-v1" || value == "cellular-v1" ||
|
||||
value == "cellular-v2"))
|
||||
value == "cellular-v2" || value == "cellular-v3"))
|
||||
o.opening = value;
|
||||
else if (o.command == "provision" && flag == "--frame" && n)
|
||||
o.primitive_frame = n;
|
||||
@@ -345,7 +346,8 @@ std::optional<Options> parse(int argc, char** argv) {
|
||||
return std::nullopt;
|
||||
if (cellular_options)
|
||||
return std::nullopt;
|
||||
} else if (o.opening == "cellular-v1" || o.opening == "cellular-v2") {
|
||||
} else if (o.opening == "cellular-v1" || o.opening == "cellular-v2" ||
|
||||
o.opening == "cellular-v3") {
|
||||
const bool has_stock = std::ranges::any_of(o.cellular_patches, [](const auto& patch) {
|
||||
return patch.stock.energy.value != 0 ||
|
||||
std::ranges::any_of(patch.stock.matter,
|
||||
@@ -454,7 +456,8 @@ std::vector<std::uint8_t> probe_bytes() {
|
||||
|
||||
int provision(const Options& o) {
|
||||
const bool primitive = o.opening == "primitive-v1";
|
||||
const bool cellular = o.opening == "cellular-v1" || o.opening == "cellular-v2";
|
||||
const bool cellular =
|
||||
o.opening == "cellular-v1" || o.opening == "cellular-v2" || o.opening == "cellular-v3";
|
||||
const auto primitive_frame = o.primitive_frame.value_or(0);
|
||||
if ((primitive || cellular) && primitive_frame == 0)
|
||||
return 2;
|
||||
@@ -557,8 +560,9 @@ int provision(const Options& o) {
|
||||
auto opening = server::CellularLives::create(
|
||||
*primitive_opening, std::move(*habitat),
|
||||
{{cellular_width_um, cellular_height_um}, 0, cellular_temperature_mk},
|
||||
o.opening == "cellular-v2" ? server::CellularLivesProfile::engulf
|
||||
: server::CellularLivesProfile::offers);
|
||||
o.opening == "cellular-v3" ? server::CellularLivesProfile::budding
|
||||
: o.opening == "cellular-v2" ? server::CellularLivesProfile::engulf
|
||||
: server::CellularLivesProfile::offers);
|
||||
if (!opening) {
|
||||
std::printf("cellular opening refused %u\n", static_cast<unsigned>(opening.error()));
|
||||
return 4;
|
||||
|
||||
@@ -12,7 +12,7 @@ spec:
|
||||
env:
|
||||
- {name: REGION_SESSION, value: "dev"}
|
||||
- {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"}
|
||||
- {name: REGION_SESSION_WINDOW, value: "dev-20261014T025703-57119:1791957423"}
|
||||
- {name: REGION_SESSION_WINDOW, value: "dev-20261014T104241-63911:1791985361"}
|
||||
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
|
||||
ports:
|
||||
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
|
||||
|
||||
@@ -34,6 +34,9 @@ matter, priced at the parent's own construction rate.
|
||||
outcome, exact retry. The client supplies only the intention.
|
||||
- The same kind in a wildlife intention is how the controller buds. There is no
|
||||
second path.
|
||||
- Below rules 4 the owner ignores a bud intention and reports no bud result, as
|
||||
rules 2 ignore engulfment. Refusing it would let one v10 client's bud fail the
|
||||
whole tick for every life in an older region.
|
||||
|
||||
### Funding (rules 4)
|
||||
|
||||
@@ -70,8 +73,10 @@ lives in stable life-id order, using the state entering that phase:
|
||||
`2^63 + region * 2^32 + sequence`, where `sequence` is a per-region counter in
|
||||
the owner state, starting at 1. It is server-derived, durable in the checkpoint,
|
||||
never reused, and replay derives it without a database round trip. Regions above
|
||||
`2^31 - 1` cannot bud. Schema v36 adds a check that the world allocator stays
|
||||
at or below `2^63`, so allocated and budded identities can never collide.
|
||||
`2^31 - 1` cannot bud. A rules-4 owner refuses a founder whose allocated identity
|
||||
is at or above `2^63`, so allocated and budded identities can never collide. The
|
||||
world allocator keeps its full u64 range (its tests exercise it); it starts far
|
||||
below the namespace (`10^12` in DEV) and advances by one per life.
|
||||
- The bud carries its parent's current genome (the same genome record, an exact
|
||||
copy). The archive records the bud organism's birth with that genome and tick;
|
||||
the owner records the parent life on the bud and keeps it after death.
|
||||
@@ -100,7 +105,7 @@ lives in stable life-id order, using the state entering that phase:
|
||||
placement and wildlife.
|
||||
- Cellular version bundle v5. The replay trace stays format 3: kind 3 is an
|
||||
intention byte value. Schema v36 admits kind 3 in action inputs, the v5 bundle
|
||||
for revision-format publication and births, and the allocator bound.
|
||||
for revision-format publication and births.
|
||||
|
||||
## Alternatives
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ descendant, and no special wildlife biology.
|
||||
channel (abundant energy never pays for matter), partial growth, damage and a
|
||||
genome without the capability.
|
||||
- 11.5b: owner format 5 / rules 4 (`CellularLivesProfile::budding`). A
|
||||
`CellularStepIntent::bud` (rules 4 only, exclusive with feeding and
|
||||
`CellularStepIntent::bud` (ignored below rules 4, exclusive with feeding and
|
||||
engulfing) funds a bud after the tick's mutations through `fund_bud`, places
|
||||
it touching the parent (eight fixed directions), gives it the next
|
||||
region-namespace identity and the parent's current genome, and records its
|
||||
@@ -58,4 +58,13 @@ descendant, and no special wildlife biology.
|
||||
offers. Validation and restore enforce the identity namespace and sequence;
|
||||
`cellular-lives-owner` buds a fed founder, checks the refusals spend nothing,
|
||||
conservation, the shared genome's two carriers, wildlife feeding without
|
||||
offers, exact restore and a rewound sequence; rules 3 refuses a bud intent.
|
||||
offers, exact restore and a rewound sequence; rules 3 ignores a bud intent.
|
||||
- 11.5c: v10 cellular actions and the canonical input carry target kind 3
|
||||
(bud, zero coordinates, exclusive with intake and engulfment); the trace keeps
|
||||
it as an intention byte and the action matcher compares it. Below rules 4 the
|
||||
owner ignores it. The v5 version bundle (`{4,5,1,1,1,2,1,2,1}`, revision
|
||||
history) is admitted in C++ and by schema v36, which also admits kind 3 in SQL
|
||||
action inputs and the v5 bundle for format-3 birth traces. The provisioner
|
||||
offers `cellular-v3` (rules 4). A rules-4 owner refuses founder identities at
|
||||
or above 2^63; the allocator keeps its full range. PostgreSQL tests publish a
|
||||
real bud from a fed founder, restart the host and recover the wildlife cell.
|
||||
|
||||
@@ -7363,3 +7363,30 @@ refusal of a bud intent.
|
||||
|
||||
Executed locally: MSVC Debug `ctest` 69/69; g++-14 `-Werror`, clang-tidy-19 and
|
||||
clang-format 19.1.5 on the owner, region step and owner tests.
|
||||
|
||||
## 2026-10-14 — CI run 372 PostgreSQL failure and fix; M11.5c bud action and v5 bundle
|
||||
|
||||
Run 372 (187b1a7, M11.4c) failed only `checks (postgres)`: the M11.4c-1
|
||||
publication test's first 64-tick feeding publish was refused client-side. The
|
||||
PostgreSQL adapter bounded every parameter to 4 KiB of text (ADR-0059), and a
|
||||
cellular trace is sent as one hex `bytea` parameter, so any trace over about
|
||||
2 KiB failed as `bounds` and surfaced as `invalid`. A one-tick trace crosses that
|
||||
at about 85 lives, which budding makes reachable. ADR-0126 raises the bound to
|
||||
4 MiB, enough for the largest admitted trace. The same run would then have
|
||||
failed on test commit ids: the new publication tests used uniform-byte commit
|
||||
ids (`0x60`, `0x65`) that other suites also produce; they now use mixed bytes.
|
||||
|
||||
M11.5c adds bud target kind 3 (v10 actions, canonical input, trace intention,
|
||||
action matching), the v5 bundle, schema v36 (kind 3 in SQL inputs, v5 bundle
|
||||
normalization and birth binding), the `cellular-v3` provisioner opening, and
|
||||
tests: protocol and canonical-input kind 3, session batch and trace round trip,
|
||||
v5 checkpoint restore, v36 SQL checks, `cellular-v3` provisioning, and a
|
||||
PostgreSQL bud publication with host restart and recovery.
|
||||
|
||||
Executed locally: `postgres-check.sh --full` (WSL g++-14 Release: C++ suite, life
|
||||
reservations, backup, DR, upgrade, migration history, permission audit and checksum
|
||||
drift; 489 s) passes; before that the C++ suite (`postgres-check.sh
|
||||
--suite-only`, WSL g++-14 Release) passes, including the M11.4c-1/-2 and M11.5
|
||||
publication tests; MSVC Debug 69/69, network 75/75, client-network 89/89 (the
|
||||
two motion-trace smokes needed a serial rerun under load); g++-14 `-Werror`,
|
||||
clang-tidy-19 (no new findings) and clang-format 19.1.5 on the changed sources.
|
||||
|
||||
@@ -60,12 +60,12 @@ class RegionSessionClient {
|
||||
[[nodiscard]] bool send_action(std::uint64_t action_id, network::ActionKind kind,
|
||||
std::uint64_t tick);
|
||||
// Protocol v7-v10. Reuse the exact same fields and action id after reconnect. `engulf`
|
||||
// (ADR-0124) needs a v10 session and no intake target.
|
||||
// and `bud` (ADR-0124/0125) are exclusive and need a v10 session and no intake target.
|
||||
[[nodiscard]] bool
|
||||
send_cellular_action(std::uint64_t action_id, std::uint64_t tick, std::int16_t move_x,
|
||||
std::int16_t move_y,
|
||||
std::optional<std::pair<std::uint32_t, std::uint32_t>> intake_target = {},
|
||||
bool engulf = false);
|
||||
bool engulf = false, bool bud = false);
|
||||
// Protocol v10 (ADR-0121): choose one candidate of the life's outstanding offer. The
|
||||
// receipt names the tick it publishes with; the outcome follows that commit. `tick` is
|
||||
// the client's latest simulated tick (after the offer); the server schedules the next.
|
||||
|
||||
@@ -174,6 +174,7 @@ struct CellularActionInput {
|
||||
bool has_intake_target{};
|
||||
std::uint32_t intake_x_um{}, intake_y_um{};
|
||||
bool engulf{};
|
||||
bool bud{}; // Kind 3 (ADR-0125): fund one wildlife bud, zero coordinates, v10 only.
|
||||
friend bool operator==(const CellularActionInput&, const CellularActionInput&) = default;
|
||||
};
|
||||
inline constexpr std::size_t cellular_action_input_bytes = 24;
|
||||
@@ -186,6 +187,8 @@ struct CellularAction {
|
||||
std::uint32_t intake_x_um{}, intake_y_um{};
|
||||
// v10 (ADR-0124): engulf a smaller contacted cell; exclusive with an intake target.
|
||||
bool engulf{};
|
||||
// v10 (ADR-0125): fund one wildlife bud; exclusive with intake and engulfment.
|
||||
bool bud{};
|
||||
friend bool operator==(const CellularAction&, const CellularAction&) = default;
|
||||
};
|
||||
// v10 reliable choice. The server binds these values to the authenticated account and
|
||||
|
||||
@@ -55,9 +55,11 @@ inline constexpr CellularVersionBundle cellular_v2_versions{2, 2, 1, 1, 1, 2, 1,
|
||||
inline constexpr CellularVersionBundle cellular_v3_versions{2, 3, 1, 1, 1, 2, 1, 2, 1};
|
||||
// ADR-0124: rules 3 (engulfment, detritus) and owner envelope 4 (corpse causes).
|
||||
inline constexpr CellularVersionBundle cellular_v4_versions{3, 4, 1, 1, 1, 2, 1, 2, 1};
|
||||
// ADR-0125: rules 4 (budding wildlife) and owner envelope 5 (bud sequence, parents).
|
||||
inline constexpr CellularVersionBundle cellular_v5_versions{4, 5, 1, 1, 1, 2, 1, 2, 1};
|
||||
// Bundles with genome revisions: the revision history profile and format-3 traces.
|
||||
[[nodiscard]] constexpr bool cellular_revision_bundle(const CellularVersionBundle& b) noexcept {
|
||||
return b == cellular_v3_versions || b == cellular_v4_versions;
|
||||
return b == cellular_v3_versions || b == cellular_v4_versions || b == cellular_v5_versions;
|
||||
}
|
||||
|
||||
// Batch evidence bound by manifest v2 (ADR-0063); all zero at genesis.
|
||||
|
||||
@@ -26,8 +26,8 @@ inline constexpr std::uint32_t cellular_lives_engulf_rules = 3;
|
||||
// life; rules 4 add funded budding of unowned wildlife on top of rules 3.
|
||||
inline constexpr std::uint32_t cellular_lives_bud_format = 5;
|
||||
inline constexpr std::uint32_t cellular_lives_bud_rules = 4;
|
||||
// A bud's life, organism and event identity: 2^63 + region * 2^32 + sequence. The world
|
||||
// allocator stays at or below 2^63 (schema v36), so the namespaces never meet.
|
||||
// A bud's life, organism and event identity: 2^63 + region * 2^32 + sequence. A rules-4
|
||||
// owner refuses an allocated identity at or above 2^63, so the namespaces never meet.
|
||||
inline constexpr std::uint64_t cellular_bud_namespace = std::uint64_t{1} << 63U;
|
||||
inline constexpr std::uint64_t cellular_bud_max_region = (std::uint64_t{1} << 31U) - 1;
|
||||
[[nodiscard]] constexpr std::uint64_t cellular_bud_identity(std::uint64_t region,
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
-- M11.5, ADR-0125: admit the cellular-v5 bundle (rules 4: budding wildlife; owner
|
||||
-- envelope 5: bud sequence and parent lives) and canonical action target kind 3 (bud).
|
||||
-- Earlier bundles, kinds and committed rows keep their exact meaning.
|
||||
|
||||
-- Byte 12 of the canonical input is a target kind: 0 none, 1 patch, 2 engulf, 3 bud. Only
|
||||
-- a patch target carries coordinates. Widening cannot invalidate an existing row.
|
||||
CREATE OR REPLACE FUNCTION evolution.valid_cellular_action_input(p_input bytea, p_tick evolution.u64)
|
||||
RETURNS boolean LANGUAGE plpgsql IMMUTABLE STRICT
|
||||
SET search_path = pg_catalog, pg_temp AS $$
|
||||
BEGIN
|
||||
IF octet_length(p_input) <> 24 THEN
|
||||
RETURN false;
|
||||
END IF;
|
||||
IF evolution.manifest_uint(p_input, 0, 8) = 0
|
||||
OR evolution.manifest_uint(p_input, 0, 8) <> p_tick OR get_byte(p_input, 12) > 3
|
||||
OR substring(p_input FROM 14 FOR 3) <> '\x000000' THEN
|
||||
RETURN false;
|
||||
END IF;
|
||||
IF get_byte(p_input, 12) <> 1 AND substring(p_input FROM 17 FOR 8) <> '\x0000000000000000' THEN
|
||||
RETURN false;
|
||||
END IF;
|
||||
RETURN true;
|
||||
END $$;
|
||||
|
||||
-- The v5 bundle shares v3's revision history profile and format-3 traces. Normalize it
|
||||
-- to v3 for the existing parser chain, then report the real bundle.
|
||||
ALTER FUNCTION evolution.parse_checkpoint_manifest(bytea)
|
||||
RENAME TO parse_checkpoint_manifest_v35;
|
||||
|
||||
CREATE FUNCTION evolution.parse_checkpoint_manifest(m bytea)
|
||||
RETURNS evolution.checkpoint_manifest LANGUAGE plpgsql IMMUTABLE
|
||||
SET search_path = pg_catalog, pg_temp AS $$
|
||||
DECLARE
|
||||
r evolution.checkpoint_manifest;
|
||||
v3_bundle constant bytea := '\x020000000300000001000000010000000100000002000000010000000200000001000000';
|
||||
v5_bundle constant bytea := '\x040000000500000001000000010000000100000002000000010000000200000001000000';
|
||||
BEGIN
|
||||
IF m IS NOT NULL AND octet_length(m) = 360
|
||||
AND evolution.manifest_uint(m, 12, 4) = 4
|
||||
AND substring(m FROM 161 FOR 36) = v5_bundle
|
||||
AND evolution.manifest_uint(m, 228, 4) = 0
|
||||
AND evolution.manifest_uint(m, 232, 4) = 4
|
||||
AND evolution.manifest_uint(m, 236, 4) = 1 THEN
|
||||
r := evolution.parse_checkpoint_manifest_v35(overlay(m PLACING v3_bundle FROM 161 FOR 36));
|
||||
r.versions := v5_bundle;
|
||||
RETURN r;
|
||||
END IF;
|
||||
RETURN evolution.parse_checkpoint_manifest_v35(m);
|
||||
END $$;
|
||||
REVOKE ALL ON FUNCTION evolution.parse_checkpoint_manifest(bytea) FROM PUBLIC;
|
||||
|
||||
-- Birth binding: v3, v4 and v5 publications carry format-3 traces. Otherwise unchanged
|
||||
-- from schema v35.
|
||||
CREATE OR REPLACE FUNCTION evolution.cellular_births(p_trace bytea, p_manifest bytea)
|
||||
RETURNS TABLE(account_id uuid, request_id evolution.u64, generation evolution.u64,
|
||||
identity evolution.u64, born evolution.u64)
|
||||
LANGUAGE plpgsql IMMUTABLE SECURITY INVOKER SET search_path = pg_catalog, pg_temp AS $$
|
||||
DECLARE
|
||||
c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest);
|
||||
revision boolean;
|
||||
ticks numeric;
|
||||
tick_index integer;
|
||||
trace_format numeric;
|
||||
tick_header_size integer;
|
||||
intent_count numeric;
|
||||
birth_count numeric;
|
||||
mutation_count numeric;
|
||||
off integer := 112;
|
||||
account bytea;
|
||||
previous_account bytea;
|
||||
previous_request numeric;
|
||||
BEGIN
|
||||
revision := c.versions IN (
|
||||
'\x020000000300000001000000010000000100000002000000010000000200000001000000'::bytea,
|
||||
'\x030000000400000001000000010000000100000002000000010000000200000001000000'::bytea,
|
||||
'\x040000000500000001000000010000000100000002000000010000000200000001000000'::bytea);
|
||||
trace_format := evolution.manifest_uint(p_trace, 8, 4);
|
||||
tick_header_size := CASE trace_format WHEN 2 THEN 8 WHEN 3 THEN 16 ELSE 0 END;
|
||||
IF c.profile <> 4 OR c.commit_sequence = 0 OR p_trace IS NULL
|
||||
OR octet_length(p_trace) <> c.trace_bytes OR sha256(p_trace) <> c.trace_sha256
|
||||
OR substring(p_trace FROM 1 FOR 8) <> '\x45564c4342543031'
|
||||
OR tick_header_size = 0
|
||||
OR (revision AND trace_format <> 3)
|
||||
OR (NOT revision AND trace_format <> 2)
|
||||
OR evolution.manifest_uint(p_trace, 12, 4) <> 4
|
||||
OR evolution.manifest_uint(p_trace, 16, 8) <> c.world_id
|
||||
OR evolution.manifest_uint(p_trace, 24, 8) <> c.region_id
|
||||
OR evolution.manifest_uint(p_trace, 32, 8) <> c.frame_id
|
||||
OR encode(substring(p_trace FROM 41 FOR 16), 'hex')::uuid <> c.predecessor_commit
|
||||
OR substring(p_trace FROM 57 FOR 32) <> c.predecessor_digest
|
||||
OR evolution.manifest_uint(p_trace, 88, 8) <> c.begin_tick
|
||||
OR evolution.manifest_uint(p_trace, 96, 8) <> c.end_tick THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth trace binding' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
ticks := c.end_tick - c.begin_tick;
|
||||
IF ticks < 1 OR ticks > 64 OR evolution.manifest_uint(p_trace, 104, 4) <> ticks
|
||||
OR evolution.manifest_uint(p_trace, 108, 4) <> 0 THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth trace range' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
FOR tick_index IN 0 .. ticks::integer - 1 LOOP
|
||||
IF off + tick_header_size > octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'truncated cellular tick header' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
intent_count := evolution.manifest_uint(p_trace, off, 4);
|
||||
birth_count := evolution.manifest_uint(p_trace, off + 4, 4);
|
||||
mutation_count := 0;
|
||||
IF trace_format = 3 THEN
|
||||
mutation_count := evolution.manifest_uint(p_trace, off + 8, 4);
|
||||
IF evolution.manifest_uint(p_trace, off + 12, 4) <> 0 THEN
|
||||
RAISE EXCEPTION 'invalid cellular tick reserved word' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
END IF;
|
||||
IF intent_count > 256 OR birth_count > 256 OR mutation_count > 256
|
||||
OR off + tick_header_size + intent_count * 24 + birth_count * 40
|
||||
+ mutation_count * 40 > octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'invalid cellular tick counts' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
off := off + tick_header_size + intent_count::integer * 24;
|
||||
previous_account := ''::bytea;
|
||||
previous_request := -1;
|
||||
FOR birth_index IN 0 .. birth_count::integer - 1 LOOP
|
||||
account := substring(p_trace FROM off + 1 FOR 16);
|
||||
account_id := encode(account, 'hex')::uuid;
|
||||
request_id := evolution.manifest_uint(p_trace, off + 16, 8);
|
||||
generation := evolution.manifest_uint(p_trace, off + 24, 8);
|
||||
identity := evolution.manifest_uint(p_trace, off + 32, 8);
|
||||
born := c.begin_tick + tick_index + 1;
|
||||
IF account_id = '00000000-0000-0000-0000-000000000000' OR request_id = 0
|
||||
OR generation = 0 OR identity = 0
|
||||
OR (account, request_id) <= (previous_account, previous_request) THEN
|
||||
RAISE EXCEPTION 'invalid cellular birth record' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
previous_account := account;
|
||||
previous_request := request_id;
|
||||
off := off + 40;
|
||||
RETURN NEXT;
|
||||
END LOOP;
|
||||
off := off + mutation_count::integer * 40;
|
||||
END LOOP;
|
||||
IF off <> octet_length(p_trace) THEN
|
||||
RAISE EXCEPTION 'trailing cellular trace bytes' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
INSERT INTO evolution.schema_migrations(version, sha256) VALUES (36, :'migration_sha_36');
|
||||
+21
-4
@@ -111,6 +111,7 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
SELECT :'history_v32' || ',33:' || :'migration_sha_33' AS history_v33 \gset
|
||||
SELECT :'history_v33' || ',34:' || :'migration_sha_34' AS history_v34 \gset
|
||||
SELECT :'history_v34' || ',35:' || :'migration_sha_35' AS history_v35 \gset
|
||||
SELECT :'history_v35' || ',36:' || :'migration_sha_36' AS history_v36 \gset
|
||||
SELECT :'history' = :'history_v22' AS at_v22,
|
||||
:'history' = :'history_v23' AS at_v23,
|
||||
:'history' = :'history_v24' AS at_v24,
|
||||
@@ -124,8 +125,10 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
:'history' = :'history_v32' AS at_v32,
|
||||
:'history' = :'history_v33' AS at_v33,
|
||||
:'history' = :'history_v34' AS at_v34,
|
||||
:'history' = :'history_v35' AS at_v35 \gset
|
||||
\if :at_v35
|
||||
:'history' = :'history_v35' AS at_v35,
|
||||
:'history' = :'history_v36' AS at_v36 \gset
|
||||
\if :at_v36
|
||||
\elif :at_v35
|
||||
\elif :at_v34
|
||||
\elif :at_v33
|
||||
\elif :at_v32
|
||||
@@ -489,7 +492,8 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
coalesce(max(version), 0) = 32 AS at_v32,
|
||||
coalesce(max(version), 0) = 33 AS at_v33,
|
||||
coalesce(max(version), 0) = 34 AS at_v34,
|
||||
coalesce(max(version), 0) = 35 AS at_v35
|
||||
coalesce(max(version), 0) = 35 AS at_v35,
|
||||
coalesce(max(version), 0) = 36 AS at_v36
|
||||
FROM evolution.schema_migrations \gset
|
||||
\if :at_v24
|
||||
\ir 0025_cellular_v2_bundle.sql
|
||||
@@ -503,6 +507,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v25
|
||||
\ir 0026_cellular_profile_migration.sql
|
||||
\ir 0027_cellular_v3_migration.sql
|
||||
@@ -514,6 +519,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v26
|
||||
\ir 0027_cellular_v3_migration.sql
|
||||
\ir 0028_cellular_v3_trace_bounds.sql
|
||||
@@ -524,6 +530,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v27
|
||||
\ir 0028_cellular_v3_trace_bounds.sql
|
||||
\ir 0029_cellular_mutation_reservations.sql
|
||||
@@ -533,6 +540,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v28
|
||||
\ir 0029_cellular_mutation_reservations.sql
|
||||
\ir 0030_cellular_birth_publication_binding.sql
|
||||
@@ -541,6 +549,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v29
|
||||
\ir 0030_cellular_birth_publication_binding.sql
|
||||
\ir 0031_fix_cellular_birth_publication_record.sql
|
||||
@@ -548,29 +557,37 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v30
|
||||
\ir 0031_fix_cellular_birth_publication_record.sql
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v31
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v32
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v33
|
||||
\ir 0034_cellular_v4_engulf_bundle.sql
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v34
|
||||
\ir 0035_cellular_mutation_publication.sql
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v35
|
||||
\ir 0036_cellular_v5_budding_bundle.sql
|
||||
\elif :at_v36
|
||||
\else
|
||||
\echo 'Unknown or changed migration history after v35'
|
||||
\echo 'Unknown or changed migration history after v36'
|
||||
DO $$ BEGIN RAISE EXCEPTION 'unknown or changed migration history'; END $$;
|
||||
\endif
|
||||
-- Effective-privilege audit on every run, including no-ops (ADR-0060). Attributes
|
||||
|
||||
@@ -285,7 +285,7 @@ bool RegionSessionClient::send_action(std::uint64_t action_id, network::ActionKi
|
||||
|
||||
bool RegionSessionClient::send_cellular_action(
|
||||
std::uint64_t action_id, std::uint64_t tick, std::int16_t move_x, std::int16_t move_y,
|
||||
std::optional<std::pair<std::uint32_t, std::uint32_t>> intake_target, bool engulf) {
|
||||
std::optional<std::pair<std::uint32_t, std::uint32_t>> intake_target, bool engulf, bool bud) {
|
||||
auto& m = *impl_;
|
||||
return (m.protocol_version == network::session_protocol_v7 ||
|
||||
m.protocol_version == network::session_protocol_v8 ||
|
||||
@@ -295,7 +295,7 @@ bool RegionSessionClient::send_cellular_action(
|
||||
m.send(network::CellularAction{m.welcome->session, m.welcome->epoch, action_id, tick,
|
||||
move_x, move_y, intake_target.has_value(),
|
||||
intake_target ? intake_target->first : 0,
|
||||
intake_target ? intake_target->second : 0, engulf});
|
||||
intake_target ? intake_target->second : 0, engulf, bud});
|
||||
}
|
||||
|
||||
bool RegionSessionClient::send_cellular_mutation(std::uint64_t action_id, std::uint64_t tick,
|
||||
|
||||
@@ -238,8 +238,9 @@ ActionReceipt IntentAdmission::action(std::uint64_t session, const CellularActio
|
||||
const AdmissionFacts& facts) {
|
||||
const SessionAction base{m.session, m.epoch, m.action_id,
|
||||
static_cast<std::uint16_t>(ActionKind::cellular), m.tick};
|
||||
const auto bytes = encode_cellular_action_input(
|
||||
{m.tick, m.move_x, m.move_y, m.has_intake_target, m.intake_x_um, m.intake_y_um, m.engulf});
|
||||
const auto bytes =
|
||||
encode_cellular_action_input({m.tick, m.move_x, m.move_y, m.has_intake_target,
|
||||
m.intake_x_um, m.intake_y_um, m.engulf, m.bud});
|
||||
auto* s = find(session);
|
||||
if (!s)
|
||||
return {m.action_id, AdmitStatus::unknown_session, facts.server_tick, m.tick};
|
||||
@@ -279,8 +280,9 @@ std::optional<ActionReceipt> IntentAdmission::admit(std::uint64_t session, const
|
||||
const AdmissionFacts& facts) {
|
||||
const SessionAction base{m.session, m.epoch, m.action_id,
|
||||
static_cast<std::uint16_t>(ActionKind::cellular), m.tick};
|
||||
const auto bytes = encode_cellular_action_input(
|
||||
{m.tick, m.move_x, m.move_y, m.has_intake_target, m.intake_x_um, m.intake_y_um, m.engulf});
|
||||
const auto bytes =
|
||||
encode_cellular_action_input({m.tick, m.move_x, m.move_y, m.has_intake_target,
|
||||
m.intake_x_um, m.intake_y_um, m.engulf, m.bud});
|
||||
auto* s = find(session);
|
||||
if (!s)
|
||||
return ActionReceipt{m.action_id, AdmitStatus::unknown_session, facts.server_tick, m.tick};
|
||||
|
||||
@@ -184,9 +184,9 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
offer && (version != session_protocol_v10 || !valid_offer(*offer)))
|
||||
return {};
|
||||
if (const auto* action = std::get_if<CellularAction>(&message);
|
||||
action && action->engulf &&
|
||||
action && (action->engulf || action->bud) &&
|
||||
(version != session_protocol_v10 || action->has_intake_target || action->intake_x_um ||
|
||||
action->intake_y_um))
|
||||
action->intake_y_um || (action->engulf && action->bud)))
|
||||
return {};
|
||||
if (version != session_protocol_v8 && version != session_protocol_v9 &&
|
||||
version != session_protocol_v10 && std::holds_alternative<CellularPerception>(message))
|
||||
@@ -268,7 +268,7 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
put(out, v, 8);
|
||||
put(out, static_cast<std::uint16_t>(m.move_x), 2);
|
||||
put(out, static_cast<std::uint16_t>(m.move_y), 2);
|
||||
out.push_back(m.has_intake_target ? 1 : m.engulf ? 2 : 0); // Target kind.
|
||||
out.push_back(m.has_intake_target ? 1 : m.engulf ? 2 : m.bud ? 3 : 0); // Target kind.
|
||||
put(out, 0, 3);
|
||||
put(out, m.intake_x_um, 4);
|
||||
put(out, m.intake_y_um, 4);
|
||||
@@ -564,12 +564,13 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
m.tick = get(payload, 24, 8);
|
||||
m.move_x = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(payload, 32, 2)));
|
||||
m.move_y = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(payload, 34, 2)));
|
||||
// Target kind: 0 none, 1 patch intake, 2 engulf (v10 only, ADR-0124).
|
||||
if (payload[36] > (wire_version == session_protocol_v10 ? 2 : 1) || payload[37] != 0 ||
|
||||
// Target kind: 0 none, 1 patch intake, 2 engulf and 3 bud (v10 only, ADR-0124/0125).
|
||||
if (payload[36] > (wire_version == session_protocol_v10 ? 3 : 1) || payload[37] != 0 ||
|
||||
payload[38] != 0 || payload[39] != 0)
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
m.has_intake_target = payload[36] == 1;
|
||||
m.engulf = payload[36] == 2;
|
||||
m.bud = payload[36] == 3;
|
||||
m.intake_x_um = static_cast<std::uint32_t>(get(payload, 40, 4));
|
||||
m.intake_y_um = static_cast<std::uint32_t>(get(payload, 44, 4));
|
||||
if (!m.session || !m.epoch || !m.action_id || !m.tick ||
|
||||
@@ -859,7 +860,10 @@ encode_cellular_action_input(const CellularActionInput& input) {
|
||||
put(bytes, input.tick, 8);
|
||||
put(bytes, static_cast<std::uint16_t>(input.move_x), 2);
|
||||
put(bytes, static_cast<std::uint16_t>(input.move_y), 2);
|
||||
bytes.push_back(input.has_intake_target ? 1 : input.engulf ? 2 : 0); // Target kind.
|
||||
bytes.push_back(input.has_intake_target ? 1 // Target kind.
|
||||
: input.engulf ? 2
|
||||
: input.bud ? 3
|
||||
: 0);
|
||||
put(bytes, 0, 3);
|
||||
put(bytes, input.intake_x_um, 4);
|
||||
put(bytes, input.intake_y_um, 4);
|
||||
@@ -872,7 +876,7 @@ std::expected<CellularActionInput, SessionCodecError>
|
||||
decode_cellular_action_input(std::span<const std::uint8_t> bytes) {
|
||||
if (bytes.size() != cellular_action_input_bytes)
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
if (bytes[12] > 2 || bytes[13] != 0 || bytes[14] != 0 || bytes[15] != 0)
|
||||
if (bytes[12] > 3 || bytes[13] != 0 || bytes[14] != 0 || bytes[15] != 0)
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
CellularActionInput input;
|
||||
input.tick = get(bytes, 0, 8);
|
||||
@@ -880,6 +884,7 @@ decode_cellular_action_input(std::span<const std::uint8_t> bytes) {
|
||||
input.move_y = static_cast<std::int16_t>(static_cast<std::uint16_t>(get(bytes, 10, 2)));
|
||||
input.has_intake_target = bytes[12] == 1;
|
||||
input.engulf = bytes[12] == 2;
|
||||
input.bud = bytes[12] == 3;
|
||||
input.intake_x_um = static_cast<std::uint32_t>(get(bytes, 16, 4));
|
||||
input.intake_y_um = static_cast<std::uint32_t>(get(bytes, 20, 4));
|
||||
if (input.tick == 0 ||
|
||||
|
||||
@@ -158,6 +158,11 @@ provision_cellular_region(Postgres& owner, const FilesystemObjectStore& objects,
|
||||
// ADR-0124: a rules-3 region starts on the v4 bundle with genome revisions.
|
||||
manifest->cellular_versions = cellular_v4_versions;
|
||||
manifest->history_profile = cellular_revision_history_profile;
|
||||
} else if (manifest && opening.format_version() == server::cellular_lives_bud_format &&
|
||||
opening.rules_version() == server::cellular_lives_bud_rules) {
|
||||
// ADR-0125: a rules-4 region starts on the v5 bundle with genome revisions.
|
||||
manifest->cellular_versions = cellular_v5_versions;
|
||||
manifest->history_profile = cellular_revision_history_profile;
|
||||
} else if (manifest && (opening.format_version() != server::cellular_lives_legacy_format ||
|
||||
opening.rules_version() != 1))
|
||||
return std::unexpected{failure(PublicationError::candidate)};
|
||||
|
||||
@@ -70,7 +70,8 @@ bool structural(const CheckpointManifest& m) noexcept {
|
||||
(cellular && m.cellular_versions != cellular_v1_versions &&
|
||||
m.cellular_versions != cellular_v2_versions &&
|
||||
m.cellular_versions != cellular_v3_versions &&
|
||||
m.cellular_versions != cellular_v4_versions) ||
|
||||
m.cellular_versions != cellular_v4_versions &&
|
||||
m.cellular_versions != cellular_v5_versions) ||
|
||||
(cellular && m.versions != environmental_v1_versions))
|
||||
return false;
|
||||
if (primitive && (m.manifest_version != 2 || m.tick_microseconds != 50000 ||
|
||||
@@ -163,7 +164,8 @@ bool supported(const CheckpointManifest& m) noexcept {
|
||||
(m.cellular_versions == cellular_v1_versions ||
|
||||
m.cellular_versions == cellular_v2_versions ||
|
||||
m.cellular_versions == cellular_v3_versions ||
|
||||
m.cellular_versions == cellular_v4_versions) &&
|
||||
m.cellular_versions == cellular_v4_versions ||
|
||||
m.cellular_versions == cellular_v5_versions) &&
|
||||
m.versions == environmental_v1_versions && m.tick_microseconds == 50000 &&
|
||||
m.rng_streams == 0 && m.durability == DurabilityPolicy::single_volume_development;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ bool valid_intent(const CellularLifeIntent& life) {
|
||||
const auto& step = life.intent;
|
||||
return life.life_id != 0 && step.movement.x >= -movement_limit &&
|
||||
step.movement.x <= movement_limit && step.movement.y >= -movement_limit &&
|
||||
step.movement.y <= movement_limit && !(step.engulf && step.intake_target);
|
||||
step.movement.y <= movement_limit && !(step.engulf && step.intake_target) &&
|
||||
!(step.bud && (step.intake_target || step.engulf));
|
||||
}
|
||||
bool valid_ticks(std::span<const CellularTickIntents> ticks) {
|
||||
std::set<std::uint64_t> identities;
|
||||
@@ -83,7 +84,7 @@ bool valid_action_input(const CellularActionRecord& action, std::uint64_t begin_
|
||||
const auto move_y = std::bit_cast<std::int16_t>(static_cast<std::uint16_t>(get(input, 10, 2)));
|
||||
return !all_zero(action.account) && action.action_id != 0 && tick > begin_tick &&
|
||||
tick <= end_tick && move_x >= -movement_limit && move_x <= movement_limit &&
|
||||
move_y >= -movement_limit && move_y <= movement_limit && input[12] <= 2 &&
|
||||
move_y >= -movement_limit && move_y <= movement_limit && input[12] <= 3 &&
|
||||
all_zero(input.subspan(13, 3)) && (input[12] == 1 || all_zero(input.subspan(16, 8)));
|
||||
}
|
||||
bool action_less(const CellularActionRecord& a, const CellularActionRecord& b) {
|
||||
@@ -137,7 +138,10 @@ void put_intent(std::vector<std::uint8_t>& out, const CellularLifeIntent& life)
|
||||
put(out, life.life_id, 8);
|
||||
put(out, static_cast<std::uint16_t>(life.intent.movement.x), 2);
|
||||
put(out, static_cast<std::uint16_t>(life.intent.movement.y), 2);
|
||||
out.push_back(life.intent.intake_target ? 1 : life.intent.engulf ? 2 : 0); // Target kind.
|
||||
out.push_back(life.intent.intake_target ? 1 // Target kind.
|
||||
: life.intent.engulf ? 2
|
||||
: life.intent.bud ? 3
|
||||
: 0);
|
||||
put(out, 0, 3);
|
||||
put(out, life.intent.intake_target ? life.intent.intake_target->x_um : 0, 4);
|
||||
put(out, life.intent.intake_target ? life.intent.intake_target->y_um : 0, 4);
|
||||
@@ -287,7 +291,7 @@ decode_cellular_batch(std::span<const std::uint8_t> bytes) {
|
||||
step.lives.reserve(static_cast<std::size_t>(count));
|
||||
for (std::uint64_t i = 0; i < count; ++i) {
|
||||
const auto record = bytes.subspan(offset, cellular_batch_intent_bytes);
|
||||
if (record[12] > 2 || !all_zero(record.subspan(13, 3)))
|
||||
if (record[12] > 3 || !all_zero(record.subspan(13, 3)))
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
CellularLifeIntent life;
|
||||
life.life_id = get(record, 0, 8);
|
||||
@@ -303,6 +307,7 @@ decode_cellular_batch(std::span<const std::uint8_t> bytes) {
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
}
|
||||
life.intent.engulf = record[12] == 2; // ADR-0124 target kind.
|
||||
life.intent.bud = record[12] == 3; // ADR-0125.
|
||||
if (!valid_intent(life) ||
|
||||
(!step.lives.empty() && step.lives.back().life_id >= life.life_id))
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
@@ -546,7 +551,8 @@ match_cellular_actions_to_trace(const CellularLives& predecessor, const Cellular
|
||||
std::bit_cast<std::int16_t>(static_cast<std::uint16_t>(get(input, 8, 2))) ||
|
||||
intent->intent.movement.y !=
|
||||
std::bit_cast<std::int16_t>(static_cast<std::uint16_t>(get(input, 10, 2))) ||
|
||||
intent->intent.intake_target != target || intent->intent.engulf != (input[12] == 2))
|
||||
intent->intent.intake_target != target || intent->intent.engulf != (input[12] == 2) ||
|
||||
intent->intent.bud != (input[12] == 3))
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
}
|
||||
return {};
|
||||
|
||||
@@ -238,8 +238,8 @@ validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
|
||||
identity - first < next_bud_sequence - 1;
|
||||
};
|
||||
const auto lineage_valid = [&](std::uint64_t life_id, std::uint64_t parent) noexcept {
|
||||
if (parent == 0)
|
||||
return life_id < cellular_bud_namespace;
|
||||
if (parent == 0) // Rules 4 keep allocated identities below the bud namespace.
|
||||
return !bud_rules || life_id < cellular_bud_namespace;
|
||||
return bud_identity(life_id) && parent != life_id;
|
||||
};
|
||||
const auto& map = habitat.config();
|
||||
@@ -1142,7 +1142,8 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
const bool bud_rules = state_->rules_version == cellular_lives_bud_rules;
|
||||
for (const auto& ordered_intent : ordered) {
|
||||
const auto& intent = ordered_intent.intent;
|
||||
if (intent.bud && (!bud_rules || intent.intake_target || intent.engulf))
|
||||
// Below rules 4 a bud is ignored, as engulfment is below rules 3 (ADR-0124/0125).
|
||||
if (intent.bud && (intent.intake_target || intent.engulf))
|
||||
return std::unexpected{CellularLivesError::invalid_intents};
|
||||
}
|
||||
for (std::size_t i = 0; i < selections.size(); ++i) {
|
||||
@@ -1328,7 +1329,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
std::vector<CellularBudExecution> bud_results;
|
||||
auto next_bud_sequence = state_->next_bud_sequence;
|
||||
for (const auto& request : ordered) {
|
||||
if (!request.intent.bud)
|
||||
if (!bud_rules || !request.intent.bud)
|
||||
continue;
|
||||
const auto parent = std::ranges::lower_bound(
|
||||
next_lives, request.life_id, {},
|
||||
|
||||
@@ -74,6 +74,8 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
|
||||
: std::nullopt;
|
||||
// ADR-0124: a rules-2 region reports the intent unsupported and ignores it.
|
||||
owned_intent->intent.engulf = input->engulf;
|
||||
// ADR-0125: below rules 4 the owner ignores a bud intent.
|
||||
owned_intent->intent.bud = input->bud;
|
||||
CellularActionRecord record;
|
||||
record.account = action.account.bytes;
|
||||
record.action_id = action.action_id;
|
||||
@@ -107,9 +109,10 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
|
||||
const auto life =
|
||||
std::ranges::find(state.lives(), reservation.account, &CellularOwnedLife::account);
|
||||
if (life == state.lives().end() || life->identity.life != life_id ||
|
||||
life->mutation.event_index != event_index || life->mutation.offer_tick != offer_tick ||
|
||||
!life->mutation.offer ||
|
||||
!std::ranges::any_of(life->mutation.offer->candidates, [&](const auto& candidate) {
|
||||
life->mutation.event_index != event_index || life->mutation.offer_tick != offer_tick)
|
||||
return std::unexpected{CellularSessionBatchError::mutation};
|
||||
const auto& offer = life->mutation.offer;
|
||||
if (!offer || !std::ranges::any_of(offer->candidates, [&](const auto& candidate) {
|
||||
return candidate.operator_id == operator_id;
|
||||
}))
|
||||
return std::unexpected{CellularSessionBatchError::mutation};
|
||||
|
||||
@@ -116,6 +116,38 @@ void v7_reliable_action_is_stable_and_strict() {
|
||||
CHECK(!decode_cellular_action_input(malformed_input));
|
||||
}
|
||||
|
||||
// ADR-0125: target kind 3 (bud) exists only on v10, without coordinates, exclusive with
|
||||
// a patch target and with engulfment.
|
||||
void v10_bud_action_is_versioned_and_exclusive() {
|
||||
CellularAction bud{17, 23, 29, 31, 0, 0, false, 0, 0};
|
||||
bud.bud = true;
|
||||
const auto bytes = encode_session(SessionMessage{bud}, session_protocol_v10);
|
||||
CHECK(bytes.size() == session_header_bytes + 48 && bytes[session_header_bytes + 36] == 3);
|
||||
const auto decoded = decode_session(bytes);
|
||||
CHECK(decoded && std::get<CellularAction>(*decoded) == bud);
|
||||
CHECK(encode_session(SessionMessage{bud}, session_protocol_v9).empty());
|
||||
CHECK(encode_session(SessionMessage{bud}).empty());
|
||||
auto feeding = bud;
|
||||
feeding.has_intake_target = true;
|
||||
CHECK(encode_session(SessionMessage{feeding}, session_protocol_v10).empty());
|
||||
auto engulfing = bud;
|
||||
engulfing.engulf = true;
|
||||
CHECK(encode_session(SessionMessage{engulfing}, session_protocol_v10).empty());
|
||||
auto as_v9 = bytes;
|
||||
as_v9[4] = static_cast<std::uint8_t>(session_protocol_v9);
|
||||
CHECK(!decode_session(as_v9));
|
||||
auto kind_four = bytes;
|
||||
kind_four[session_header_bytes + 36] = 4;
|
||||
CHECK(!decode_session(kind_four));
|
||||
|
||||
CellularActionInput input{31, 0, 0, false, 0, 0, false, true};
|
||||
const auto canonical = encode_cellular_action_input(input);
|
||||
CHECK(canonical[12] == 3 && decode_cellular_action_input(canonical) == input);
|
||||
auto placed = canonical;
|
||||
placed[16] = 1;
|
||||
CHECK(!decode_cellular_action_input(placed));
|
||||
}
|
||||
|
||||
// ADR-0124: target kind 2 (engulf) exists only on v10, without coordinates or a patch.
|
||||
void v10_engulf_action_is_versioned_and_exclusive() {
|
||||
CellularAction engulf{17, 23, 29, 31, 5, -5, false, 0, 0};
|
||||
@@ -151,7 +183,7 @@ void v10_engulf_action_is_versioned_and_exclusive() {
|
||||
coordinated[16] = 1;
|
||||
CHECK(!decode_cellular_action_input(coordinated));
|
||||
auto unknown_kind = canonical;
|
||||
unknown_kind[12] = 3;
|
||||
unknown_kind[12] = 4; // Kind 3 is a bud since ADR-0125.
|
||||
CHECK(!decode_cellular_action_input(unknown_kind));
|
||||
}
|
||||
|
||||
@@ -300,6 +332,7 @@ int main() {
|
||||
malformed_frames_are_refused();
|
||||
v7_reliable_action_is_stable_and_strict();
|
||||
v10_engulf_action_is_versioned_and_exclusive();
|
||||
v10_bud_action_is_versioned_and_exclusive();
|
||||
v8_perception_is_bounded_and_canonical();
|
||||
v9_perception_carries_only_valid_owner_diagnostics();
|
||||
v10_mutation_choice_is_a_strict_reliable_action();
|
||||
|
||||
@@ -587,11 +587,12 @@ void rules_three_owner_resolves_engulf_and_detritus() {
|
||||
both.intake_target = evo::biology::CellularPatchAddress{0, 0};
|
||||
const std::array conflicting{CellularLifeIntent{1, both}, CellularLifeIntent{2, {}}};
|
||||
CHECK(!owner.advance_tick(conflicting) && owner.tick() == 2);
|
||||
// Budding needs rules 4.
|
||||
// Below rules 4 a bud intent is ignored: the tick advances and nothing buds.
|
||||
evo::biology::CellularStepIntent bud{};
|
||||
bud.bud = true;
|
||||
CHECK(owner.advance_tick(std::array{CellularLifeIntent{1, bud}, CellularLifeIntent{2, {}}})
|
||||
.error() == CellularLivesError::invalid_intents);
|
||||
CHECK(owner.advance_tick(std::array{CellularLifeIntent{1, bud}, CellularLifeIntent{2, {}}}));
|
||||
CHECK(owner.lives().size() == 2 && !owner.last_tick_feedback()[0].bud &&
|
||||
owner.current_total() == owner.opening_total());
|
||||
|
||||
const auto patch_before = owner.habitat().patches()[0].stock;
|
||||
std::size_t steps{};
|
||||
@@ -661,7 +662,7 @@ void rules_four_owner_buds_wildlife() {
|
||||
feed.intake_target = evo::biology::CellularPatchAddress{0, 0};
|
||||
evo::biology::CellularStepIntent bud{};
|
||||
bud.bud = true;
|
||||
// A bud is exclusive with feeding, and needs rules 4 (checked in the rules 3 test).
|
||||
// A bud is exclusive with feeding; below rules 4 it is ignored (the rules 3 test).
|
||||
auto feeding_bud = feed;
|
||||
feeding_bud.bud = true;
|
||||
CHECK(owner.advance_tick(std::array{CellularLifeIntent{1, feeding_bud}}).error() ==
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "evo/server/cellular_region_host.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <optional>
|
||||
#include <source_location>
|
||||
@@ -48,6 +49,14 @@ template <std::size_t N> std::array<std::uint8_t, N> filled(std::uint8_t value)
|
||||
out.fill(value);
|
||||
return out;
|
||||
}
|
||||
// Commit ids are unique across the whole store; other suites use uniform-byte ids, so
|
||||
// these mix bytes.
|
||||
Uuid distinct_commit(std::uint8_t tag) {
|
||||
auto id = filled<16>(0xC3);
|
||||
id[1] = 0x5E;
|
||||
id[15] = tag;
|
||||
return id;
|
||||
}
|
||||
std::string hex(std::span<const std::uint8_t> bytes) {
|
||||
constexpr char digits[] = "0123456789abcdef";
|
||||
std::string out = "\\x";
|
||||
@@ -345,8 +354,8 @@ void cellular_mutation_publication_binds_results() {
|
||||
CHECK(opening);
|
||||
auto objects = FilesystemObjectStore::open(env("PGHOST"), key, max_cellular_lives_bytes);
|
||||
CHECK(objects);
|
||||
CHECK(provision_cellular_region(*owner, **objects, key, 1, **opening, filled<16>(0x60), build,
|
||||
5s));
|
||||
CHECK(provision_cellular_region(*owner, **objects, key, 1, **opening, distinct_commit(0x9A),
|
||||
build, 5s));
|
||||
CHECK(owner->query("INSERT INTO evolution.life_allocators VALUES(9764,1000) "
|
||||
"ON CONFLICT DO NOTHING",
|
||||
{}, 5s));
|
||||
@@ -430,10 +439,10 @@ void cellular_mutation_publication_binds_results() {
|
||||
// Publishing without the mutation block is refused: only the block binds the choice.
|
||||
CHECK(!publish_cellular_batch(*runtime, **mutation_objects, authority,
|
||||
checked_value(host->committed()), mutation, **candidate,
|
||||
filled<16>(0x65), build, 5s));
|
||||
distinct_commit(0x9B), build, 5s));
|
||||
const auto published = publish_cellular_batch(
|
||||
*runtime, **mutation_objects, authority, checked_value(host->committed()), mutation,
|
||||
**candidate, filled<16>(0x65), build, 5s, {}, {}, choices);
|
||||
**candidate, distinct_commit(0x9B), build, 5s, {}, {}, choices);
|
||||
CHECK(published && published->mutation_results.size() == 1);
|
||||
const auto result = published->mutation_results.front();
|
||||
// Applied exactly when the replayed life now carries the reserved successor genome.
|
||||
@@ -498,8 +507,8 @@ void cellular_host_admits_mutation_choices() {
|
||||
CHECK(opening);
|
||||
auto objects = FilesystemObjectStore::open(env("PGHOST"), key, max_cellular_lives_bytes);
|
||||
CHECK(objects);
|
||||
CHECK(provision_cellular_region(*owner, **objects, key, 1, **opening, filled<16>(0x70), build,
|
||||
5s));
|
||||
CHECK(provision_cellular_region(*owner, **objects, key, 1, **opening, distinct_commit(0x9C),
|
||||
build, 5s));
|
||||
CHECK(owner->query("INSERT INTO evolution.life_allocators VALUES(9765,1000) "
|
||||
"ON CONFLICT DO NOTHING",
|
||||
{}, 5s));
|
||||
@@ -627,6 +636,112 @@ void cellular_host_admits_mutation_choices() {
|
||||
CHECK(admit_status(final_repeat.status) == evo::network::AdmitStatus::duplicate);
|
||||
host->drain();
|
||||
}
|
||||
|
||||
// ADR-0125 (schema v36): a rules-4 region publishes a bud with its tick; the wildlife
|
||||
// descendant, its identity and the parent's debit recover after a restart.
|
||||
void cellular_bud_publishes_and_recovers() {
|
||||
using namespace evo::biology;
|
||||
constexpr RegionKey key{9767, 1};
|
||||
auto owner = connect_as(env("PGUSER"));
|
||||
auto runtime = connect_as(env("EVO_PG_RUNTIME_USER"));
|
||||
const auto build = filled<32>(0xDB);
|
||||
CHECK(owner->query("INSERT INTO evolution.retained_builds(build_identity) VALUES "
|
||||
"(decode(repeat('db',32),'hex')) ON CONFLICT DO NOTHING",
|
||||
{}, 5s));
|
||||
auto endowed = primitive_endowment();
|
||||
CHECK(endowed);
|
||||
auto funding = endowed->body;
|
||||
funding.energy.value = endowed->reserve.energy.value + endowed->construction.value;
|
||||
auto primitive = PrimitiveLives::create({key.world, key.region, 1, 17, funding, {{0, 0}}});
|
||||
CHECK(primitive);
|
||||
constexpr std::uint64_t stock = 10'000'000'000;
|
||||
auto habitat = CellularHabitat::create(
|
||||
{key.world,
|
||||
key.region,
|
||||
1,
|
||||
3'000,
|
||||
2'000,
|
||||
{{{0, 0}, 29, {{stock}, {{{stock}, {stock}, {stock}, {stock}}}}}}});
|
||||
CHECK(habitat);
|
||||
auto opening =
|
||||
CellularLives::create(**primitive, std::move(*habitat), {{3'000, 2'000}, 0, 293'150},
|
||||
CellularLivesProfile::budding);
|
||||
CHECK(opening);
|
||||
auto objects = FilesystemObjectStore::open(env("PGHOST"), key, max_cellular_lives_bytes);
|
||||
CHECK(objects);
|
||||
CHECK(provision_cellular_region(*owner, **objects, key, 1, **opening, distinct_commit(0x9D),
|
||||
build, 5s));
|
||||
CHECK(owner->query("INSERT INTO evolution.life_allocators VALUES(9767,1000) "
|
||||
"ON CONFLICT DO NOTHING",
|
||||
{}, 5s));
|
||||
const auto connect = [&]() -> std::expected<std::unique_ptr<Postgres>, PgFailure> {
|
||||
return Postgres::connect({env("PGHOST"),
|
||||
{},
|
||||
env("PGPORT"),
|
||||
env("PGDATABASE"),
|
||||
env("EVO_PG_RUNTIME_USER"),
|
||||
{},
|
||||
{}},
|
||||
5s);
|
||||
};
|
||||
CellularHostConfig config{key, 1, {}, build, {build}};
|
||||
auto made = CellularRegionHost::create(config, connect, std::move(*objects));
|
||||
CHECK(made);
|
||||
auto host = std::move(*made);
|
||||
CHECK(host->step().ready);
|
||||
const auto account = filled<16>(0x84);
|
||||
const auto control = claim_account_control(*runtime, key, checked_value(host->authority()),
|
||||
account, 1, 1, 60'000ms, 5s);
|
||||
CHECK(control);
|
||||
CHECK(host->create_primitive_life(account, control->generation, 11).result ==
|
||||
evo::network::PrimitiveLifeResult::pending);
|
||||
const auto header = [&](std::uint64_t ticks) {
|
||||
const auto& committed = checked_value(host->committed());
|
||||
const auto digest = sha256(committed.manifest);
|
||||
CHECK(digest);
|
||||
return CellularBatchHeader{key.world,
|
||||
key.region,
|
||||
1,
|
||||
committed.head.commit,
|
||||
checked_value(digest),
|
||||
host->state()->tick(),
|
||||
host->state()->tick() + ticks};
|
||||
};
|
||||
CellularBatch birth;
|
||||
birth.header = header(1);
|
||||
birth.ticks.push_back({{}, {host->queued_births().front()}, {}});
|
||||
CHECK(host->publish(birth));
|
||||
const auto parent = host->state()->lives().front().identity.life;
|
||||
CellularStepIntent feed{};
|
||||
feed.intake_target = CellularPatchAddress{0, 0};
|
||||
CellularStepIntent bud{};
|
||||
bud.bud = true;
|
||||
// Feed for 63 ticks, then ask to bud on the batch's last tick, until it buds.
|
||||
for (int round = 0; round < 200 && host->state()->lives().size() == 1; ++round) {
|
||||
CHECK(host->step().ready);
|
||||
CellularBatch batch;
|
||||
batch.header = header(64);
|
||||
for (int tick = 0; tick < 63; ++tick)
|
||||
batch.ticks.push_back({{{parent, feed}}, {}, {}});
|
||||
batch.ticks.push_back({{{parent, bud}}, {}, {}});
|
||||
CHECK(host->publish(batch));
|
||||
}
|
||||
CHECK(host->state()->lives().size() == 2);
|
||||
const auto expected_bud = cellular_bud_identity(key.region, 1);
|
||||
const auto& wildlife = host->state()->lives()[1];
|
||||
CHECK(wildlife.identity.life == expected_bud && wildlife.parent_life == parent &&
|
||||
wildlife.account == LifeAccount{} && host->state()->next_bud_sequence() == 2);
|
||||
const auto snapshot = host->state()->snapshot();
|
||||
host->drain();
|
||||
host.reset();
|
||||
|
||||
auto reopened = FilesystemObjectStore::open(env("PGHOST"), key, max_cellular_lives_bytes);
|
||||
CHECK(reopened);
|
||||
auto restarted = CellularRegionHost::create(config, connect, std::move(*reopened));
|
||||
CHECK(restarted);
|
||||
CHECK((*restarted)->step().ready && (*restarted)->state()->snapshot() == snapshot);
|
||||
(*restarted)->drain();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void run_cellular_publication_tests() {
|
||||
@@ -634,6 +749,7 @@ void run_cellular_publication_tests() {
|
||||
cellular_profile_migration_is_durable_and_recovers_without_a_tick();
|
||||
cellular_mutation_publication_binds_results();
|
||||
cellular_host_admits_mutation_choices();
|
||||
cellular_bud_publishes_and_recovers();
|
||||
auto owner = connect_as(env("PGUSER"));
|
||||
const auto build = filled<32>(0xD9);
|
||||
CHECK(owner->query("INSERT INTO evolution.retained_builds(build_identity) VALUES "
|
||||
|
||||
@@ -102,6 +102,26 @@ void actions_bind_to_owned_life_and_preserve_other_inputs() {
|
||||
stripped.ticks[0].lives[0].intent.engulf = false;
|
||||
CHECK(!match_cellular_actions_to_trace(**state, stripped, engulfing->actions));
|
||||
|
||||
// ADR-0125: a bud action becomes the life's bud intent, kept as kind 3 in the trace.
|
||||
const auto bud_input =
|
||||
network::encode_cellular_action_input({2, 0, 0, false, 0, 0, false, true});
|
||||
const network::CarriedAction bud_action{network::AccountId{controlled.account}, 80, 2,
|
||||
network::ActionKind::cellular, bud_input};
|
||||
const std::array bud_actions{bud_action};
|
||||
const auto budding = prepare_cellular_session_tick(**state, 2, baseline, bud_actions);
|
||||
CHECK(budding && budding->intents.lives[0].intent.bud &&
|
||||
!budding->intents.lives[0].intent.engulf &&
|
||||
!budding->intents.lives[0].intent.intake_target);
|
||||
auto bud_batch = engulf_batch;
|
||||
bud_batch.ticks[0] = budding->intents;
|
||||
CHECK(match_cellular_actions_to_trace(**state, bud_batch, budding->actions));
|
||||
const auto bud_bytes = encode_cellular_batch(bud_batch);
|
||||
CHECK(bud_bytes);
|
||||
const auto bud_decoded = decode_cellular_batch(*bud_bytes);
|
||||
CHECK(bud_decoded && *bud_decoded == bud_batch);
|
||||
auto unbudded = bud_batch;
|
||||
unbudded.ticks[0].lives[0].intent.bud = false;
|
||||
CHECK(!match_cellular_actions_to_trace(**state, unbudded, budding->actions));
|
||||
CellularBatch batch;
|
||||
batch.header = {(*state)->world(), (*state)->region(), (*state)->frame(), {}, {}, 1, 2};
|
||||
batch.header.predecessor.fill(1);
|
||||
|
||||
@@ -533,6 +533,28 @@ void cellular_profile() {
|
||||
engulf_payload.size(), filled<32>(0x34), batch_for(1, 1));
|
||||
CHECK(v4_next && supported(*v4_next) && v4_next->cellular_versions == cellular_v4_versions);
|
||||
|
||||
// ADR-0125: a rules-4 owner restores only under the v5 bundle and revision history.
|
||||
auto bud_primitive = PrimitiveLives::create({7, 3, 9, 17, funding, {{0, 0}}});
|
||||
auto bud_habitat = CellularHabitat::create({7, 3, 9, 1'000, 1'000, {}});
|
||||
CHECK(bud_primitive && bud_habitat);
|
||||
auto bud_owner =
|
||||
CellularLives::create(**bud_primitive, std::move(*bud_habitat),
|
||||
{{1'000, 1'000}, 0, 293'150}, CellularLivesProfile::budding);
|
||||
CHECK(bud_owner);
|
||||
const auto bud_payload = (*bud_owner)->snapshot();
|
||||
auto v5 = genesis_manifest(key, 9, filled<16>(0x35), 50000, build, bud_payload.size(),
|
||||
filled<32>(0x36), CheckpointProfile::cellular_lives_v1);
|
||||
CHECK(v5);
|
||||
v5->cellular_versions = cellular_v5_versions;
|
||||
v5->history_profile = cellular_revision_history_profile;
|
||||
CHECK(supported(*v5) && cellular_revision_bundle(v5->cellular_versions));
|
||||
const auto v5_bytes = encode_manifest(*v5);
|
||||
CHECK(v5_bytes && decode_manifest(*v5_bytes) == *v5);
|
||||
CHECK(restore_cellular_payload(bud_payload, *v5));
|
||||
auto bud_as_v4 = *v5;
|
||||
bud_as_v4.cellular_versions = cellular_v4_versions;
|
||||
CHECK(!restore_cellular_payload(bud_payload, bud_as_v4));
|
||||
CHECK(!restore_cellular_payload(engulf_payload, *v5));
|
||||
auto bad_identity = *manifest;
|
||||
bad_identity.key.region = 4;
|
||||
const auto wrong_identity = restore_cellular_payload(payload, bad_identity);
|
||||
|
||||
@@ -212,7 +212,7 @@ void upgrade_across_migration_and_barrier() {
|
||||
" EVO_PG_RUNTIME_ROLE=evo_runtime_test bash \"$EVO_SOURCE_ROOT/"
|
||||
"tools/migrate-postgres.sh\" > /dev/null") == 0);
|
||||
CHECK(history(*owner_db) == "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
|
||||
"25,26,27,28,29,30,31,32,33,34,35");
|
||||
"25,26,27,28,29,30,31,32,33,34,35,36");
|
||||
CHECK(scalar(*owner_db, "SELECT (c.condeferrable AND c.condeferred AND "
|
||||
"c.confrelid = 'evolution.region_commits'::regclass)::text "
|
||||
"FROM pg_catalog.pg_constraint c WHERE c.conrelid = "
|
||||
@@ -242,7 +242,8 @@ void upgrade_across_migration_and_barrier() {
|
||||
"repeat('00', 23), 'hex'), 1)::text") == "true");
|
||||
CHECK(scalar(*owner_db, "SELECT evolution.valid_cellular_action_input(decode(repeat('00', 24), "
|
||||
"'hex'), 1)::text") == "false");
|
||||
// Schema v34 (ADR-0124): target kind 2 is engulf, with no coordinates; kind 3 is unknown.
|
||||
// Schema v34 (ADR-0124): target kind 2 is engulf, with no coordinates. Schema v36
|
||||
// (ADR-0125): kind 3 is a bud, with no coordinates; kind 4 is unknown.
|
||||
CHECK(scalar(*owner_db,
|
||||
"SELECT evolution.valid_cellular_action_input(decode('01' || "
|
||||
"repeat('00', 11) || '02' || repeat('00', 11), 'hex'), 1)::text") == "true");
|
||||
@@ -251,7 +252,13 @@ void upgrade_across_migration_and_barrier() {
|
||||
"repeat('00', 7), 'hex'), 1)::text") == "false");
|
||||
CHECK(scalar(*owner_db,
|
||||
"SELECT evolution.valid_cellular_action_input(decode('01' || "
|
||||
"repeat('00', 11) || '03' || repeat('00', 11), 'hex'), 1)::text") == "false");
|
||||
"repeat('00', 11) || '03' || repeat('00', 11), 'hex'), 1)::text") == "true");
|
||||
CHECK(scalar(*owner_db, "SELECT evolution.valid_cellular_action_input(decode('01' || "
|
||||
"repeat('00', 11) || '03' || repeat('00', 3) || '01' || "
|
||||
"repeat('00', 7), 'hex'), 1)::text") == "false");
|
||||
CHECK(scalar(*owner_db,
|
||||
"SELECT evolution.valid_cellular_action_input(decode('01' || "
|
||||
"repeat('00', 11) || '04' || repeat('00', 11), 'hex'), 1)::text") == "false");
|
||||
CHECK(scalar(*owner_db,
|
||||
"SELECT evolution.check_cellular_action_block(decode(repeat('01', 16) || "
|
||||
"'0100000000000000' || '0100000000000000' || repeat('00', 16), 'hex'), "
|
||||
|
||||
@@ -514,6 +514,27 @@ void cellular_v2_provisioning_uses_the_engulf_bundle() {
|
||||
manifest->history_profile == cellular_revision_history_profile);
|
||||
}
|
||||
|
||||
// ADR-0125: cellular-v3 is the rules-4 budding opening on the v5 bundle.
|
||||
void cellular_v3_provisioning_uses_the_budding_bundle() {
|
||||
const ServerRegion r{{9766, 1}, fresh("cellular-v3-provision-9766")};
|
||||
const std::string build(64, 'e');
|
||||
const std::string commit(32, 'b');
|
||||
const std::string patch = "3000,3000,2,1000,1000,1000,1000,1000";
|
||||
int code = -1;
|
||||
const auto first = provision_cellular(r, "9766", "cellular-v3", build, commit, patch, code);
|
||||
CHECK(code == 0 && has(first, "provisioned world=9766 region=1 sequence=0 tick=0"));
|
||||
const auto again = provision_cellular(r, "9766", "cellular-v3", build, commit, patch, code);
|
||||
CHECK(code == 0 && has(again, "already-provisioned world=9766 region=1 sequence=0 tick=0"));
|
||||
const auto older = provision_cellular(r, "9766", "cellular-v2", build, commit, patch, code);
|
||||
CHECK(code == 4);
|
||||
auto db = owner();
|
||||
const auto head = load_region_checkpoint(*db, r.key, 5s);
|
||||
CHECK(head);
|
||||
const auto manifest = decode_manifest(head->manifest);
|
||||
CHECK(manifest && manifest->cellular_versions == cellular_v5_versions &&
|
||||
manifest->history_profile == cellular_revision_history_profile);
|
||||
}
|
||||
|
||||
void cellular_provisioning_survives_a_build_promotion() {
|
||||
const ServerRegion r{{9761, 1}, fresh("cellular-provision-9761")};
|
||||
const auto run = [&](const std::string& build, const std::string& commit,
|
||||
@@ -545,6 +566,7 @@ void run_region_store_tests() {
|
||||
provisioning_creates_the_life_allocator_once();
|
||||
cellular_provisioning_survives_a_build_promotion();
|
||||
cellular_v2_provisioning_uses_the_engulf_bundle();
|
||||
cellular_v3_provisioning_uses_the_budding_bundle();
|
||||
full_volumes_publish_nothing();
|
||||
failing_writes_leave_nothing();
|
||||
check_store_qualifies_the_stores();
|
||||
|
||||
@@ -122,7 +122,7 @@ PGDATABASE=upgrade_path psql -X -v ON_ERROR_STOP=1 -1 -v "migration_sha=$v1_sha"
|
||||
-f "$root/migrations/0001_region_bootstrap.sql" > /dev/null
|
||||
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',') FROM evolution.schema_migrations")" = 1
|
||||
PGDATABASE=upgrade_path bash "$root/tools/migrate-postgres.sh"
|
||||
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35
|
||||
test "$(PGDATABASE=upgrade_path psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36
|
||||
# v2 heads have no payload binding: v2->v3 fails closed and leaves history at v2.
|
||||
v2_sha="$(sha256sum "$root/migrations/0002_region_fencing.sql")"
|
||||
v2_sha="${v2_sha%% *}"
|
||||
@@ -143,7 +143,7 @@ PGDATABASE=v3_commits psql -X -v ON_ERROR_STOP=1 \
|
||||
-c "INSERT INTO evolution.retained_builds VALUES (decode(repeat('b1', 32), 'hex'))" \
|
||||
-c "SELECT evolution.provision_region_checkpoint(decode('4145564f52434d31' || '01000000' || '01000000' || '0100000000000000' || '0100000000000000' || '0900000000000000' || repeat('11', 16) || repeat('00', 8) || repeat('00', 16) || repeat('00', 32) || repeat('00', 16) || repeat('00', 16) || repeat('00', 8) || '50c3000000000000' || '020000000200000001000000010000000100000001000000010000000100000001000000' || repeat('b1', 32) || '00000000' || '00000000' || '01000000' || '6400000000000000' || repeat('a0', 32), 'hex'))" > /dev/null
|
||||
PGDATABASE=v3_commits bash "$root/tools/migrate-postgres.sh"
|
||||
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) || ':' || string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 35:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35
|
||||
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) || ':' || string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 36:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36
|
||||
test "$(PGDATABASE=v3_commits psql -XAtc "SELECT count(*) FROM evolution.region_commits")" = 1
|
||||
# Review P1: a v4 database holding a published (possibly terminal) checkpoint has
|
||||
# no durable decisions for it. The v5 upgrade must refuse before changing anything.
|
||||
@@ -197,7 +197,7 @@ PGDATABASE=v6_populated psql -X -v ON_ERROR_STOP=1 \
|
||||
-c "INSERT INTO evolution.retained_builds VALUES (decode(repeat('b1', 32), 'hex'))" \
|
||||
-c "SELECT evolution.provision_region_checkpoint(decode('4145564f52434d31' || '02000000' || '01000000' || '0100000000000000' || '0100000000000000' || '0900000000000000' || repeat('11', 16) || repeat('00', 8) || repeat('00', 16) || repeat('00', 32) || repeat('00', 16) || repeat('00', 16) || repeat('00', 8) || '50c3000000000000' || '020000000200000001000000010000000100000001000000010000000100000001000000' || repeat('b1', 32) || '00000000' || '00000000' || '01000000' || '6400000000000000' || repeat('a0', 32) || repeat('00', 80), 'hex'))" > /dev/null
|
||||
PGDATABASE=v6_populated bash "$root/tools/migrate-postgres.sh"
|
||||
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35
|
||||
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(version::text, ',' ORDER BY version) FROM evolution.schema_migrations")" = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36
|
||||
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT count(*) FROM evolution.region_commits c, LATERAL evolution.parse_checkpoint_manifest(c.manifest) m WHERE m.commit_sequence = 0 AND m.predecessor_commit IS NULL")" = 1
|
||||
test "$(PGDATABASE=v6_populated psql -XAtc "SELECT string_agg(conname, ',') FROM pg_constraint WHERE conrelid = 'evolution.region_heads'::regclass AND contype = 'c' AND pg_get_constraintdef(oid) LIKE '%end_tick%'")" = region_heads_published_tick
|
||||
phase permission-audit
|
||||
@@ -250,9 +250,9 @@ expect_audit_failure 'REVOKE EXECUTE ON FUNCTION evolution.claim_account_control
|
||||
bash "$root/tools/migrate-postgres.sh" # Restored configuration passes the audit again.
|
||||
phase checksum-drift
|
||||
# Unknown future versions and checksum drift must not be repaired silently.
|
||||
psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=36 WHERE version=35'
|
||||
psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=37 WHERE version=36'
|
||||
if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi
|
||||
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=35 WHERE version=36"
|
||||
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=36 WHERE version=37"
|
||||
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET sha256=repeat('0',64) WHERE version=14"
|
||||
if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi
|
||||
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET sha256=repeat('0',64) WHERE version=13"
|
||||
|
||||
@@ -82,6 +82,8 @@ digest_34="$(sha256sum "$root/migrations/0034_cellular_v4_engulf_bundle.sql")"
|
||||
digest_34="${digest_34%% *}"
|
||||
digest_35="$(sha256sum "$root/migrations/0035_cellular_mutation_publication.sql")"
|
||||
digest_35="${digest_35%% *}"
|
||||
digest_36="$(sha256sum "$root/migrations/0036_cellular_v5_budding_bundle.sql")"
|
||||
digest_36="${digest_36%% *}"
|
||||
psql -X --no-password --set=ON_ERROR_STOP=1 --set="migration_sha=$digest" \
|
||||
--set="migration_sha_2=$digest_2" --set="migration_sha_3=$digest_3" \
|
||||
--set="migration_sha_4=$digest_4" --set="migration_sha_5=$digest_5" \
|
||||
@@ -110,5 +112,6 @@ psql -X --no-password --set=ON_ERROR_STOP=1 --set="migration_sha=$digest" \
|
||||
--set="migration_sha_33=$digest_33" \
|
||||
--set="migration_sha_34=$digest_34" \
|
||||
--set="migration_sha_35=$digest_35" \
|
||||
--set="migration_sha_36=$digest_36" \
|
||||
--set="runtime_role=$runtime_role" \
|
||||
--file="$root/migrations/apply.sql"
|
||||
|
||||
Reference in New Issue
Block a user