Foundation / checks (ecs) (push) Successful in 2m41s
Foundation / checks (tsan) (push) Failing after 18m12s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (network) (push) Canceled after 20m41s
Foundation / checks (postgres) (push) Canceled after 20m43s
Foundation / checks (checks) (push) Canceled after 20m49s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (client) (push) Failing after 17m4s
Foundation / postgres-tools (push) Canceled after 0s
339 lines
22 KiB
PL/PgSQL
339 lines
22 KiB
PL/PgSQL
-- ADR-0142: exact population profile 5, immutable evidence and fenced publishers.
|
|
-- All historical profile-4 bytes and parsers retain their original meanings.
|
|
ALTER FUNCTION evolution.parse_checkpoint_manifest(bytea) RENAME TO parse_checkpoint_manifest_v43;
|
|
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;
|
|
n bytea;
|
|
tick_begin numeric;
|
|
tick_end numeric;
|
|
payload_size numeric;
|
|
trace_size numeric;
|
|
trace_digest bytea;
|
|
zero32 constant bytea := decode(repeat('00',32),'hex');
|
|
bundle9 constant bytea := '\x080000000600000002000000010000000100000004000000030000000200000001000000';
|
|
BEGIN
|
|
IF m IS NULL OR octet_length(m) <> 360 OR evolution.manifest_uint(m,12,4) <> 5 THEN
|
|
RETURN evolution.parse_checkpoint_manifest_v43(m);
|
|
END IF;
|
|
tick_begin := evolution.manifest_uint(m,112,8);
|
|
tick_end := evolution.manifest_uint(m,120,8);
|
|
payload_size := evolution.manifest_uint(m,240,8);
|
|
trace_size := evolution.manifest_uint(m,280,8);
|
|
trace_digest := substring(m FROM 289 FOR 32);
|
|
IF substring(m FROM 161 FOR 36) <> bundle9 OR evolution.manifest_uint(m,232,4) <> 5
|
|
OR evolution.manifest_uint(m,228,4) <> 0 OR evolution.manifest_uint(m,236,4) <> 1
|
|
OR evolution.manifest_uint(m,56,8) = 0 OR tick_end < tick_begin OR tick_end - tick_begin > 64
|
|
OR payload_size = 0 OR payload_size > 16781400 OR evolution.manifest_uint(m,320,4) <> 0
|
|
OR substring(m FROM 329 FOR 32) <> zero32
|
|
OR (trace_size = 0 AND (trace_digest <> zero32 OR tick_begin <> tick_end OR tick_end = 0))
|
|
OR (trace_size > 0 AND (trace_size < 152 OR trace_size > 1968376 OR trace_size % 8 <> 0
|
|
OR trace_digest = zero32)) THEN
|
|
RAISE EXCEPTION 'unsupported or malformed population manifest' USING ERRCODE = '22023';
|
|
END IF;
|
|
-- Reuse historical common-field validation, with only parser-local normalized
|
|
-- profile/history/size/trace declarations. Stored and returned bytes stay profile 5.
|
|
n := overlay(m PLACING '\x04000000'::bytea FROM 13 FOR 4);
|
|
n := overlay(n PLACING '\x04000000'::bytea FROM 233 FOR 4);
|
|
n := overlay(n PLACING evolution.manifest_u64le(least(payload_size,16777216)) FROM 241 FOR 8);
|
|
n := overlay(n PLACING evolution.manifest_u64le(CASE WHEN tick_end = tick_begin THEN 0
|
|
ELSE 112 + 16 * (tick_end - tick_begin) END) FROM 281 FOR 8);
|
|
IF tick_end = tick_begin THEN
|
|
n := overlay(n PLACING zero32 FROM 289 FOR 32);
|
|
END IF;
|
|
r := evolution.parse_checkpoint_manifest_v43(n);
|
|
r.profile := 5;
|
|
r.payload_bytes := payload_size;
|
|
r.trace_bytes := trace_size;
|
|
r.trace_sha256 := trace_digest;
|
|
RETURN r;
|
|
END $$;
|
|
REVOKE ALL ON FUNCTION evolution.parse_checkpoint_manifest(bytea) FROM PUBLIC;
|
|
|
|
CREATE TABLE evolution.population_publications (
|
|
commit_id uuid PRIMARY KEY REFERENCES evolution.region_commits(commit_id) DEFERRABLE INITIALLY DEFERRED,
|
|
trace bytea NOT NULL CHECK (octet_length(trace) BETWEEN 152 AND 1968376)
|
|
);
|
|
CREATE TABLE evolution.population_profile_transitions (
|
|
target_commit uuid PRIMARY KEY REFERENCES evolution.region_commits(commit_id) DEFERRABLE INITIALLY DEFERRED,
|
|
source_commit uuid NOT NULL REFERENCES evolution.region_commits(commit_id),
|
|
source_manifest_sha256 bytea NOT NULL CHECK (octet_length(source_manifest_sha256) = 32),
|
|
source_payload_sha256 bytea NOT NULL CHECK (octet_length(source_payload_sha256) = 32),
|
|
source_profile integer NOT NULL CHECK (source_profile IN (4,5)),
|
|
target_profile integer NOT NULL CHECK (target_profile IN (4,5)),
|
|
CHECK (source_profile <> target_profile AND source_commit <> target_commit)
|
|
);
|
|
REVOKE ALL ON evolution.population_publications, evolution.population_profile_transitions FROM PUBLIC;
|
|
CREATE TRIGGER population_publications_immutable BEFORE UPDATE OR DELETE ON evolution.population_publications
|
|
FOR EACH ROW EXECUTE FUNCTION evolution.refuse_history_rewrite();
|
|
CREATE TRIGGER population_publications_no_truncate BEFORE TRUNCATE ON evolution.population_publications
|
|
FOR EACH STATEMENT EXECUTE FUNCTION evolution.refuse_history_rewrite();
|
|
CREATE TRIGGER population_transitions_immutable BEFORE UPDATE OR DELETE ON evolution.population_profile_transitions
|
|
FOR EACH ROW EXECUTE FUNCTION evolution.refuse_history_rewrite();
|
|
CREATE TRIGGER population_transitions_no_truncate BEFORE TRUNCATE ON evolution.population_profile_transitions
|
|
FOR EACH STATEMENT EXECUTE FUNCTION evolution.refuse_history_rewrite();
|
|
|
|
CREATE OR REPLACE FUNCTION evolution.refuse_unpublished_cellular() RETURNS trigger
|
|
LANGUAGE plpgsql SECURITY INVOKER SET search_path = pg_catalog, pg_temp AS $$
|
|
BEGIN
|
|
IF evolution.manifest_uint(NEW.manifest,12,4) = 4 AND NEW.commit_sequence > 0
|
|
AND NOT EXISTS (SELECT 1 FROM evolution.cellular_publications p WHERE p.commit_id = NEW.commit_id)
|
|
AND NOT EXISTS (SELECT 1 FROM evolution.cellular_profile_migrations p WHERE p.target_commit = NEW.commit_id)
|
|
AND NOT EXISTS (SELECT 1 FROM evolution.population_profile_transitions p
|
|
WHERE p.target_commit = NEW.commit_id AND p.target_profile = 4) THEN
|
|
RAISE EXCEPTION 'cellular commit requires fenced publisher' USING ERRCODE = 'EVL06';
|
|
END IF;
|
|
RETURN NEW;
|
|
END $$;
|
|
CREATE FUNCTION evolution.refuse_unpublished_population() RETURNS trigger
|
|
LANGUAGE plpgsql SECURITY INVOKER SET search_path = pg_catalog, pg_temp AS $$
|
|
BEGIN
|
|
IF evolution.manifest_uint(NEW.manifest,12,4) = 5 AND
|
|
(NEW.commit_sequence = 0 OR
|
|
(NOT EXISTS (SELECT 1 FROM evolution.population_publications p WHERE p.commit_id = NEW.commit_id)
|
|
AND NOT EXISTS (SELECT 1 FROM evolution.population_profile_transitions p
|
|
WHERE p.target_commit = NEW.commit_id AND p.target_profile = 5))) THEN
|
|
RAISE EXCEPTION 'population commit requires fenced publisher' USING ERRCODE = 'EVL06';
|
|
END IF;
|
|
RETURN NEW;
|
|
END $$;
|
|
REVOKE ALL ON FUNCTION evolution.refuse_unpublished_population() FROM PUBLIC;
|
|
CREATE TRIGGER region_population_evidence BEFORE INSERT ON evolution.region_commits
|
|
FOR EACH ROW EXECUTE FUNCTION evolution.refuse_unpublished_population();
|
|
|
|
CREATE OR REPLACE FUNCTION evolution.publish_region_checkpoint(p_manifest bytea,p_decisions bytea)
|
|
RETURNS TABLE(region_frame evolution.u64,head_sequence evolution.u64,head_commit uuid,
|
|
head_digest text,head_tick evolution.u64)
|
|
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
|
|
DECLARE c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest);
|
|
BEGIN
|
|
IF c.profile IN (4,5) THEN
|
|
RAISE EXCEPTION 'cellular/population requires dedicated publisher' USING ERRCODE = 'EVL06';
|
|
END IF;
|
|
RETURN QUERY SELECT * FROM evolution.publish_region_checkpoint_core(p_manifest,p_decisions);
|
|
END $$;
|
|
|
|
-- Structural validation only. C++ additionally replays all biology and verifies
|
|
-- the exact policy/sample, including controlled presence and source state closure.
|
|
CREATE FUNCTION evolution.check_population_trace(m bytea,t bytea) RETURNS void
|
|
LANGUAGE plpgsql IMMUTABLE SET search_path = pg_catalog, pg_temp AS $$
|
|
DECLARE
|
|
c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(m);
|
|
kind numeric; n numeric; biological numeric; genome numeric; to_cohort numeric;
|
|
off integer; bio_end integer; intents numeric; members numeric; previous numeric;
|
|
sequence numeric; last_sequence numeric := -1; life numeric;
|
|
BEGIN
|
|
IF c.profile <> 5 OR t IS NULL OR octet_length(t) <> c.trace_bytes OR sha256(t) <> c.trace_sha256
|
|
OR octet_length(t) < 152 OR substring(t FROM 1 FOR 8) <> '\x4145564f50425431'
|
|
OR evolution.manifest_uint(t,8,4) <> 1 OR evolution.manifest_uint(t,12,4) > 1
|
|
OR substring(t FROM 17 FOR 88) <> (substring(m FROM 17 FOR 24) ||
|
|
substring(m FROM 65 FOR 48) || substring(m FROM 113 FOR 16))
|
|
OR evolution.manifest_uint(t,108,4) <> 0 THEN
|
|
RAISE EXCEPTION 'invalid population trace binding' USING ERRCODE = '22023';
|
|
END IF;
|
|
kind := evolution.manifest_uint(t,12,4); n := evolution.manifest_uint(t,104,4);
|
|
biological := evolution.manifest_uint(t,112,8); genome := evolution.manifest_uint(t,120,8);
|
|
to_cohort := evolution.manifest_uint(t,128,8);
|
|
IF n < 1 OR n > 64 OR biological > 1705072 OR biological > octet_length(t) - 136
|
|
OR to_cohort > 1 OR (kind = 1 AND (biological <> 0 OR genome = 0 OR n <> 1
|
|
OR c.begin_tick <> c.end_tick OR c.end_tick = 0))
|
|
OR (kind = 0 AND (genome <> 0 OR to_cohort <> 0 OR biological < 112
|
|
OR c.end_tick - c.begin_tick <> n)) THEN
|
|
RAISE EXCEPTION 'invalid population trace shape' USING ERRCODE = '22023';
|
|
END IF;
|
|
off := 136;
|
|
IF kind = 0 THEN
|
|
IF substring(t FROM 137 FOR 8) <> '\x45564c4342543031'
|
|
OR evolution.manifest_uint(t,144,4) <> 3 OR evolution.manifest_uint(t,148,4) <> 4
|
|
OR substring(t FROM 153 FOR 88) <> substring(t FROM 17 FOR 88)
|
|
OR evolution.manifest_uint(t,240,4) <> n OR evolution.manifest_uint(t,244,4) <> 0 THEN
|
|
RAISE EXCEPTION 'invalid population biological binding' USING ERRCODE = '22023';
|
|
END IF;
|
|
off := 248; bio_end := (136 + biological)::integer;
|
|
FOR i IN 1..n::integer LOOP
|
|
IF off + 16 > bio_end THEN RAISE EXCEPTION 'truncated population tick' USING ERRCODE = '22023'; END IF;
|
|
intents := evolution.manifest_uint(t,off,4);
|
|
IF intents > 256 OR evolution.manifest_uint(t,off+4,4) <> 0
|
|
OR evolution.manifest_uint(t,off+8,4) <> 0 OR evolution.manifest_uint(t,off+12,4) <> 0
|
|
OR off + 16 + intents * 24 > bio_end THEN
|
|
RAISE EXCEPTION 'unsupported population player operation' USING ERRCODE = '22023';
|
|
END IF;
|
|
off := off + 16; previous := 0;
|
|
FOR j IN 1..intents::integer LOOP
|
|
life := evolution.manifest_uint(t,off,8);
|
|
IF life <= previous THEN RAISE EXCEPTION 'unordered population inputs' USING ERRCODE = '22023'; END IF;
|
|
previous := life; off := off + 24;
|
|
END LOOP;
|
|
END LOOP;
|
|
IF off <> bio_end THEN RAISE EXCEPTION 'population biological length differs' USING ERRCODE = '22023'; END IF;
|
|
END IF;
|
|
FOR i IN 1..n::integer LOOP
|
|
IF off + 16 > octet_length(t) THEN RAISE EXCEPTION 'truncated population sample' USING ERRCODE = '22023'; END IF;
|
|
sequence := evolution.manifest_uint(t,off,8); members := evolution.manifest_uint(t,off+8,8);
|
|
IF members > 256 OR off + 16 + members * 16 > octet_length(t)
|
|
OR (last_sequence >= 0 AND (sequence < last_sequence OR sequence > last_sequence + 1)) THEN
|
|
RAISE EXCEPTION 'invalid population sample' USING ERRCODE = '22023';
|
|
END IF;
|
|
last_sequence := sequence; off := off + 16; previous := 0;
|
|
FOR j IN 1..members::integer LOOP
|
|
life := evolution.manifest_uint(t,off,8);
|
|
IF life <= previous OR evolution.manifest_uint(t,off+8,8) = 0 THEN
|
|
RAISE EXCEPTION 'invalid population member' USING ERRCODE = '22023';
|
|
END IF;
|
|
previous := life; off := off + 16;
|
|
END LOOP;
|
|
END LOOP;
|
|
IF off <> octet_length(t) THEN RAISE EXCEPTION 'trailing population bytes' USING ERRCODE = '22023'; END IF;
|
|
END $$;
|
|
REVOKE ALL ON FUNCTION evolution.check_population_trace(bytea,bytea) FROM PUBLIC;
|
|
|
|
CREATE FUNCTION evolution.publish_population_checkpoint(m bytea,t bytea)
|
|
RETURNS TABLE(region_frame evolution.u64,head_sequence evolution.u64,head_commit uuid,
|
|
head_digest text,head_tick evolution.u64)
|
|
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
|
|
DECLARE c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(m); existing bytea;
|
|
BEGIN
|
|
PERFORM evolution.check_population_trace(m,t);
|
|
-- Lease then head lock follows the common writer's order. Trace evidence is in
|
|
-- this same transaction; any core rejection rolls the insertion back.
|
|
PERFORM evolution.check_region_lease(c.world_id,c.region_id,c.holder,c.epoch);
|
|
SELECT p.trace INTO existing FROM evolution.population_publications p WHERE p.commit_id = c.commit_id;
|
|
IF FOUND THEN
|
|
IF existing <> t THEN RAISE EXCEPTION 'population identity reused' USING ERRCODE = 'EVL07'; END IF;
|
|
ELSE
|
|
INSERT INTO evolution.population_publications VALUES(c.commit_id,t);
|
|
END IF;
|
|
RETURN QUERY SELECT * FROM evolution.publish_region_checkpoint_core(m,''::bytea);
|
|
END $$;
|
|
REVOKE ALL ON FUNCTION evolution.publish_population_checkpoint(bytea,bytea) FROM PUBLIC;
|
|
GRANT EXECUTE ON FUNCTION evolution.publish_population_checkpoint(bytea,bytea) TO :"runtime_role";
|
|
|
|
CREATE FUNCTION evolution.publish_population_profile_transition(m bytea)
|
|
RETURNS TABLE(region_frame evolution.u64,head_sequence evolution.u64,head_commit uuid,
|
|
head_digest text,head_tick evolution.u64)
|
|
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
|
|
DECLARE
|
|
c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(m);
|
|
s evolution.checkpoint_manifest; p evolution.region_commits%ROWTYPE;
|
|
h evolution.region_heads%ROWTYPE; old evolution.region_commits%ROWTYPE;
|
|
d bytea := sha256(m); frame evolution.u64;
|
|
bundle9 constant bytea := '\x080000000600000002000000010000000100000004000000030000000200000001000000';
|
|
BEGIN
|
|
IF c.profile NOT IN (4,5) OR c.versions <> bundle9 OR c.commit_sequence = 0
|
|
OR c.begin_tick <> c.end_tick OR c.end_tick = 0 OR c.trace_bytes <> 0 THEN
|
|
RAISE EXCEPTION 'invalid population profile transition' USING ERRCODE = '22023';
|
|
END IF;
|
|
PERFORM evolution.check_region_lease(c.world_id,c.region_id,c.holder,c.epoch);
|
|
SELECT * INTO old FROM evolution.region_commits r WHERE r.commit_id = c.commit_id;
|
|
IF FOUND THEN
|
|
IF old.manifest <> m OR NOT EXISTS (SELECT 1 FROM evolution.population_profile_transitions x
|
|
WHERE x.target_commit = c.commit_id AND x.source_commit = c.predecessor_commit
|
|
AND x.source_manifest_sha256 = c.predecessor_digest AND x.target_profile = c.profile) THEN
|
|
RAISE EXCEPTION 'population transition identity reused' USING ERRCODE = 'EVL07';
|
|
END IF;
|
|
SELECT l.frame_id INTO frame FROM evolution.region_leases l WHERE l.world_id = c.world_id AND l.region_id = c.region_id;
|
|
RETURN QUERY SELECT frame,old.commit_sequence,old.commit_id,encode(old.commit_digest,'hex'),old.end_tick;
|
|
RETURN;
|
|
END IF;
|
|
SELECT * INTO h FROM evolution.region_heads r WHERE r.world_id = c.world_id AND r.region_id = c.region_id FOR UPDATE;
|
|
IF NOT FOUND OR h.commit_sequence = 18446744073709551615 OR c.commit_sequence <> h.commit_sequence + 1
|
|
OR c.predecessor_commit <> h.commit_id OR c.predecessor_digest <> h.digest OR c.begin_tick <> h.end_tick THEN
|
|
RAISE EXCEPTION 'population transition head moved' USING ERRCODE = 'EVL03';
|
|
END IF;
|
|
SELECT * INTO p FROM evolution.region_commits r WHERE r.commit_id = h.commit_id;
|
|
IF NOT FOUND THEN RAISE EXCEPTION 'missing population source' USING ERRCODE = 'XX000'; END IF;
|
|
s := evolution.parse_checkpoint_manifest(p.manifest);
|
|
IF c.profile = 5 AND EXISTS (SELECT 1 FROM evolution.cellular_mutation_reservations x
|
|
WHERE x.world_id = c.world_id AND x.region_id = c.region_id AND NOT EXISTS
|
|
(SELECT 1 FROM evolution.cellular_mutation_action_publications a
|
|
WHERE a.world_id = x.world_id AND a.account_id = x.account_id AND a.action_id = x.action_id)) THEN
|
|
RAISE EXCEPTION 'pending player mutation blocks population transition' USING ERRCODE = 'EVL18';
|
|
END IF;
|
|
IF s.profile NOT IN (4,5) OR s.profile = c.profile OR s.versions <> bundle9
|
|
OR s.frame_id <> c.frame_id OR s.tick_microseconds <> c.tick_microseconds
|
|
OR s.end_tick <> c.end_tick OR NOT EXISTS (SELECT 1 FROM evolution.retained_builds b WHERE b.build_identity = c.build_identity) THEN
|
|
RAISE EXCEPTION 'unsupported population source' USING ERRCODE = 'EVL06';
|
|
END IF;
|
|
INSERT INTO evolution.population_profile_transitions VALUES(c.commit_id,p.commit_id,p.commit_digest,p.payload_sha256,s.profile,c.profile);
|
|
INSERT INTO evolution.region_commits(world_id,region_id,commit_sequence,commit_id,commit_digest,manifest,
|
|
begin_tick,end_tick,published_epoch,tick_microseconds,versions,build_identity,payload_bytes,payload_sha256)
|
|
VALUES(c.world_id,c.region_id,c.commit_sequence,c.commit_id,d,m,c.begin_tick,c.end_tick,c.epoch,
|
|
c.tick_microseconds,c.versions,c.build_identity,c.payload_bytes,c.payload_sha256);
|
|
UPDATE evolution.region_heads r SET commit_sequence = c.commit_sequence,commit_id = c.commit_id,
|
|
digest = d,end_tick = c.end_tick,published_epoch = c.epoch WHERE r.world_id = c.world_id AND r.region_id = c.region_id;
|
|
RETURN QUERY SELECT c.frame_id,c.commit_sequence,c.commit_id,encode(d,'hex'),c.end_tick;
|
|
END $$;
|
|
REVOKE ALL ON FUNCTION evolution.publish_population_profile_transition(bytea) FROM PUBLIC;
|
|
GRANT EXECUTE ON FUNCTION evolution.publish_population_profile_transition(bytea) TO :"runtime_role";
|
|
|
|
CREATE FUNCTION evolution.resolve_population_commit(w evolution.u64,r evolution.u64,id uuid,m bytea,t bytea)
|
|
RETURNS TABLE(status text,region_frame evolution.u64,head_sequence evolution.u64,head_commit uuid,
|
|
head_digest text,head_tick evolution.u64)
|
|
LANGUAGE plpgsql STABLE SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
|
|
DECLARE c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(m); result record;
|
|
BEGIN
|
|
IF c.world_id <> w OR c.region_id <> r OR c.commit_id <> id OR t IS NULL
|
|
OR c.profile NOT IN (4,5) THEN RAISE EXCEPTION 'invalid population resolution' USING ERRCODE = '22023'; END IF;
|
|
IF octet_length(t) > 0 THEN PERFORM evolution.check_population_trace(m,t);
|
|
ELSIF c.trace_bytes <> 0 OR c.begin_tick <> c.end_tick THEN
|
|
RAISE EXCEPTION 'invalid transition resolution' USING ERRCODE = '22023';
|
|
END IF;
|
|
SELECT * INTO result FROM evolution.resolve_region_commit(w,r,id,m,''::bytea);
|
|
IF result.status = 'committed' AND
|
|
((octet_length(t) = 0 AND NOT EXISTS (SELECT 1 FROM evolution.population_profile_transitions x WHERE x.target_commit = id))
|
|
OR (octet_length(t) > 0 AND NOT EXISTS (SELECT 1 FROM evolution.population_publications x WHERE x.commit_id = id AND x.trace = t))) THEN
|
|
RETURN QUERY SELECT 'conflict'::text,NULL::evolution.u64,NULL::evolution.u64,NULL::uuid,NULL::text,NULL::evolution.u64;
|
|
ELSE
|
|
RETURN QUERY SELECT result.status,result.region_frame,result.head_sequence,result.head_commit,result.head_digest,result.head_tick;
|
|
END IF;
|
|
END $$;
|
|
REVOKE ALL ON FUNCTION evolution.resolve_population_commit(evolution.u64,evolution.u64,uuid,bytea,bytea) FROM PUBLIC;
|
|
GRANT EXECUTE ON FUNCTION evolution.resolve_population_commit(evolution.u64,evolution.u64,uuid,bytea,bytea) TO :"runtime_role";
|
|
|
|
CREATE FUNCTION evolution.load_population_evidence(w evolution.u64,r evolution.u64,holder uuid,epoch evolution.u64,id uuid)
|
|
RETURNS TABLE(trace bytea,source_commit uuid,source_manifest_sha256 bytea,source_payload_sha256 bytea)
|
|
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
|
|
BEGIN
|
|
PERFORM evolution.check_region_lease(w,r,holder,epoch);
|
|
RETURN QUERY SELECT p.trace,NULL::uuid,NULL::bytea,NULL::bytea FROM evolution.population_publications p
|
|
JOIN evolution.region_commits c ON c.commit_id = p.commit_id WHERE c.world_id = w AND c.region_id = r AND c.commit_id = id
|
|
UNION ALL SELECT ''::bytea,p.source_commit,p.source_manifest_sha256,p.source_payload_sha256 FROM evolution.population_profile_transitions p
|
|
JOIN evolution.region_commits c ON c.commit_id = p.target_commit WHERE c.world_id = w AND c.region_id = r AND c.commit_id = id;
|
|
END $$;
|
|
REVOKE ALL ON FUNCTION evolution.load_population_evidence(evolution.u64,evolution.u64,uuid,evolution.u64,uuid) FROM PUBLIC;
|
|
GRANT EXECUTE ON FUNCTION evolution.load_population_evidence(evolution.u64,evolution.u64,uuid,evolution.u64,uuid) TO :"runtime_role";
|
|
|
|
-- Region lease serialization prevents a new player choice from racing entry into
|
|
-- the unattended profile. Exact old action retries retain their original result.
|
|
ALTER FUNCTION evolution.reserve_cellular_mutation(evolution.u64,evolution.u64,uuid,evolution.u64,
|
|
uuid,evolution.u64,evolution.u64,evolution.u64,bytea) RENAME TO reserve_cellular_mutation_v43;
|
|
REVOKE ALL ON FUNCTION evolution.reserve_cellular_mutation_v43(evolution.u64,evolution.u64,uuid,evolution.u64,
|
|
uuid,evolution.u64,evolution.u64,evolution.u64,bytea) FROM PUBLIC, :"runtime_role";
|
|
CREATE FUNCTION evolution.reserve_cellular_mutation(p_world evolution.u64,p_region evolution.u64,
|
|
p_holder uuid,p_epoch evolution.u64,p_account uuid,p_generation evolution.u64,p_action evolution.u64,
|
|
p_target_tick evolution.u64,p_input bytea)
|
|
RETURNS TABLE(successor_identity evolution.u64,action_region evolution.u64)
|
|
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
|
|
DECLARE m bytea;
|
|
BEGIN
|
|
PERFORM evolution.check_region_lease(p_world,p_region,p_holder,p_epoch);
|
|
IF NOT EXISTS (SELECT 1 FROM evolution.cellular_mutation_reservations x
|
|
WHERE x.world_id = p_world AND x.account_id = p_account AND x.action_id = p_action) THEN
|
|
SELECT c.manifest INTO m FROM evolution.region_heads h JOIN evolution.region_commits c
|
|
ON c.commit_id = h.commit_id WHERE h.world_id = p_world AND h.region_id = p_region;
|
|
IF m IS NOT NULL AND (evolution.parse_checkpoint_manifest(m)).profile = 5 THEN
|
|
RAISE EXCEPTION 'population profile refuses player mutation' USING ERRCODE = 'EVL06';
|
|
END IF;
|
|
END IF;
|
|
RETURN QUERY SELECT * FROM evolution.reserve_cellular_mutation_v43(p_world,p_region,p_holder,p_epoch,
|
|
p_account,p_generation,p_action,p_target_tick,p_input);
|
|
END $$;
|
|
REVOKE ALL ON FUNCTION evolution.reserve_cellular_mutation(evolution.u64,evolution.u64,uuid,evolution.u64,
|
|
uuid,evolution.u64,evolution.u64,evolution.u64,bytea) FROM PUBLIC;
|
|
GRANT EXECUTE ON FUNCTION evolution.reserve_cellular_mutation(evolution.u64,evolution.u64,uuid,evolution.u64,
|
|
uuid,evolution.u64,evolution.u64,evolution.u64,bytea) TO :"runtime_role";
|
|
|
|
INSERT INTO evolution.schema_migrations(version,sha256) VALUES(44,:'migration_sha_44');
|