Fix cellular action tick publication offset
Foundation / checks (checks) (push) Successful in 6s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (postgres) (push) Failing after 32m57s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Foundation / checks (checks) (push) Successful in 6s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (postgres) (push) Failing after 32m57s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
-- M11.3d: the action tick is the first eight bytes of canonical input. The
|
||||
-- manifest_uint helper uses zero-based offsets, unlike bytea substring below.
|
||||
-- Correct migration 20's off-by-one read without changing its recorded checksum.
|
||||
CREATE OR REPLACE FUNCTION evolution.publish_cellular_checkpoint(p_manifest bytea,
|
||||
p_decisions bytea, p_actions 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);
|
||||
n integer;
|
||||
old_actions bytea;
|
||||
r record;
|
||||
BEGIN
|
||||
IF c.profile <> 4 OR c.commit_sequence = 0 OR p_actions IS NULL THEN
|
||||
RAISE EXCEPTION 'invalid cellular publication' USING ERRCODE = '22023';
|
||||
END IF;
|
||||
n := evolution.check_cellular_action_block(p_actions, c.begin_tick, c.end_tick);
|
||||
SELECT p.actions INTO old_actions FROM evolution.cellular_publications p
|
||||
WHERE p.commit_id = c.commit_id;
|
||||
IF FOUND THEN
|
||||
IF old_actions <> p_actions THEN
|
||||
RAISE EXCEPTION 'cellular commit identity reused' USING ERRCODE = 'EVL07';
|
||||
END IF;
|
||||
RETURN QUERY SELECT * FROM evolution.publish_region_checkpoint_core(p_manifest, p_decisions);
|
||||
RETURN;
|
||||
END IF;
|
||||
|
||||
PERFORM evolution.check_region_lease(c.world_id, c.region_id, c.holder, c.epoch);
|
||||
-- Recheck after the lease lock: an uncertain first attempt may have completed.
|
||||
SELECT p.actions INTO old_actions FROM evolution.cellular_publications p
|
||||
WHERE p.commit_id = c.commit_id;
|
||||
IF FOUND THEN
|
||||
IF old_actions <> p_actions THEN
|
||||
RAISE EXCEPTION 'cellular commit identity reused' USING ERRCODE = 'EVL07';
|
||||
END IF;
|
||||
RETURN QUERY SELECT * FROM evolution.publish_region_checkpoint_core(p_manifest, p_decisions);
|
||||
RETURN;
|
||||
END IF;
|
||||
|
||||
INSERT INTO evolution.cellular_publications(commit_id, actions)
|
||||
VALUES (c.commit_id, p_actions);
|
||||
FOR i IN 0 .. n - 1 LOOP
|
||||
INSERT INTO evolution.region_actions(world_id, account_id, action_id, region_id, tick,
|
||||
kind, commit_sequence, input_bytes, result)
|
||||
VALUES (c.world_id,
|
||||
encode(substring(p_actions FROM 48 * i + 1 FOR 16), 'hex')::uuid,
|
||||
evolution.manifest_uint(p_actions, 48 * i + 16, 8), c.region_id,
|
||||
evolution.manifest_uint(p_actions, 48 * i + 24, 8), 2, c.commit_sequence,
|
||||
substring(p_actions FROM 48 * i + 25 FOR 24), 5)
|
||||
ON CONFLICT (world_id, account_id, action_id) DO NOTHING;
|
||||
IF NOT EXISTS (SELECT 1 FROM evolution.region_actions a
|
||||
WHERE a.world_id = c.world_id
|
||||
AND a.account_id = encode(substring(p_actions FROM 48 * i + 1 FOR 16), 'hex')::uuid
|
||||
AND a.action_id = evolution.manifest_uint(p_actions, 48 * i + 16, 8)
|
||||
AND a.kind = 2 AND a.result = 5
|
||||
AND a.input_bytes = substring(p_actions FROM 48 * i + 25 FOR 24)) THEN
|
||||
RAISE EXCEPTION 'cellular action identity reused' USING ERRCODE = 'EVL07';
|
||||
END IF;
|
||||
END LOOP;
|
||||
-- The trigger on region_commits requires the private action-block row above.
|
||||
-- A failure here rolls back the block and all outcome rows with the head advance.
|
||||
SELECT * INTO r FROM evolution.publish_region_checkpoint_core(p_manifest, p_decisions);
|
||||
IF NOT FOUND THEN
|
||||
RAISE EXCEPTION 'publication returned no head' USING ERRCODE = 'XX000';
|
||||
END IF;
|
||||
RETURN QUERY SELECT r.region_frame, r.head_sequence, r.head_commit, r.head_digest,
|
||||
r.head_tick;
|
||||
END $$;
|
||||
|
||||
REVOKE ALL ON FUNCTION evolution.publish_cellular_checkpoint(bytea,bytea,bytea) FROM PUBLIC;
|
||||
GRANT EXECUTE ON FUNCTION evolution.publish_cellular_checkpoint(bytea,bytea,bytea)
|
||||
TO :"runtime_role";
|
||||
INSERT INTO evolution.schema_migrations(version, sha256) VALUES (33, :'migration_sha_33');
|
||||
+16
-3
@@ -106,7 +106,9 @@ SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution')
|
||||
SELECT right(:'history', length(',30:' || :'migration_sha_30')) = ',30:' || :'migration_sha_30' AS at_v30 \gset
|
||||
SELECT right(:'history', length(',31:' || :'migration_sha_31')) = ',31:' || :'migration_sha_31' AS at_v31 \gset
|
||||
SELECT right(:'history', length(',32:' || :'migration_sha_32')) = ',32:' || :'migration_sha_32' AS at_v32 \gset
|
||||
\if :at_v32
|
||||
SELECT right(:'history', length(',33:' || :'migration_sha_33')) = ',33:' || :'migration_sha_33' AS at_v33 \gset
|
||||
\if :at_v33
|
||||
\elif :at_v32
|
||||
\elif :at_v31
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
\elif :at_v30
|
||||
@@ -464,7 +466,8 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
coalesce(max(version), 0) = 29 AS at_v29,
|
||||
coalesce(max(version), 0) = 30 AS at_v30,
|
||||
coalesce(max(version), 0) = 31 AS at_v31,
|
||||
coalesce(max(version), 0) = 32 AS at_v32
|
||||
coalesce(max(version), 0) = 32 AS at_v32,
|
||||
coalesce(max(version), 0) = 33 AS at_v33
|
||||
FROM evolution.schema_migrations \gset
|
||||
\if :at_v24
|
||||
\ir 0025_cellular_v2_bundle.sql
|
||||
@@ -475,6 +478,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0030_cellular_birth_publication_binding.sql
|
||||
\ir 0031_fix_cellular_birth_publication_record.sql
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\elif :at_v25
|
||||
\ir 0026_cellular_profile_migration.sql
|
||||
\ir 0027_cellular_v3_migration.sql
|
||||
@@ -483,6 +487,7 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0030_cellular_birth_publication_binding.sql
|
||||
\ir 0031_fix_cellular_birth_publication_record.sql
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\elif :at_v26
|
||||
\ir 0027_cellular_v3_migration.sql
|
||||
\ir 0028_cellular_v3_trace_bounds.sql
|
||||
@@ -490,29 +495,37 @@ SELECT coalesce(max(version), 0) = 24 AS at_v24,
|
||||
\ir 0030_cellular_birth_publication_binding.sql
|
||||
\ir 0031_fix_cellular_birth_publication_record.sql
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\elif :at_v27
|
||||
\ir 0028_cellular_v3_trace_bounds.sql
|
||||
\ir 0029_cellular_mutation_reservations.sql
|
||||
\ir 0030_cellular_birth_publication_binding.sql
|
||||
\ir 0031_fix_cellular_birth_publication_record.sql
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\elif :at_v28
|
||||
\ir 0029_cellular_mutation_reservations.sql
|
||||
\ir 0030_cellular_birth_publication_binding.sql
|
||||
\ir 0031_fix_cellular_birth_publication_record.sql
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\elif :at_v29
|
||||
\ir 0030_cellular_birth_publication_binding.sql
|
||||
\ir 0031_fix_cellular_birth_publication_record.sql
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
\ir 0033_fix_cellular_action_tick_offset.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
|
||||
\elif :at_v31
|
||||
\ir 0032_fix_cellular_v3_manifest_normalization.sql
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\elif :at_v32
|
||||
\ir 0033_fix_cellular_action_tick_offset.sql
|
||||
\elif :at_v33
|
||||
\else
|
||||
\echo 'Unknown or changed migration history after v32'
|
||||
\echo 'Unknown or changed migration history after v33'
|
||||
DO $$ BEGIN RAISE EXCEPTION 'unknown or changed migration history'; END $$;
|
||||
\endif
|
||||
-- Effective-privilege audit on every run, including no-ops (ADR-0060). Attributes
|
||||
|
||||
Reference in New Issue
Block a user