Add cellular mutation replay trace v3
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 2m9s
Foundation / checks (ecs) (push) Successful in 2m2s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (client) (push) Canceled after 3m11s
Foundation / checks (postgres) (push) Canceled after 1m3s
Foundation / checks (network) (push) Canceled after 1m9s

This commit is contained in:
dingo
2026-10-11 06:29:17 -04:00
parent a479ce2d95
commit d9bf60138e
14 changed files with 596 additions and 49 deletions
+21 -5
View File
@@ -62,7 +62,11 @@ bool prepared_is_canonical(const CellularPreparedCommit& prepared,
std::unexpected{server::CellularActionBlockError::format}};
const auto encoded_trace = server::encode_cellular_batch(trace);
const auto digest = sha256(prepared.trace);
return manifest.profile == CheckpointProfile::cellular_lives_v1 &&
const bool trace_version_matches = (manifest.cellular_versions == cellular_v3_versions &&
trace.format_version == server::cellular_batch_format) ||
(manifest.cellular_versions != cellular_v3_versions &&
trace.format_version == server::cellular_batch_v2_format);
return manifest.profile == CheckpointProfile::cellular_lives_v1 && trace_version_matches &&
manifest.key == prepared.key && manifest.commit == prepared.commit &&
manifest.sequence > 0 && manifest.batch.trace_bytes == prepared.trace.size() && digest &&
*digest == manifest.batch.trace_sha256 && manifest.batch.decision_count == 0 &&
@@ -320,7 +324,12 @@ publish_cellular_batch(Postgres& db, const FilesystemObjectStore& objects, const
std::span<const server::CellularActionRecord> actions) {
const auto previous = decode_manifest(predecessor.manifest);
const auto predecessor_digest = sha256(predecessor.manifest);
const auto trace = server::encode_cellular_batch(batch);
auto committed_batch = batch;
if (previous)
committed_batch.format_version = previous->cellular_versions == cellular_v3_versions
? server::cellular_batch_format
: server::cellular_batch_v2_format;
const auto trace = server::encode_cellular_batch(committed_batch);
const auto action_block = server::encode_cellular_action_block(actions, batch.header.begin_tick,
batch.header.end_tick);
if (!previous || !predecessor_digest || !trace || !action_block ||
@@ -336,7 +345,9 @@ publish_cellular_batch(Postgres& db, const FilesystemObjectStore& objects, const
candidate.region() != previous->key.region || candidate.frame() != previous->frame ||
candidate.format_version() != previous->cellular_versions.envelope ||
candidate.rules_version() != previous->cellular_versions.rules ||
candidate.tick() != batch.header.end_tick)
candidate.tick() != batch.header.end_tick ||
std::ranges::any_of(committed_batch.ticks,
[](const auto& tick) { return !tick.mutations.empty(); }))
return std::unexpected{failure(PublicationError::candidate)};
auto predecessor_bytes = objects.get({previous->payload_sha256, previous->payload_bytes});
@@ -345,10 +356,10 @@ publish_cellular_batch(Postgres& db, const FilesystemObjectStore& objects, const
auto base = restore_cellular_payload(*predecessor_bytes, *previous);
if (!base)
return std::unexpected{failure(PublicationError::predecessor)};
auto replay = server::replay_cellular_batch(**base, batch);
auto replay = server::replay_cellular_batch(**base, committed_batch);
const auto payload = candidate.snapshot();
if (!replay || (*replay)->snapshot() != payload ||
!server::match_cellular_actions_to_trace(**base, batch, actions))
!server::match_cellular_actions_to_trace(**base, committed_batch, actions))
return std::unexpected{failure(PublicationError::candidate)};
const auto payload_digest = sha256(payload);
@@ -488,6 +499,11 @@ recover_cellular_checkpoint(Postgres& db, const FilesystemObjectStore& objects,
auto trace = server::decode_cellular_batch(*trace_bytes);
if (!trace)
return fail_with(RecoveryError::tail);
if ((manifest->cellular_versions == cellular_v3_versions &&
trace->format_version != server::cellular_batch_format) ||
(manifest->cellular_versions != cellular_v3_versions &&
trace->format_version != server::cellular_batch_v2_format))
return fail_with(RecoveryError::tail);
if (trace->header.world != key.world || trace->header.region != key.region ||
trace->header.frame != manifest->frame ||
trace->header.predecessor != manifest->predecessor_commit ||