Format M11 cellular code with clang-format 19
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m52s
Foundation / checks (client) (push) Failing after 4m25s
Foundation / checks (network) (push) Failing after 3m2s
Foundation / checks (tsan) (push) Failing after 33s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 5m47s
Foundation / checks (postgres) (push) Canceled after 1m24s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m52s
Foundation / checks (client) (push) Failing after 4m25s
Foundation / checks (network) (push) Failing after 3m2s
Foundation / checks (tsan) (push) Failing after 33s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 5m47s
Foundation / checks (postgres) (push) Canceled after 1m24s
This commit is contained in:
@@ -209,9 +209,9 @@ void patch_box(std::vector<evo::render::Rectangle>& out, double x, double y, boo
|
||||
if (x1 > x0 && y1 > y0)
|
||||
out.push_back({static_cast<float>(x0), static_cast<float>(y0), static_cast<float>(x1 - x0),
|
||||
static_cast<float>(y1 - y0),
|
||||
selected ? evo::render::Color{250, 190, 40, 255}
|
||||
: stocked ? evo::render::Color{80, 220, 130, 255}
|
||||
: evo::render::Color{115, 125, 135, 255}});
|
||||
selected ? evo::render::Color{250, 190, 40, 255}
|
||||
: stocked ? evo::render::Color{80, 220, 130, 255}
|
||||
: evo::render::Color{115, 125, 135, 255}});
|
||||
}
|
||||
void outline(std::vector<evo::render::Rectangle>& out, double l, double t, double r, double b,
|
||||
double width, double height) {
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
// [--max-commits N]
|
||||
// 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
|
||||
// evo-world-clone provision --world W --region R --opening
|
||||
// development-v1|primitive-v1|cellular-v1
|
||||
// --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 also requires --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.
|
||||
// and one or more ordered --patch X,Y,SOURCE,ENERGY,C,N,P,O values plus a stable --commit
|
||||
// HEX32.
|
||||
// evo-world-clone compare --world A --region R --other-world B --pg-* ...
|
||||
// --objects DIR [--other-objects DIR] --retained HEX... [--max-commits N]
|
||||
//
|
||||
@@ -56,10 +58,10 @@
|
||||
//
|
||||
// Exit: 0 done, 2 usage, 3 source/history/database failure, 4 target/objects refused,
|
||||
// 5 target unknown, 6 compared histories differ.
|
||||
#include "evo/biology/cellular_habitat.hpp"
|
||||
#include "evo/persistence/region_clone.hpp"
|
||||
#include "evo/persistence/sha256.hpp"
|
||||
#include "evo/processes/development_opening.hpp"
|
||||
#include "evo/biology/cellular_habitat.hpp"
|
||||
#include "evo/server/lifecycle/cellular_lives.hpp"
|
||||
#include "evo/server/lifecycle/primitive_lives.hpp"
|
||||
|
||||
@@ -98,8 +100,7 @@ struct Options {
|
||||
std::optional<std::uint64_t> primitive_frame, primitive_source;
|
||||
std::array<std::optional<std::uint64_t>, 5> primitive_funding;
|
||||
std::vector<server::SpawnSite> primitive_sites;
|
||||
std::optional<std::uint32_t> cellular_width_um, cellular_height_um,
|
||||
cellular_temperature_mk;
|
||||
std::optional<std::uint32_t> cellular_width_um, cellular_height_um, cellular_temperature_mk;
|
||||
std::vector<biology::CellularPatch> cellular_patches;
|
||||
std::optional<persistence::Sha256Digest> build;
|
||||
bool retain_build{};
|
||||
@@ -146,8 +147,7 @@ std::optional<biology::CellularPatch> cellular_patch(std::string_view text) {
|
||||
fields[1] > std::numeric_limits<std::uint32_t>::max())
|
||||
return std::nullopt;
|
||||
biology::CellularPatch result{};
|
||||
result.address = {static_cast<std::uint32_t>(fields[0]),
|
||||
static_cast<std::uint32_t>(fields[1])};
|
||||
result.address = {static_cast<std::uint32_t>(fields[0]), static_cast<std::uint32_t>(fields[1])};
|
||||
result.source = fields[2];
|
||||
result.stock.energy.value = fields[3];
|
||||
for (std::size_t i = 0; i < result.stock.matter.size(); ++i)
|
||||
@@ -263,8 +263,7 @@ std::optional<Options> parse(int argc, char** argv) {
|
||||
else if (o.command == "check-store" && flag == "--reserve-mib" && n && *n <= 1048576)
|
||||
o.reserve_mib = *n;
|
||||
else if (o.command == "provision" && flag == "--opening" &&
|
||||
(value == "development-v1" || value == "primitive-v1" ||
|
||||
value == "cellular-v1"))
|
||||
(value == "development-v1" || value == "primitive-v1" || value == "cellular-v1"))
|
||||
o.opening = value;
|
||||
else if (o.command == "provision" && flag == "--frame" && n)
|
||||
o.primitive_frame = *n;
|
||||
@@ -444,9 +443,9 @@ 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";
|
||||
const auto payload_limit = cellular ? server::max_cellular_lives_bytes
|
||||
: primitive ? server::max_primitive_lives_bytes
|
||||
: persistence::max_lineage_payload_bytes;
|
||||
const auto payload_limit = cellular ? server::max_cellular_lives_bytes
|
||||
: primitive ? server::max_primitive_lives_bytes
|
||||
: persistence::max_lineage_payload_bytes;
|
||||
auto store = open_objects(o.source, payload_limit);
|
||||
if (!store) {
|
||||
std::puts("objects refused");
|
||||
@@ -534,7 +533,8 @@ int provision(const Options& o) {
|
||||
timeout);
|
||||
if (same_genesis)
|
||||
return report("already-provisioned", same_genesis->head);
|
||||
std::puts("provision refused existing cellular region; use its original --commit to resolve genesis");
|
||||
std::puts("provision refused existing cellular region; use its original --commit to "
|
||||
"resolve genesis");
|
||||
return 4;
|
||||
}
|
||||
const auto manifest = persistence::decode_manifest(existing->manifest);
|
||||
@@ -564,10 +564,12 @@ int provision(const Options& o) {
|
||||
return 3;
|
||||
}
|
||||
if (cellular) {
|
||||
auto made = persistence::provision_cellular_region(
|
||||
*db, *store, o.source.key, *o.primitive_frame, *cellular_opening, commit, build, timeout);
|
||||
auto made =
|
||||
persistence::provision_cellular_region(*db, *store, o.source.key, *o.primitive_frame,
|
||||
*cellular_opening, commit, build, timeout);
|
||||
if (!made) {
|
||||
std::printf("cellular provision refused %u\n", static_cast<unsigned>(made.error().kind));
|
||||
std::printf("cellular provision refused %u\n",
|
||||
static_cast<unsigned>(made.error().kind));
|
||||
return 4;
|
||||
}
|
||||
return report("provisioned", made->head);
|
||||
|
||||
@@ -6696,3 +6696,9 @@ compile under MSVC `/W4 /WX /DNDEBUG`. A standalone local link is unavailable:
|
||||
the cached release libraries do not contain the latest cellular lifecycle
|
||||
symbols and the cached debug libraries use a different CRT. The Linux CI run
|
||||
provides the full linked test.
|
||||
|
||||
CI run 242 passed all 68 `checks` tests, including the new trace-shape regression,
|
||||
but the final whole-tree format target found 25 recently edited cellular-stage
|
||||
files that were not formatted to the CI-pinned clang-format 19.1.5 style. They
|
||||
are now formatted with that exact version; the repository-wide check passes
|
||||
locally and CI is pending on the formatting-only follow-up.
|
||||
|
||||
@@ -60,9 +60,10 @@ class RegionSessionClient {
|
||||
[[nodiscard]] bool send_action(std::uint64_t action_id, network::ActionKind kind,
|
||||
std::uint64_t tick);
|
||||
// Protocol v7/v8. Reuse the exact same fields and action id after reconnect.
|
||||
[[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 = {});
|
||||
[[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 = {});
|
||||
[[nodiscard]] bool query_action(std::uint64_t action_id);
|
||||
// Primitive profile v5 only. The account and generation are always supplied by the
|
||||
// authenticated session; callers choose only a stable request id.
|
||||
|
||||
@@ -202,14 +202,14 @@ class IntentAdmission {
|
||||
[[nodiscard]] Found lookup(const AccountId& account, std::uint64_t action_id) const;
|
||||
// The in-memory checks of an action; `check` is set when only the ledger can still
|
||||
// refuse it.
|
||||
[[nodiscard]] ActionReceipt screen(
|
||||
Session& s, const SessionAction& m, const AdmissionFacts& facts, bool& check,
|
||||
std::optional<std::array<std::uint8_t, cellular_action_input_bytes>> cellular_input =
|
||||
std::nullopt);
|
||||
[[nodiscard]] ActionReceipt
|
||||
screen(Session& s, const SessionAction& m, const AdmissionFacts& facts, bool& check,
|
||||
std::optional<std::array<std::uint8_t, cellular_action_input_bytes>> cellular_input =
|
||||
std::nullopt);
|
||||
// Applies a durable answer to a receipt that passed `screen`.
|
||||
void decide(const AccountId& account, ActionReceipt& r, const Found& found,
|
||||
std::optional<std::array<std::uint8_t, cellular_action_input_bytes>> cellular_input =
|
||||
std::nullopt);
|
||||
std::optional<std::array<std::uint8_t, cellular_action_input_bytes>>
|
||||
cellular_input = std::nullopt);
|
||||
Session* find(std::uint64_t session);
|
||||
const Session* find(std::uint64_t session) const;
|
||||
void count_window(Session& s, std::uint64_t server_tick) const;
|
||||
|
||||
@@ -204,11 +204,11 @@ provision_cellular_region(Postgres& owner, const FilesystemObjectStore& objects,
|
||||
std::uint64_t frame, const server::CellularLives& opening, Uuid commit,
|
||||
const Sha256Digest& build, std::chrono::milliseconds timeout);
|
||||
[[nodiscard]] std::expected<PublishedCellularBatch, CellularPublicationFailure>
|
||||
publish_cellular_batch(Postgres& db, const FilesystemObjectStore& objects,
|
||||
const LeaseGrant& lease, const CommittedCheckpoint& predecessor,
|
||||
const server::CellularBatch& batch, const server::CellularLives& candidate,
|
||||
Uuid commit, const Sha256Digest& build,
|
||||
std::chrono::milliseconds timeout, const PublishHooks& hooks = {},
|
||||
publish_cellular_batch(Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease,
|
||||
const CommittedCheckpoint& predecessor, const server::CellularBatch& batch,
|
||||
const server::CellularLives& candidate, Uuid commit,
|
||||
const Sha256Digest& build, std::chrono::milliseconds timeout,
|
||||
const PublishHooks& hooks = {},
|
||||
std::span<const server::CellularActionRecord> actions = {});
|
||||
[[nodiscard]] std::expected<CommittedCheckpoint, CellularPublicationFailure>
|
||||
retry_cellular_prepared(Postgres& db, const CellularPreparedCommit& prepared,
|
||||
@@ -218,8 +218,7 @@ resolve_cellular_prepared(Postgres& db, const CellularPreparedCommit& prepared,
|
||||
std::chrono::milliseconds timeout);
|
||||
[[nodiscard]] std::expected<RecoveredCellularCheckpoint, RecoveryFailure>
|
||||
recover_cellular_checkpoint(Postgres& db, const FilesystemObjectStore& objects, RegionKey key,
|
||||
const LeaseGrant& lease,
|
||||
std::span<const Sha256Digest> retained_builds,
|
||||
const LeaseGrant& lease, std::span<const Sha256Digest> retained_builds,
|
||||
std::chrono::milliseconds timeout);
|
||||
|
||||
// After an `unknown` publication: resolve exactly the prepared bytes. A committed
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "evo/persistence/region_lease.hpp"
|
||||
#include "evo/processes/environmental_community.hpp"
|
||||
#include "evo/processes/lineage_region.hpp"
|
||||
#include "evo/server/lifecycle/cellular_lives.hpp"
|
||||
#include "evo/server/lifecycle/cellular_batch.hpp"
|
||||
#include "evo/server/lifecycle/cellular_lives.hpp"
|
||||
#include "evo/server/lifecycle/primitive_batch.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@@ -97,7 +97,7 @@ inline constexpr std::size_t max_lineage_payload_bytes = processes::max_lineage_
|
||||
return profile == CheckpointProfile::environmental_v1 ? max_environmental_payload_bytes
|
||||
: profile == CheckpointProfile::environmental_lineage_v1 ? max_lineage_payload_bytes
|
||||
: profile == CheckpointProfile::primitive_lives_v1 ? server::max_primitive_lives_bytes
|
||||
: profile == CheckpointProfile::cellular_lives_v1 ? server::max_cellular_lives_bytes
|
||||
: profile == CheckpointProfile::cellular_lives_v1 ? server::max_cellular_lives_bytes
|
||||
: 0;
|
||||
}
|
||||
inline constexpr std::uint64_t max_checkpoint_ticks = 64;
|
||||
@@ -159,6 +159,5 @@ restore_lineage_payload(std::span<const std::uint8_t> payload, const CheckpointM
|
||||
restore_primitive_payload(std::span<const std::uint8_t> payload,
|
||||
const CheckpointManifest& manifest);
|
||||
[[nodiscard]] std::expected<std::unique_ptr<server::CellularLives>, CheckpointError>
|
||||
restore_cellular_payload(std::span<const std::uint8_t> payload,
|
||||
const CheckpointManifest& manifest);
|
||||
restore_cellular_payload(std::span<const std::uint8_t> payload, const CheckpointManifest& manifest);
|
||||
} // namespace evo::persistence
|
||||
|
||||
@@ -82,8 +82,7 @@ publish_region_checkpoint(Postgres& db, std::span<const std::uint8_t> manifest,
|
||||
publish_cellular_checkpoint(Postgres& db, std::span<const std::uint8_t> manifest,
|
||||
std::span<const std::uint8_t> decisions,
|
||||
std::span<const std::uint8_t> actions,
|
||||
std::span<const std::uint8_t> trace,
|
||||
std::chrono::milliseconds timeout);
|
||||
std::span<const std::uint8_t> trace, std::chrono::milliseconds timeout);
|
||||
|
||||
enum class Resolution : std::uint8_t {
|
||||
committed, // Exact bytes are durable; receipt holds the head. Grants no authority.
|
||||
@@ -107,13 +106,10 @@ resolve_region_commit(Postgres& db, RegionKey key, const Uuid& commit,
|
||||
std::span<const std::uint8_t> actions, std::chrono::milliseconds timeout);
|
||||
|
||||
// Schema v20 resolution also compares the immutable profile-4 cellular action block.
|
||||
[[nodiscard]] std::expected<ResolvedCommit, LeaseStoreFailure>
|
||||
resolve_cellular_region_commit(Postgres& db, RegionKey key, const Uuid& commit,
|
||||
std::span<const std::uint8_t> manifest,
|
||||
std::span<const std::uint8_t> decisions,
|
||||
std::span<const std::uint8_t> actions,
|
||||
std::span<const std::uint8_t> trace,
|
||||
std::chrono::milliseconds timeout);
|
||||
[[nodiscard]] std::expected<ResolvedCommit, LeaseStoreFailure> resolve_cellular_region_commit(
|
||||
Postgres& db, RegionKey key, const Uuid& commit, std::span<const std::uint8_t> manifest,
|
||||
std::span<const std::uint8_t> decisions, std::span<const std::uint8_t> actions,
|
||||
std::span<const std::uint8_t> trace, std::chrono::milliseconds timeout);
|
||||
|
||||
// Load the immutable action block for a committed profile-4 link under the current lease.
|
||||
// Empty means this commit has no cellular publication row; a missing row for a progressing
|
||||
@@ -146,9 +142,8 @@ struct CommittedActionRecord {
|
||||
friend bool operator==(const CommittedActionRecord&, const CommittedActionRecord&) = default;
|
||||
};
|
||||
[[nodiscard]] std::expected<std::optional<CommittedActionRecord>, LeaseStoreFailure>
|
||||
find_region_action_record(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
const Uuid& account, std::uint64_t action_id,
|
||||
std::chrono::milliseconds timeout);
|
||||
find_region_action_record(Postgres& db, RegionKey key, const LeaseGrant& lease, const Uuid& account,
|
||||
std::uint64_t action_id, std::chrono::milliseconds timeout);
|
||||
// The same for several (account, action) pairs in one statement, answered in order
|
||||
// (M10.9d, ADR-0097). Empty asks nothing.
|
||||
struct ActionRef {
|
||||
@@ -160,8 +155,7 @@ find_region_actions(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
std::span<const ActionRef> actions, std::chrono::milliseconds timeout);
|
||||
[[nodiscard]] std::expected<std::vector<std::optional<CommittedActionRecord>>, LeaseStoreFailure>
|
||||
find_region_action_records(Postgres& db, RegionKey key, const LeaseGrant& lease,
|
||||
std::span<const ActionRef> actions,
|
||||
std::chrono::milliseconds timeout);
|
||||
std::span<const ActionRef> actions, std::chrono::milliseconds timeout);
|
||||
|
||||
struct CommittedDecision {
|
||||
std::uint64_t commit_sequence{};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "evo/network/session_protocol.hpp"
|
||||
#include "evo/persistence/checkpoint_store.hpp"
|
||||
#include "evo/persistence/life_reservation_store.hpp"
|
||||
#include "evo/network/session_protocol.hpp"
|
||||
#include "evo/server/lifecycle/cellular_batch.hpp"
|
||||
#include "evo/server/ops.hpp"
|
||||
|
||||
@@ -25,7 +25,12 @@ struct CellularHostConfig {
|
||||
persistence::Sha256Digest build{};
|
||||
std::vector<persistence::Sha256Digest> retained_builds;
|
||||
};
|
||||
enum class CellularHostError : std::uint8_t { configuration, not_ready, invalid_batch, publication };
|
||||
enum class CellularHostError : std::uint8_t {
|
||||
configuration,
|
||||
not_ready,
|
||||
invalid_batch,
|
||||
publication
|
||||
};
|
||||
struct FinalCellularAction {
|
||||
CellularActionRecord action;
|
||||
std::uint64_t commit_sequence{};
|
||||
@@ -36,8 +41,7 @@ struct FinalCellularAction {
|
||||
// the host replays it from its recovered state and advances only on a confirmed head.
|
||||
class CellularRegionHost {
|
||||
public:
|
||||
[[nodiscard]] static std::expected<std::unique_ptr<CellularRegionHost>,
|
||||
CellularHostError>
|
||||
[[nodiscard]] static std::expected<std::unique_ptr<CellularRegionHost>, CellularHostError>
|
||||
create(CellularHostConfig config, CellularConnect connect,
|
||||
std::unique_ptr<persistence::FilesystemObjectStore> objects);
|
||||
CellularRegionHost(const CellularRegionHost&) = delete;
|
||||
@@ -47,8 +51,7 @@ class CellularRegionHost {
|
||||
// Acquires/renews authority, recovers fully, or resolves the exact pending commit.
|
||||
const HostStatus& step();
|
||||
[[nodiscard]] std::expected<persistence::PublishedCellularBatch, CellularHostError>
|
||||
publish(const CellularBatch& batch,
|
||||
std::span<const CellularActionRecord> actions = {});
|
||||
publish(const CellularBatch& batch, std::span<const CellularActionRecord> actions = {});
|
||||
// v5 requests allocate durably, then wait for the scheduler to include the exact
|
||||
// reservation in a profile-4 batch. Repeating the request is idempotent.
|
||||
[[nodiscard]] network::PrimitiveLifeOutcome
|
||||
@@ -63,9 +66,14 @@ class CellularRegionHost {
|
||||
[[nodiscard]] std::vector<FinalCellularAction> take_finalized_actions();
|
||||
void drain();
|
||||
[[nodiscard]] std::optional<persistence::LeaseGrant> authority() const;
|
||||
[[nodiscard]] const HostStatus& status() const noexcept { return status_; }
|
||||
[[nodiscard]] const CellularLives* state() const noexcept { return state_.get(); }
|
||||
[[nodiscard]] const std::optional<persistence::CommittedCheckpoint>& committed() const noexcept {
|
||||
[[nodiscard]] const HostStatus& status() const noexcept {
|
||||
return status_;
|
||||
}
|
||||
[[nodiscard]] const CellularLives* state() const noexcept {
|
||||
return state_.get();
|
||||
}
|
||||
[[nodiscard]] const std::optional<persistence::CommittedCheckpoint>&
|
||||
committed() const noexcept {
|
||||
return committed_;
|
||||
}
|
||||
|
||||
@@ -80,9 +88,9 @@ class CellularRegionHost {
|
||||
void refresh();
|
||||
void finalize_births(std::span<const CellularTickIntents::Birth> births);
|
||||
void queue_birth(const CellularTickIntents::Birth& birth);
|
||||
[[nodiscard]] network::PrimitiveLifeOutcome query_birth(
|
||||
const persistence::Uuid& account, std::uint64_t generation, std::uint64_t request,
|
||||
bool enqueue);
|
||||
[[nodiscard]] network::PrimitiveLifeOutcome query_birth(const persistence::Uuid& account,
|
||||
std::uint64_t generation,
|
||||
std::uint64_t request, bool enqueue);
|
||||
|
||||
CellularHostConfig config_;
|
||||
CellularConnect connect_;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "evo/network/intent_admission.hpp"
|
||||
#include "evo/server/lifecycle/cellular_batch.hpp"
|
||||
#include "evo/persistence/region_lease.hpp"
|
||||
#include "evo/server/lifecycle/cellular_batch.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
@@ -51,11 +51,15 @@ class CellularSessionBatchBuilder {
|
||||
append(std::uint64_t tick, std::span<const CellularLifeIntent> baseline,
|
||||
std::span<const network::CarriedAction> actions,
|
||||
std::span<const CellularTickIntents::Birth> births = {});
|
||||
[[nodiscard]] const CellularBatch& batch() const noexcept { return batch_; }
|
||||
[[nodiscard]] const CellularBatch& batch() const noexcept {
|
||||
return batch_;
|
||||
}
|
||||
[[nodiscard]] std::span<const CellularActionRecord> actions() const noexcept {
|
||||
return actions_;
|
||||
}
|
||||
[[nodiscard]] const CellularLives& candidate() const noexcept { return *working_; }
|
||||
[[nodiscard]] const CellularLives& candidate() const noexcept {
|
||||
return *working_;
|
||||
}
|
||||
|
||||
private:
|
||||
explicit CellularSessionBatchBuilder(std::unique_ptr<CellularLives> working)
|
||||
|
||||
@@ -50,10 +50,11 @@ inline constexpr std::size_t cellular_batch_tick_header_bytes = 8;
|
||||
inline constexpr std::size_t cellular_batch_intent_bytes = 24;
|
||||
inline constexpr std::size_t cellular_batch_birth_bytes = 40;
|
||||
inline constexpr std::size_t max_cellular_batch_ticks = 64;
|
||||
inline constexpr std::size_t max_cellular_batch_bytes = cellular_batch_header_bytes +
|
||||
inline constexpr std::size_t max_cellular_batch_bytes =
|
||||
cellular_batch_header_bytes +
|
||||
max_cellular_batch_ticks * (cellular_batch_tick_header_bytes +
|
||||
biology::max_cellular_tick_lives *
|
||||
(cellular_batch_intent_bytes + cellular_batch_birth_bytes));
|
||||
biology::max_cellular_tick_lives *
|
||||
(cellular_batch_intent_bytes + cellular_batch_birth_bytes));
|
||||
enum class CellularBatchError : std::uint8_t { format, version, scope, state };
|
||||
inline constexpr std::size_t cellular_action_record_bytes = 48;
|
||||
inline constexpr std::size_t max_cellular_action_records = 1'024;
|
||||
|
||||
@@ -144,11 +144,9 @@ IntentAdmission::scheduled_cellular_intentions(std::uint64_t tick) const {
|
||||
return out;
|
||||
}
|
||||
|
||||
ActionReceipt IntentAdmission::screen(Session& s, const SessionAction& m,
|
||||
const AdmissionFacts& facts, bool& check,
|
||||
std::optional<std::array<std::uint8_t,
|
||||
cellular_action_input_bytes>>
|
||||
cellular_input) {
|
||||
ActionReceipt IntentAdmission::screen(
|
||||
Session& s, const SessionAction& m, const AdmissionFacts& facts, bool& check,
|
||||
std::optional<std::array<std::uint8_t, cellular_action_input_bytes>> cellular_input) {
|
||||
ActionReceipt r{m.action_id, AdmitStatus::admitted, facts.server_tick, m.tick};
|
||||
check = false;
|
||||
count_window(s, facts.server_tick);
|
||||
@@ -174,15 +172,14 @@ ActionReceipt IntentAdmission::screen(Session& s, const SessionAction& m,
|
||||
m.kind != static_cast<std::uint16_t>(ActionKind::cellular)) ||
|
||||
(m.kind == static_cast<std::uint16_t>(ActionKind::cellular)) !=
|
||||
cellular_input.has_value() ||
|
||||
m.action_id == 0 ||
|
||||
(cellular_input && !decode_cellular_action_input(*cellular_input)))
|
||||
m.action_id == 0 || (cellular_input && !decode_cellular_action_input(*cellular_input)))
|
||||
r.status = AdmitStatus::invalid_action;
|
||||
else if (known_action != actions_.end() || known_final != finals_.end()) {
|
||||
const auto same = [&](ActionKind kind,
|
||||
const std::optional<std::array<std::uint8_t,
|
||||
cellular_action_input_bytes>>& bytes) {
|
||||
return static_cast<std::uint16_t>(kind) == m.kind && bytes == cellular_input;
|
||||
};
|
||||
const auto same =
|
||||
[&](ActionKind kind,
|
||||
const std::optional<std::array<std::uint8_t, cellular_action_input_bytes>>& bytes) {
|
||||
return static_cast<std::uint16_t>(kind) == m.kind && bytes == cellular_input;
|
||||
};
|
||||
if (known_action != actions_.end()) {
|
||||
r.tick = known_action->carried.tick;
|
||||
r.status = same(known_action->carried.kind, known_action->carried.cellular_input)
|
||||
@@ -216,8 +213,8 @@ void IntentAdmission::decide(
|
||||
}
|
||||
r.status = AdmitStatus::duplicate;
|
||||
r.tick = found.outcome.tick;
|
||||
remember(account, found.outcome,
|
||||
cellular_input ? ActionKind::cellular : ActionKind::probe, cellular_input);
|
||||
remember(account, found.outcome, cellular_input ? ActionKind::cellular : ActionKind::probe,
|
||||
cellular_input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,8 +247,8 @@ ActionReceipt IntentAdmission::action(std::uint64_t session, const CellularActio
|
||||
if (check)
|
||||
decide(s->account, r, lookup(s->account, m.action_id), bytes);
|
||||
if (r.status == AdmitStatus::admitted)
|
||||
actions_.push_back({{s->account, m.action_id, m.tick, ActionKind::cellular, bytes},
|
||||
Stage::scheduled});
|
||||
actions_.push_back(
|
||||
{{s->account, m.action_id, m.tick, ActionKind::cellular, bytes}, Stage::scheduled});
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -277,9 +274,8 @@ std::optional<ActionReceipt> IntentAdmission::admit(std::uint64_t session, const
|
||||
return r;
|
||||
}
|
||||
|
||||
std::optional<ActionReceipt> IntentAdmission::admit(std::uint64_t session,
|
||||
const CellularAction& m,
|
||||
const AdmissionFacts& facts) {
|
||||
std::optional<ActionReceipt> IntentAdmission::admit(std::uint64_t session, const CellularAction& m,
|
||||
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(
|
||||
@@ -452,8 +448,9 @@ std::vector<AccountOutcome> IntentAdmission::committed(std::span<const CarriedAc
|
||||
}
|
||||
for (std::size_t i = 0; i < actions.size(); ++i) {
|
||||
const auto& c = actions[i];
|
||||
const auto local_result = c.kind == ActionKind::cellular ? ActionResult::committed
|
||||
: ActionResult::committed_no_effect;
|
||||
const auto local_result = c.kind == ActionKind::cellular
|
||||
? ActionResult::committed
|
||||
: ActionResult::committed_no_effect;
|
||||
ActionOutcome o{c.action_id, local_result, c.tick, commit_sequence};
|
||||
if (records.has_value())
|
||||
if (const auto& record = (*records)[i]; record.has_value())
|
||||
|
||||
@@ -23,16 +23,16 @@ CellularPublicationFailure failure(PublicationError kind, ObjectError object = {
|
||||
CellularPreparedCommit prepared = {}) {
|
||||
return {kind, store, object, std::move(prepared)};
|
||||
}
|
||||
std::expected<void, CellularPublicationFailure>
|
||||
put_verified(const FilesystemObjectStore& objects, std::span<const std::uint8_t> bytes,
|
||||
VerifiedObject expected) {
|
||||
std::expected<void, CellularPublicationFailure> put_verified(const FilesystemObjectStore& objects,
|
||||
std::span<const std::uint8_t> bytes,
|
||||
VerifiedObject expected) {
|
||||
auto stored = objects.put(bytes);
|
||||
if (!stored)
|
||||
return std::unexpected{failure(PublicationError::upload, stored.error())};
|
||||
auto readback = objects.get(*stored);
|
||||
if (!readback || *stored != expected || !std::ranges::equal(*readback, bytes))
|
||||
return std::unexpected{failure(PublicationError::verify,
|
||||
readback ? ObjectError::corrupt : readback.error())};
|
||||
return std::unexpected{
|
||||
failure(PublicationError::verify, readback ? ObjectError::corrupt : readback.error())};
|
||||
return {};
|
||||
}
|
||||
std::expected<CommittedCheckpoint, CellularPublicationFailure>
|
||||
@@ -46,28 +46,29 @@ confirm(const RegionHead& head, const CellularPreparedCommit& prepared,
|
||||
return CommittedCheckpoint{head, prepared.manifest};
|
||||
}
|
||||
bool prepared_is_canonical(const CellularPreparedCommit& prepared,
|
||||
const CheckpointManifest& manifest,
|
||||
const server::CellularBatch& trace) {
|
||||
const CheckpointManifest& manifest, const server::CellularBatch& trace) {
|
||||
const auto decoded_actions = server::decode_cellular_action_block(
|
||||
prepared.actions, manifest.begin_tick, manifest.end_tick);
|
||||
const auto encoded_actions = decoded_actions
|
||||
? server::encode_cellular_action_block(*decoded_actions, manifest.begin_tick,
|
||||
manifest.end_tick)
|
||||
: std::expected<std::vector<std::uint8_t>, server::CellularActionBlockError>{
|
||||
std::unexpected{server::CellularActionBlockError::format}};
|
||||
const auto encoded_actions =
|
||||
decoded_actions
|
||||
? server::encode_cellular_action_block(*decoded_actions, manifest.begin_tick,
|
||||
manifest.end_tick)
|
||||
: std::expected<std::vector<std::uint8_t>, server::CellularActionBlockError>{
|
||||
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 &&
|
||||
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 &&
|
||||
manifest.batch.decisions_sha256 == Sha256Digest{} && trace.header.world == prepared.key.world &&
|
||||
trace.header.region == prepared.key.region && trace.header.frame == manifest.frame &&
|
||||
manifest.sequence > 0 && manifest.batch.trace_bytes == prepared.trace.size() && digest &&
|
||||
*digest == manifest.batch.trace_sha256 && manifest.batch.decision_count == 0 &&
|
||||
manifest.batch.decisions_sha256 == Sha256Digest{} &&
|
||||
trace.header.world == prepared.key.world && trace.header.region == prepared.key.region &&
|
||||
trace.header.frame == manifest.frame &&
|
||||
trace.header.predecessor == manifest.predecessor_commit &&
|
||||
trace.header.predecessor_digest == manifest.predecessor_digest &&
|
||||
trace.header.begin_tick == manifest.begin_tick && trace.header.end_tick == manifest.end_tick &&
|
||||
encoded_actions && *encoded_actions == prepared.actions && encoded_trace &&
|
||||
trace.header.begin_tick == manifest.begin_tick &&
|
||||
trace.header.end_tick == manifest.end_tick && encoded_actions &&
|
||||
*encoded_actions == prepared.actions && encoded_trace &&
|
||||
*encoded_trace == prepared.trace;
|
||||
}
|
||||
} // namespace
|
||||
@@ -77,16 +78,17 @@ provision_cellular_region(Postgres& owner, const FilesystemObjectStore& objects,
|
||||
std::uint64_t frame, const server::CellularLives& opening, Uuid commit,
|
||||
const Sha256Digest& build, milliseconds timeout) {
|
||||
const auto payload = opening.snapshot();
|
||||
if (opening.world() != key.world || opening.region() != key.region || opening.frame() != frame ||
|
||||
opening.tick() != 0 || !opening.lives().empty() || !opening.corpses().empty() ||
|
||||
opening.archive().recorded() != 0 || opening.archive().archived() != 0)
|
||||
if (opening.world() != key.world || opening.region() != key.region ||
|
||||
opening.frame() != frame || opening.tick() != 0 || !opening.lives().empty() ||
|
||||
!opening.corpses().empty() || opening.archive().recorded() != 0 ||
|
||||
opening.archive().archived() != 0)
|
||||
return std::unexpected{failure(PublicationError::candidate)};
|
||||
const auto digest = sha256(payload);
|
||||
if (!digest)
|
||||
return std::unexpected{failure(PublicationError::digest)};
|
||||
auto manifest = genesis_manifest(key, frame, commit, biology::cellular_motion_tick_microseconds,
|
||||
build, payload.size(), *digest,
|
||||
CheckpointProfile::cellular_lives_v1);
|
||||
auto manifest =
|
||||
genesis_manifest(key, frame, commit, biology::cellular_motion_tick_microseconds, build,
|
||||
payload.size(), *digest, CheckpointProfile::cellular_lives_v1);
|
||||
auto encoded = manifest ? encode_manifest(*manifest)
|
||||
: std::expected<std::vector<std::uint8_t>, CheckpointError>{
|
||||
std::unexpected{CheckpointError::format}};
|
||||
@@ -140,10 +142,10 @@ retry_cellular_prepared(Postgres& db, const CellularPreparedCommit& prepared,
|
||||
auto result = publish_cellular_checkpoint(db, prepared.manifest, {}, prepared.actions,
|
||||
prepared.trace, timeout);
|
||||
if (!result) {
|
||||
return std::unexpected{failure(
|
||||
result.error().kind == LeaseStoreError::unknown ? PublicationError::unknown
|
||||
: PublicationError::rejected,
|
||||
{}, result.error(), prepared)};
|
||||
return std::unexpected{failure(result.error().kind == LeaseStoreError::unknown
|
||||
? PublicationError::unknown
|
||||
: PublicationError::rejected,
|
||||
{}, result.error(), prepared)};
|
||||
}
|
||||
return confirm(*result, prepared, *manifest);
|
||||
}
|
||||
@@ -155,29 +157,29 @@ resolve_cellular_prepared(Postgres& db, const CellularPreparedCommit& prepared,
|
||||
auto trace = server::decode_cellular_batch(prepared.trace);
|
||||
if (!manifest || !trace || !prepared_is_canonical(prepared, *manifest, *trace))
|
||||
return std::unexpected{LeaseStoreFailure{LeaseStoreError::invalid, {}}};
|
||||
return resolve_cellular_region_commit(db, prepared.key, prepared.commit, prepared.manifest,
|
||||
{}, prepared.actions, prepared.trace, timeout);
|
||||
return resolve_cellular_region_commit(db, prepared.key, prepared.commit, prepared.manifest, {},
|
||||
prepared.actions, prepared.trace, timeout);
|
||||
}
|
||||
|
||||
std::expected<PublishedCellularBatch, CellularPublicationFailure>
|
||||
publish_cellular_batch(Postgres& db, const FilesystemObjectStore& objects,
|
||||
const LeaseGrant& lease, const CommittedCheckpoint& predecessor,
|
||||
const server::CellularBatch& batch, const server::CellularLives& candidate,
|
||||
Uuid commit, const Sha256Digest& build, milliseconds timeout,
|
||||
const PublishHooks& hooks,
|
||||
publish_cellular_batch(Postgres& db, const FilesystemObjectStore& objects, const LeaseGrant& lease,
|
||||
const CommittedCheckpoint& predecessor, const server::CellularBatch& batch,
|
||||
const server::CellularLives& candidate, Uuid commit,
|
||||
const Sha256Digest& build, milliseconds timeout, const PublishHooks& hooks,
|
||||
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);
|
||||
const auto action_block = server::encode_cellular_action_block(
|
||||
actions, batch.header.begin_tick, batch.header.end_tick);
|
||||
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 ||
|
||||
previous->profile != CheckpointProfile::cellular_lives_v1 ||
|
||||
predecessor.head.digest != *predecessor_digest ||
|
||||
previous->sequence != predecessor.head.sequence || previous->commit != predecessor.head.commit ||
|
||||
previous->end_tick != predecessor.head.end_tick || batch.header.world != previous->key.world ||
|
||||
batch.header.region != previous->key.region || batch.header.frame != previous->frame ||
|
||||
batch.header.predecessor != previous->commit ||
|
||||
previous->sequence != predecessor.head.sequence ||
|
||||
previous->commit != predecessor.head.commit ||
|
||||
previous->end_tick != predecessor.head.end_tick ||
|
||||
batch.header.world != previous->key.world || batch.header.region != previous->key.region ||
|
||||
batch.header.frame != previous->frame || batch.header.predecessor != previous->commit ||
|
||||
batch.header.predecessor_digest != *predecessor_digest ||
|
||||
batch.header.begin_tick != previous->end_tick || candidate.world() != previous->key.world ||
|
||||
candidate.region() != previous->key.region || candidate.frame() != previous->frame ||
|
||||
@@ -201,8 +203,8 @@ publish_cellular_batch(Postgres& db, const FilesystemObjectStore& objects,
|
||||
if (!payload_digest || !trace_digest)
|
||||
return std::unexpected{failure(PublicationError::digest)};
|
||||
auto manifest = successor_manifest(*previous, *predecessor_digest, commit, lease,
|
||||
batch.header.end_tick, build, payload.size(), *payload_digest,
|
||||
{trace->size(), *trace_digest, 0, {}});
|
||||
batch.header.end_tick, build, payload.size(),
|
||||
*payload_digest, {trace->size(), *trace_digest, 0, {}});
|
||||
auto manifest_bytes = manifest ? encode_manifest(*manifest)
|
||||
: std::expected<std::vector<std::uint8_t>, CheckpointError>{
|
||||
std::unexpected{CheckpointError::format}};
|
||||
@@ -224,25 +226,24 @@ publish_cellular_batch(Postgres& db, const FilesystemObjectStore& objects,
|
||||
|
||||
std::expected<RecoveredCellularCheckpoint, RecoveryFailure>
|
||||
recover_cellular_checkpoint(Postgres& db, const FilesystemObjectStore& objects, RegionKey key,
|
||||
const LeaseGrant& lease,
|
||||
std::span<const Sha256Digest> retained_builds,
|
||||
const LeaseGrant& lease, std::span<const Sha256Digest> retained_builds,
|
||||
milliseconds timeout) {
|
||||
const auto fail_with = [](RecoveryError kind) {
|
||||
return std::unexpected{RecoveryFailure{kind, {}}};
|
||||
};
|
||||
auto committed = load_region_checkpoint(db, key, timeout);
|
||||
if (!committed)
|
||||
return std::unexpected{RecoveryFailure{
|
||||
committed.error().kind == LeaseStoreError::not_provisioned
|
||||
? RecoveryError::not_provisioned
|
||||
: RecoveryError::store,
|
||||
committed.error()}};
|
||||
return std::unexpected{
|
||||
RecoveryFailure{committed.error().kind == LeaseStoreError::not_provisioned
|
||||
? RecoveryError::not_provisioned
|
||||
: RecoveryError::store,
|
||||
committed.error()}};
|
||||
const auto digest = sha256(committed->manifest);
|
||||
auto manifest = decode_manifest(committed->manifest);
|
||||
if (!digest || *digest != committed->head.digest || !manifest || manifest->key != key ||
|
||||
manifest->sequence != committed->head.sequence ||
|
||||
manifest->commit != committed->head.commit || manifest->end_tick != committed->head.end_tick ||
|
||||
manifest->frame != committed->head.frame)
|
||||
manifest->commit != committed->head.commit ||
|
||||
manifest->end_tick != committed->head.end_tick || manifest->frame != committed->head.frame)
|
||||
return fail_with(RecoveryError::manifest);
|
||||
if (!supported(*manifest) || manifest->profile != CheckpointProfile::cellular_lives_v1 ||
|
||||
std::ranges::find(retained_builds, manifest->build) == retained_builds.end())
|
||||
@@ -253,14 +254,15 @@ recover_cellular_checkpoint(Postgres& db, const FilesystemObjectStore& objects,
|
||||
auto payload = objects.get({manifest->payload_sha256, manifest->payload_bytes});
|
||||
if (!payload)
|
||||
return fail_with(payload.error() == ObjectError::io ? RecoveryError::store
|
||||
: RecoveryError::corrupt_payload);
|
||||
: RecoveryError::corrupt_payload);
|
||||
auto state = restore_cellular_payload(*payload, *manifest);
|
||||
if (!state)
|
||||
return fail_with(RecoveryError::payload);
|
||||
|
||||
std::vector<server::CellularActionRecord> actions;
|
||||
if (manifest->sequence != 0) {
|
||||
auto action_bytes = load_cellular_publication_actions(db, key, lease, manifest->commit, timeout);
|
||||
auto action_bytes =
|
||||
load_cellular_publication_actions(db, key, lease, manifest->commit, timeout);
|
||||
if (!action_bytes)
|
||||
return std::unexpected{RecoveryFailure{RecoveryError::store, action_bytes.error()}};
|
||||
if (!*action_bytes)
|
||||
@@ -281,17 +283,15 @@ recover_cellular_checkpoint(Postgres& db, const FilesystemObjectStore& objects,
|
||||
trace->header.end_tick != manifest->end_tick)
|
||||
return fail_with(RecoveryError::tail);
|
||||
|
||||
auto committed_births = load_cellular_publication_births(db, key, lease,
|
||||
manifest->commit, timeout);
|
||||
auto committed_births =
|
||||
load_cellular_publication_births(db, key, lease, manifest->commit, timeout);
|
||||
if (!committed_births)
|
||||
return std::unexpected{RecoveryFailure{RecoveryError::store,
|
||||
committed_births.error()}};
|
||||
return std::unexpected{RecoveryFailure{RecoveryError::store, committed_births.error()}};
|
||||
std::vector<CellularBirthBinding> traced_births;
|
||||
for (std::size_t tick_index = 0; tick_index < trace->ticks.size(); ++tick_index) {
|
||||
for (const auto& birth : trace->ticks[tick_index].births) {
|
||||
traced_births.push_back({birth.account, manifest->commit, birth.request,
|
||||
birth.identity,
|
||||
manifest->begin_tick + tick_index + 1,
|
||||
birth.identity, manifest->begin_tick + tick_index + 1,
|
||||
manifest->sequence});
|
||||
}
|
||||
}
|
||||
@@ -319,7 +319,8 @@ recover_cellular_checkpoint(Postgres& db, const FilesystemObjectStore& objects,
|
||||
return fail_with(RecoveryError::tail);
|
||||
auto batch_actions = server::decode_cellular_action_block(
|
||||
**action_bytes, manifest->begin_tick, manifest->end_tick);
|
||||
if (!batch_actions || !server::match_cellular_actions_to_trace(**base, *trace, *batch_actions))
|
||||
if (!batch_actions ||
|
||||
!server::match_cellular_actions_to_trace(**base, *trace, *batch_actions))
|
||||
return fail_with(RecoveryError::history);
|
||||
auto replay = server::replay_cellular_batch(**base, *trace);
|
||||
if (!replay || (*replay)->snapshot() != *payload)
|
||||
|
||||
@@ -169,12 +169,17 @@ encode_manifest(const CheckpointManifest& m) {
|
||||
w.u(m.tick_microseconds, 8);
|
||||
const auto versions =
|
||||
m.profile == CheckpointProfile::cellular_lives_v1
|
||||
? std::array{m.cellular_versions.rules, m.cellular_versions.envelope,
|
||||
m.cellular_versions.habitat, m.cellular_versions.coordinate,
|
||||
m.cellular_versions.genome, m.cellular_versions.development,
|
||||
m.cellular_versions.founder, m.cellular_versions.archive, 0U}
|
||||
: std::array{m.versions.rules, m.versions.envelope, m.versions.resources,
|
||||
m.versions.fields, m.versions.terrain, m.versions.coordinate,
|
||||
? std::array{m.cellular_versions.rules,
|
||||
m.cellular_versions.envelope,
|
||||
m.cellular_versions.habitat,
|
||||
m.cellular_versions.coordinate,
|
||||
m.cellular_versions.genome,
|
||||
m.cellular_versions.development,
|
||||
m.cellular_versions.founder,
|
||||
m.cellular_versions.archive,
|
||||
0U}
|
||||
: std::array{m.versions.rules, m.versions.envelope, m.versions.resources,
|
||||
m.versions.fields, m.versions.terrain, m.versions.coordinate,
|
||||
m.versions.generator, m.versions.material, m.versions.interval_adapter};
|
||||
for (const auto v : versions)
|
||||
w.u(v, 4);
|
||||
@@ -225,13 +230,13 @@ decode_manifest(std::span<const std::uint8_t> bytes) {
|
||||
for (auto& v : versions)
|
||||
v = static_cast<std::uint32_t>(r.u(4));
|
||||
if (m.profile == CheckpointProfile::cellular_lives_v1) {
|
||||
m.cellular_versions = {versions[0], versions[1], versions[2], versions[3], versions[4],
|
||||
versions[5], versions[6], versions[7]};
|
||||
m.cellular_versions = {versions[0], versions[1], versions[2], versions[3],
|
||||
versions[4], versions[5], versions[6], versions[7]};
|
||||
if (versions[8] != 0)
|
||||
return std::unexpected{CheckpointError::format};
|
||||
} else {
|
||||
m.versions = {versions[0], versions[1], versions[2], versions[3], versions[4],
|
||||
versions[5], versions[6], versions[7], versions[8]};
|
||||
versions[5], versions[6], versions[7], versions[8]};
|
||||
}
|
||||
m.build = r.bytes<32>();
|
||||
m.rng_streams = static_cast<std::uint32_t>(r.u(4));
|
||||
@@ -424,8 +429,8 @@ restore_cellular_payload(std::span<const std::uint8_t> payload, const Checkpoint
|
||||
return std::unexpected{CheckpointError::unsupported};
|
||||
if (payload.size() != m.payload_bytes)
|
||||
return std::unexpected{CheckpointError::payload};
|
||||
auto restored = server::CellularLives::restore(payload, m.key.world, m.key.region, m.frame,
|
||||
m.end_tick);
|
||||
auto restored =
|
||||
server::CellularLives::restore(payload, m.key.world, m.key.region, m.frame, m.end_tick);
|
||||
if (!restored)
|
||||
return std::unexpected{restored.error() == server::CellularLivesError::version
|
||||
? CheckpointError::unsupported
|
||||
|
||||
@@ -51,8 +51,8 @@ std::vector<CellularTickIntents::Birth> births_in(const CellularBatch& batch) {
|
||||
}
|
||||
|
||||
std::optional<persistence::Uuid> commit_id(const persistence::CommittedCheckpoint& previous,
|
||||
std::span<const std::uint8_t> trace,
|
||||
std::span<const std::uint8_t> actions) {
|
||||
std::span<const std::uint8_t> trace,
|
||||
std::span<const std::uint8_t> actions) {
|
||||
std::vector<std::uint8_t> identity;
|
||||
identity.reserve(previous.head.digest.size() + 16 + trace.size() + actions.size());
|
||||
identity.insert(identity.end(), previous.head.digest.begin(), previous.head.digest.end());
|
||||
@@ -76,9 +76,8 @@ std::optional<persistence::Uuid> commit_id(const persistence::CommittedCheckpoin
|
||||
}
|
||||
} // namespace
|
||||
|
||||
CellularRegionHost::CellularRegionHost(
|
||||
CellularHostConfig config, CellularConnect connect,
|
||||
std::unique_ptr<persistence::FilesystemObjectStore> objects)
|
||||
CellularRegionHost::CellularRegionHost(CellularHostConfig config, CellularConnect connect,
|
||||
std::unique_ptr<persistence::FilesystemObjectStore> objects)
|
||||
: config_{std::move(config)}, connect_{std::move(connect)}, objects_{std::move(objects)},
|
||||
authority_{config_.lease} {}
|
||||
|
||||
@@ -109,9 +108,8 @@ void CellularRegionHost::acquire() {
|
||||
if (!database())
|
||||
return;
|
||||
const auto sent = LeaseClock::now();
|
||||
auto lease = persistence::acquire_region_lease(*db_, config_.key, config_.build,
|
||||
config_.lease.duration,
|
||||
config_.lease.renew_timeout);
|
||||
auto lease = persistence::acquire_region_lease(
|
||||
*db_, config_.key, config_.build, config_.lease.duration, config_.lease.renew_timeout);
|
||||
if (!lease) {
|
||||
if (lease.error().kind == LeaseStoreError::not_provisioned ||
|
||||
lease.error().kind == LeaseStoreError::unsupported) {
|
||||
@@ -122,14 +120,13 @@ void CellularRegionHost::acquire() {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (lease->frame != config_.frame ||
|
||||
!authority_.acquired(*lease, sent, LeaseClock::now())) {
|
||||
if (lease->frame != config_.frame || !authority_.acquired(*lease, sent, LeaseClock::now())) {
|
||||
status_.phase = HostPhase::quarantined;
|
||||
return;
|
||||
}
|
||||
auto recovered = persistence::recover_cellular_checkpoint(
|
||||
*db_, *objects_, config_.key, *lease, config_.retained_builds,
|
||||
config_.lease.commit_timeout);
|
||||
auto recovered = persistence::recover_cellular_checkpoint(*db_, *objects_, config_.key, *lease,
|
||||
config_.retained_builds,
|
||||
config_.lease.commit_timeout);
|
||||
if (!recovered) {
|
||||
if (recovered.error().kind == persistence::RecoveryError::store) {
|
||||
db_.reset();
|
||||
@@ -204,8 +201,8 @@ void CellularRegionHost::resolve() {
|
||||
++status_.fences;
|
||||
return;
|
||||
}
|
||||
const auto resolved = persistence::resolve_cellular_prepared(
|
||||
*db_, pending_->prepared, config_.lease.commit_timeout);
|
||||
const auto resolved = persistence::resolve_cellular_prepared(*db_, pending_->prepared,
|
||||
config_.lease.commit_timeout);
|
||||
if (!resolved) {
|
||||
if (resolved.error().kind == LeaseStoreError::fenced) {
|
||||
authority_.fence();
|
||||
@@ -233,8 +230,8 @@ void CellularRegionHost::resolve() {
|
||||
if (resolved->status == persistence::Resolution::absent &&
|
||||
!authority_.may_begin_commit(LeaseClock::now()))
|
||||
return;
|
||||
auto retried = persistence::retry_cellular_prepared(
|
||||
*db_, pending_->prepared, config_.lease.commit_timeout);
|
||||
auto retried = persistence::retry_cellular_prepared(*db_, pending_->prepared,
|
||||
config_.lease.commit_timeout);
|
||||
if (!retried) {
|
||||
if (retried.error().kind == persistence::PublicationError::unknown) {
|
||||
db_.reset();
|
||||
@@ -278,11 +275,10 @@ void CellularRegionHost::refresh() {
|
||||
authority_.may_originate(LeaseClock::now());
|
||||
status_.epoch = grant ? grant->epoch : 0;
|
||||
status_.lease_remaining_ms =
|
||||
status_.ready
|
||||
? static_cast<std::uint64_t>(std::chrono::duration_cast<milliseconds>(
|
||||
authority_.deadline() - LeaseClock::now())
|
||||
.count())
|
||||
: 0;
|
||||
status_.ready ? static_cast<std::uint64_t>(std::chrono::duration_cast<milliseconds>(
|
||||
authority_.deadline() - LeaseClock::now())
|
||||
.count())
|
||||
: 0;
|
||||
}
|
||||
|
||||
const HostStatus& CellularRegionHost::step() {
|
||||
@@ -301,18 +297,16 @@ const HostStatus& CellularRegionHost::step() {
|
||||
std::expected<persistence::PublishedCellularBatch, CellularHostError>
|
||||
CellularRegionHost::publish(const CellularBatch& batch,
|
||||
std::span<const CellularActionRecord> actions) {
|
||||
if (!status_.ready || !state_ || !committed_ ||
|
||||
!authority_.may_begin_commit(LeaseClock::now()))
|
||||
if (!status_.ready || !state_ || !committed_ || !authority_.may_begin_commit(LeaseClock::now()))
|
||||
return std::unexpected{CellularHostError::not_ready};
|
||||
auto candidate = replay_cellular_batch(*state_, batch);
|
||||
if (!candidate)
|
||||
return std::unexpected{CellularHostError::invalid_batch};
|
||||
auto trace = encode_cellular_batch(batch);
|
||||
auto action_block = encode_cellular_action_block(actions, batch.header.begin_tick,
|
||||
batch.header.end_tick);
|
||||
const auto commit = trace && action_block
|
||||
? commit_id(*committed_, *trace, *action_block)
|
||||
: std::nullopt;
|
||||
auto action_block =
|
||||
encode_cellular_action_block(actions, batch.header.begin_tick, batch.header.end_tick);
|
||||
const auto commit =
|
||||
trace && action_block ? commit_id(*committed_, *trace, *action_block) : std::nullopt;
|
||||
if (!commit)
|
||||
return std::unexpected{CellularHostError::invalid_batch};
|
||||
auto published = persistence::publish_cellular_batch(
|
||||
@@ -320,9 +314,10 @@ CellularRegionHost::publish(const CellularBatch& batch,
|
||||
config_.build, config_.lease.commit_timeout, {}, actions);
|
||||
if (!published) {
|
||||
if (published.error().kind == persistence::PublicationError::unknown) {
|
||||
pending_ = std::make_unique<Pending>(
|
||||
Pending{published.error().prepared, std::move(*candidate),
|
||||
{actions.begin(), actions.end()}, births_in(batch)});
|
||||
pending_ = std::make_unique<Pending>(Pending{published.error().prepared,
|
||||
std::move(*candidate),
|
||||
{actions.begin(), actions.end()},
|
||||
births_in(batch)});
|
||||
status_.phase = HostPhase::resolving;
|
||||
status_.ready = false;
|
||||
++status_.unknown_outcomes;
|
||||
@@ -367,22 +362,21 @@ void CellularRegionHost::finalize_births(std::span<const CellularTickIntents::Bi
|
||||
});
|
||||
}
|
||||
|
||||
network::PrimitiveLifeOutcome CellularRegionHost::query_birth(
|
||||
const persistence::Uuid& account, std::uint64_t generation, std::uint64_t request,
|
||||
bool enqueue) {
|
||||
network::PrimitiveLifeOutcome CellularRegionHost::query_birth(const persistence::Uuid& account,
|
||||
std::uint64_t generation,
|
||||
std::uint64_t request, bool enqueue) {
|
||||
using network::PrimitiveLifeResult;
|
||||
const auto unknown = [&] {
|
||||
return network::PrimitiveLifeOutcome{request, PrimitiveLifeResult::unknown, 0, 0};
|
||||
};
|
||||
if (!status_.ready || !authority_.may_begin_commit(LeaseClock::now()) || account ==
|
||||
persistence::Uuid{} || generation == 0 || request == 0 || !database())
|
||||
if (!status_.ready || !authority_.may_begin_commit(LeaseClock::now()) ||
|
||||
account == persistence::Uuid{} || generation == 0 || request == 0 || !database())
|
||||
return unknown();
|
||||
const auto grant = authority_.grant();
|
||||
if (!grant)
|
||||
return unknown();
|
||||
auto queried = persistence::query_primitive_life(*db_, config_.key, *grant, account,
|
||||
generation, request,
|
||||
config_.lease.commit_timeout);
|
||||
auto queried = persistence::query_primitive_life(*db_, config_.key, *grant, account, generation,
|
||||
request, config_.lease.commit_timeout);
|
||||
if (!queried) {
|
||||
if (queried.error().kind == persistence::LifeReservationError::unknown ||
|
||||
queried.error().kind == persistence::LifeReservationError::store)
|
||||
@@ -407,8 +401,9 @@ network::PrimitiveLifeOutcome CellularRegionHost::query_birth(
|
||||
return {request, result, outcome.reservation.identity, 0};
|
||||
}
|
||||
|
||||
network::PrimitiveLifeOutcome CellularRegionHost::create_primitive_life(
|
||||
const persistence::Uuid& account, std::uint64_t generation, std::uint64_t request) {
|
||||
network::PrimitiveLifeOutcome
|
||||
CellularRegionHost::create_primitive_life(const persistence::Uuid& account,
|
||||
std::uint64_t generation, std::uint64_t request) {
|
||||
using network::PrimitiveLifeResult;
|
||||
const auto existing = query_birth(account, generation, request, true);
|
||||
if (existing.result != PrimitiveLifeResult::unknown)
|
||||
@@ -419,8 +414,8 @@ network::PrimitiveLifeOutcome CellularRegionHost::create_primitive_life(
|
||||
if (!grant)
|
||||
return {request, PrimitiveLifeResult::unknown, 0, 0};
|
||||
auto reserved = persistence::reserve_primitive_life(
|
||||
*db_, config_.key, *grant, account, generation, request,
|
||||
biology::founder_life_rules, config_.lease.commit_timeout);
|
||||
*db_, config_.key, *grant, account, generation, request, biology::founder_life_rules,
|
||||
config_.lease.commit_timeout);
|
||||
if (!reserved) {
|
||||
if (reserved.error().kind == persistence::LifeReservationError::unknown ||
|
||||
reserved.error().kind == persistence::LifeReservationError::store)
|
||||
@@ -439,8 +434,9 @@ network::PrimitiveLifeOutcome CellularRegionHost::create_primitive_life(
|
||||
return {request, result, reserved->identity, 0};
|
||||
}
|
||||
|
||||
network::PrimitiveLifeOutcome CellularRegionHost::query_primitive_life(
|
||||
const persistence::Uuid& account, std::uint64_t generation, std::uint64_t request) {
|
||||
network::PrimitiveLifeOutcome
|
||||
CellularRegionHost::query_primitive_life(const persistence::Uuid& account, std::uint64_t generation,
|
||||
std::uint64_t request) {
|
||||
return query_birth(account, generation, request, true);
|
||||
}
|
||||
|
||||
@@ -454,8 +450,8 @@ void CellularRegionHost::drain() {
|
||||
pending_.reset();
|
||||
const auto grant = authority_.grant();
|
||||
if (grant && authority_.may_originate(LeaseClock::now()) && database())
|
||||
static_cast<void>(persistence::release_region_lease(
|
||||
*db_, config_.key, *grant, config_.lease.renew_timeout));
|
||||
static_cast<void>(persistence::release_region_lease(*db_, config_.key, *grant,
|
||||
config_.lease.renew_timeout));
|
||||
authority_.fence();
|
||||
state_.reset();
|
||||
committed_.reset();
|
||||
|
||||
@@ -30,8 +30,7 @@ bool all_zero(std::span<const std::uint8_t> bytes) {
|
||||
bool valid_header(const CellularBatchHeader& h, std::size_t ticks) {
|
||||
return h.world != 0 && h.region != 0 && h.frame != 0 && !all_zero(h.predecessor) &&
|
||||
!all_zero(h.predecessor_digest) && h.end_tick > h.begin_tick &&
|
||||
h.end_tick - h.begin_tick == ticks && ticks > 0 &&
|
||||
ticks <= max_cellular_batch_ticks;
|
||||
h.end_tick - h.begin_tick == ticks && ticks > 0 && ticks <= max_cellular_batch_ticks;
|
||||
}
|
||||
bool valid_intent(const CellularLifeIntent& life) {
|
||||
const auto& step = life.intent;
|
||||
@@ -48,16 +47,14 @@ bool valid_ticks(std::span<const CellularTickIntents> ticks) {
|
||||
return false;
|
||||
for (std::size_t i = 0; i < tick.lives.size(); ++i) {
|
||||
const auto& life = tick.lives[i];
|
||||
if (!valid_intent(life) ||
|
||||
(i > 0 && tick.lives[i - 1].life_id >= life.life_id))
|
||||
if (!valid_intent(life) || (i > 0 && tick.lives[i - 1].life_id >= life.life_id))
|
||||
return false;
|
||||
}
|
||||
for (std::size_t i = 0; i < tick.births.size(); ++i) {
|
||||
const auto& birth = tick.births[i];
|
||||
if (all_zero(birth.account) || birth.request == 0 || birth.generation == 0 ||
|
||||
birth.identity == 0 ||
|
||||
(i > 0 && std::tie(tick.births[i - 1].account,
|
||||
tick.births[i - 1].request) >=
|
||||
(i > 0 && std::tie(tick.births[i - 1].account, tick.births[i - 1].request) >=
|
||||
std::tie(birth.account, birth.request)))
|
||||
return false;
|
||||
if (!identities.insert(birth.identity).second || !accounts.insert(birth.account).second)
|
||||
@@ -73,22 +70,19 @@ bool valid_action_input(const CellularActionRecord& action, std::uint64_t begin_
|
||||
std::uint64_t end_tick) {
|
||||
const auto input = std::span<const std::uint8_t>{action.input};
|
||||
const auto tick = action_tick(action);
|
||||
const auto move_x = std::bit_cast<std::int16_t>(
|
||||
static_cast<std::uint16_t>(get(input, 8, 2)));
|
||||
const auto move_y = std::bit_cast<std::int16_t>(
|
||||
static_cast<std::uint16_t>(get(input, 10, 2)));
|
||||
const auto move_x = std::bit_cast<std::int16_t>(static_cast<std::uint16_t>(get(input, 8, 2)));
|
||||
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] <= 1 &&
|
||||
all_zero(input.subspan(13, 3)) &&
|
||||
(input[12] == 1 || all_zero(input.subspan(16, 8)));
|
||||
all_zero(input.subspan(13, 3)) && (input[12] == 1 || all_zero(input.subspan(16, 8)));
|
||||
}
|
||||
bool action_less(const CellularActionRecord& a, const CellularActionRecord& b) {
|
||||
const auto a_tick = action_tick(a);
|
||||
const auto b_tick = action_tick(b);
|
||||
return a_tick < b_tick ||
|
||||
(a_tick == b_tick && (a.account < b.account ||
|
||||
(a.account == b.account && a.action_id < b.action_id)));
|
||||
(a_tick == b_tick &&
|
||||
(a.account < b.account || (a.account == b.account && a.action_id < b.action_id)));
|
||||
}
|
||||
bool valid_actions(std::span<const CellularActionRecord> actions, std::uint64_t begin_tick,
|
||||
std::uint64_t end_tick) {
|
||||
@@ -215,14 +209,14 @@ decode_cellular_batch(std::span<const std::uint8_t> bytes) {
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
CellularLifeIntent life;
|
||||
life.life_id = get(record, 0, 8);
|
||||
life.intent.movement.x = std::bit_cast<std::int16_t>(
|
||||
static_cast<std::uint16_t>(get(record, 8, 2)));
|
||||
life.intent.movement.y = std::bit_cast<std::int16_t>(
|
||||
static_cast<std::uint16_t>(get(record, 10, 2)));
|
||||
life.intent.movement.x =
|
||||
std::bit_cast<std::int16_t>(static_cast<std::uint16_t>(get(record, 8, 2)));
|
||||
life.intent.movement.y =
|
||||
std::bit_cast<std::int16_t>(static_cast<std::uint16_t>(get(record, 10, 2)));
|
||||
if (record[12] == 1) {
|
||||
life.intent.intake_target = biology::CellularPatchAddress{
|
||||
static_cast<std::uint32_t>(get(record, 16, 4)),
|
||||
static_cast<std::uint32_t>(get(record, 20, 4))};
|
||||
life.intent.intake_target =
|
||||
biology::CellularPatchAddress{static_cast<std::uint32_t>(get(record, 16, 4)),
|
||||
static_cast<std::uint32_t>(get(record, 20, 4))};
|
||||
} else if (!all_zero(record.subspan(16, 8))) {
|
||||
return std::unexpected{CellularBatchError::format};
|
||||
}
|
||||
@@ -275,8 +269,11 @@ replay_cellular_batch(const CellularLives& base, const CellularBatch& batch) {
|
||||
return std::unexpected{CellularBatchError::state};
|
||||
for (const auto& birth : tick.births) {
|
||||
const LifeRequest request{birth.account, birth.request};
|
||||
const LifeAllocation allocation{birth.identity, birth.identity, birth.identity,
|
||||
birth.identity, {(*replay)->tick()}};
|
||||
const LifeAllocation allocation{birth.identity,
|
||||
birth.identity,
|
||||
birth.identity,
|
||||
birth.identity,
|
||||
{(*replay)->tick()}};
|
||||
auto born = (*replay)->birth_candidate(request, allocation);
|
||||
if (!born)
|
||||
return std::unexpected{CellularBatchError::state};
|
||||
@@ -331,28 +328,27 @@ match_cellular_actions_to_trace(const CellularLives& predecessor, const Cellular
|
||||
predecessor.frame() != batch.header.frame || predecessor.tick() != batch.header.begin_tick)
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
for (const auto& action : actions) {
|
||||
const auto life = std::ranges::find(predecessor.lives(), action.account,
|
||||
&CellularOwnedLife::account);
|
||||
const auto life =
|
||||
std::ranges::find(predecessor.lives(), action.account, &CellularOwnedLife::account);
|
||||
if (life == predecessor.lives().end())
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
const auto index = static_cast<std::size_t>(action_tick(action) - batch.header.begin_tick - 1);
|
||||
const auto index =
|
||||
static_cast<std::size_t>(action_tick(action) - batch.header.begin_tick - 1);
|
||||
const auto& intents = batch.ticks[index].lives;
|
||||
const auto intent = std::ranges::lower_bound(
|
||||
intents, life->identity.life, {}, [](const CellularLifeIntent& value) {
|
||||
return value.life_id;
|
||||
});
|
||||
const auto intent =
|
||||
std::ranges::lower_bound(intents, life->identity.life, {},
|
||||
[](const CellularLifeIntent& value) { return value.life_id; });
|
||||
if (intent == intents.end() || intent->life_id != life->identity.life)
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
const auto input = std::span<const std::uint8_t>{action.input};
|
||||
std::optional<biology::CellularPatchAddress> target;
|
||||
if (input[12] != 0)
|
||||
target = biology::CellularPatchAddress{
|
||||
static_cast<std::uint32_t>(get(input, 16, 4)),
|
||||
static_cast<std::uint32_t>(get(input, 20, 4))};
|
||||
if (intent->intent.movement.x != 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))) ||
|
||||
target = biology::CellularPatchAddress{static_cast<std::uint32_t>(get(input, 16, 4)),
|
||||
static_cast<std::uint32_t>(get(input, 20, 4))};
|
||||
if (intent->intent.movement.x !=
|
||||
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)
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
|
||||
std::ranges::sort(prepared.intents.lives, {}, &CellularLifeIntent::life_id);
|
||||
for (std::size_t i = 0; i < state.lives().size(); ++i)
|
||||
if (prepared.intents.lives[i].life_id != state.lives()[i].identity.life ||
|
||||
(i != 0 && prepared.intents.lives[i - 1].life_id ==
|
||||
prepared.intents.lives[i].life_id))
|
||||
(i != 0 && prepared.intents.lives[i - 1].life_id == prepared.intents.lives[i].life_id))
|
||||
return std::unexpected{CellularSessionBatchError::intents};
|
||||
|
||||
prepared.actions.reserve(actions.size());
|
||||
@@ -33,16 +32,16 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
|
||||
if (!input || input->tick != tick)
|
||||
return std::unexpected{CellularSessionBatchError::action};
|
||||
|
||||
const auto life = std::ranges::find(state.lives(), action.account.bytes,
|
||||
&CellularOwnedLife::account);
|
||||
const auto life =
|
||||
std::ranges::find(state.lives(), action.account.bytes, &CellularOwnedLife::account);
|
||||
if (life == state.lives().end())
|
||||
return std::unexpected{CellularSessionBatchError::life};
|
||||
if (input->has_intake_target) {
|
||||
const auto view = state.perceive(life->identity.life);
|
||||
const biology::CellularPatchAddress target{input->intake_x_um, input->intake_y_um};
|
||||
if (!view || std::ranges::find(*view, target,
|
||||
&biology::CellularPatchPerception::address) ==
|
||||
view->end())
|
||||
if (!view ||
|
||||
std::ranges::find(*view, target, &biology::CellularPatchPerception::address) ==
|
||||
view->end())
|
||||
return std::unexpected{CellularSessionBatchError::unperceived_target};
|
||||
}
|
||||
const auto owned_intent = std::ranges::lower_bound(
|
||||
@@ -67,12 +66,12 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
|
||||
record.input = *action.cellular_input;
|
||||
prepared.actions.push_back(record);
|
||||
}
|
||||
std::ranges::sort(prepared.actions, [](const CellularActionRecord& left,
|
||||
const CellularActionRecord& right) {
|
||||
if (left.account != right.account)
|
||||
return left.account < right.account;
|
||||
return left.action_id < right.action_id;
|
||||
});
|
||||
std::ranges::sort(prepared.actions,
|
||||
[](const CellularActionRecord& left, const CellularActionRecord& right) {
|
||||
if (left.account != right.account)
|
||||
return left.account < right.account;
|
||||
return left.action_id < right.action_id;
|
||||
});
|
||||
return prepared;
|
||||
}
|
||||
|
||||
@@ -93,7 +92,7 @@ CellularSessionBatchBuilder::create(const CellularLives& committed_state,
|
||||
CellularSessionBatchBuilder builder{std::move(*working)};
|
||||
builder.batch_.header = {committed_state.world(), committed_state.region(),
|
||||
committed_state.frame(), committed_head.commit,
|
||||
committed_head.digest, committed_state.tick(),
|
||||
committed_head.digest, committed_state.tick(),
|
||||
committed_state.tick()};
|
||||
return builder;
|
||||
}
|
||||
@@ -112,8 +111,7 @@ CellularSessionBatchBuilder::append(std::uint64_t tick,
|
||||
return std::unexpected{prepared.error()};
|
||||
for (const auto& action : prepared->actions)
|
||||
if (std::ranges::find_if(actions_, [&](const CellularActionRecord& previous) {
|
||||
return previous.account == action.account &&
|
||||
previous.action_id == action.action_id;
|
||||
return previous.account == action.account && previous.action_id == action.action_id;
|
||||
}) != actions_.end())
|
||||
return std::unexpected{CellularSessionBatchError::duplicate_action};
|
||||
if (births.size() > biology::max_cellular_tick_lives)
|
||||
@@ -133,21 +131,20 @@ CellularSessionBatchBuilder::append(std::uint64_t tick,
|
||||
return std::unexpected{CellularSessionBatchError::duplicate_birth};
|
||||
for (const auto& previous_tick : batch_.ticks)
|
||||
if (std::ranges::any_of(previous_tick.births, [&](const auto& previous) {
|
||||
return previous.account == birth.account ||
|
||||
previous.identity == birth.identity;
|
||||
return previous.account == birth.account || previous.identity == birth.identity;
|
||||
}))
|
||||
return std::unexpected{CellularSessionBatchError::duplicate_birth};
|
||||
}
|
||||
|
||||
auto next = CellularLives::restore(working_->snapshot(), working_->world(),
|
||||
working_->region(), working_->frame(), working_->tick());
|
||||
auto next = CellularLives::restore(working_->snapshot(), working_->world(), working_->region(),
|
||||
working_->frame(), working_->tick());
|
||||
if (!next || !(*next)->advance_tick(prepared->intents.lives))
|
||||
return std::unexpected{CellularSessionBatchError::biology};
|
||||
|
||||
for (const auto& birth : prepared->intents.births) {
|
||||
const LifeRequest request{birth.account, birth.request};
|
||||
const LifeAllocation allocation{birth.identity, birth.identity, birth.identity,
|
||||
birth.identity, {tick}};
|
||||
const LifeAllocation allocation{
|
||||
birth.identity, birth.identity, birth.identity, birth.identity, {tick}};
|
||||
auto created = (*next)->birth_candidate(request, allocation);
|
||||
if (!created)
|
||||
return std::unexpected{CellularSessionBatchError::invalid_birth};
|
||||
|
||||
@@ -36,8 +36,8 @@ PostgresActionLedger::find_record(const network::AccountId& account, std::uint64
|
||||
auto* db = db_->get();
|
||||
if (!db)
|
||||
return std::unexpected(network::ActionLedgerError::unavailable);
|
||||
const auto found = persistence::find_region_action_record(
|
||||
*db, key_, *lease, account.bytes, action_id, timeout_);
|
||||
const auto found = persistence::find_region_action_record(*db, key_, *lease, account.bytes,
|
||||
action_id, timeout_);
|
||||
if (!found.has_value()) {
|
||||
const auto kind = found.error().kind;
|
||||
if (kind == persistence::LeaseStoreError::store ||
|
||||
@@ -54,8 +54,7 @@ PostgresActionLedger::find_record(const network::AccountId& account, std::uint64
|
||||
std::nullopt};
|
||||
if (row.cellular_input) {
|
||||
const auto input = network::decode_cellular_action_input(*row.cellular_input);
|
||||
if (!input || input->tick != row.action.tick ||
|
||||
result != network::ActionResult::committed)
|
||||
if (!input || input->tick != row.action.tick || result != network::ActionResult::committed)
|
||||
return std::unexpected(network::ActionLedgerError::unavailable);
|
||||
std::array<std::uint8_t, network::cellular_action_input_bytes> canonical{};
|
||||
std::ranges::copy(*row.cellular_input, canonical.begin());
|
||||
@@ -66,8 +65,7 @@ PostgresActionLedger::find_record(const network::AccountId& account, std::uint64
|
||||
return std::optional<network::DurableActionRecord>{std::move(record)};
|
||||
}
|
||||
|
||||
std::expected<std::vector<std::optional<network::DurableActionRecord>>,
|
||||
network::ActionLedgerError>
|
||||
std::expected<std::vector<std::optional<network::DurableActionRecord>>, network::ActionLedgerError>
|
||||
PostgresActionLedger::find_all_records(std::span<const network::ActionKey> keys) {
|
||||
std::vector<std::optional<network::DurableActionRecord>> out(keys.size());
|
||||
if (keys.empty())
|
||||
@@ -97,10 +95,10 @@ PostgresActionLedger::find_all_records(std::span<const network::ActionKey> keys)
|
||||
continue;
|
||||
const auto& row = *(*found)[i];
|
||||
const auto result = static_cast<network::ActionResult>(row.result);
|
||||
network::DurableActionRecord record{
|
||||
network::ActionOutcome{keys[i].action_id, result, row.action.tick,
|
||||
row.action.commit_sequence},
|
||||
std::nullopt};
|
||||
network::DurableActionRecord record{network::ActionOutcome{keys[i].action_id, result,
|
||||
row.action.tick,
|
||||
row.action.commit_sequence},
|
||||
std::nullopt};
|
||||
if (row.cellular_input) {
|
||||
const auto input = network::decode_cellular_action_input(*row.cellular_input);
|
||||
if (!input || input->tick != row.action.tick ||
|
||||
|
||||
@@ -98,11 +98,11 @@ void cellular_actions_keep_exact_retry_identity() {
|
||||
|
||||
const auto carried = queue.carry(11);
|
||||
CHECK(carried.size() == 1 && carried.front().kind == ActionKind::cellular);
|
||||
CHECK(carried.front().cellular_input == encode_cellular_action_input(
|
||||
{11, 500, 0, true, 1'000, 2'000}));
|
||||
CHECK(carried.front().cellular_input ==
|
||||
encode_cellular_action_input({11, 500, 0, true, 1'000, 2'000}));
|
||||
const auto outcome = queue.committed(carried, 3);
|
||||
CHECK(outcome.size() == 1 && outcome.front().outcome ==
|
||||
ActionOutcome{77, ActionResult::committed, 11, 3});
|
||||
CHECK(outcome.size() == 1 &&
|
||||
outcome.front().outcome == ActionOutcome{77, ActionResult::committed, 11, 3});
|
||||
CHECK(queue.admit(22, action, facts) ==
|
||||
std::optional<ActionReceipt>{ActionReceipt{77, AdmitStatus::duplicate, 10, 11}});
|
||||
CHECK(queue.admit(22, changed, facts) ==
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Profile-4 publication and recovery against the migration-backed PostgreSQL adapter.
|
||||
#include "evo/persistence/checkpoint_store.hpp"
|
||||
#include "evo/persistence/account_control_store.hpp"
|
||||
#include "evo/persistence/checkpoint_store.hpp"
|
||||
#include "evo/persistence/life_reservation_store.hpp"
|
||||
#include "evo/persistence/sha256.hpp"
|
||||
#include "evo/server/cellular_region_host.hpp"
|
||||
@@ -26,8 +26,8 @@ std::string env(const char* name) {
|
||||
return value;
|
||||
}
|
||||
auto connect_as(const std::string& user) {
|
||||
auto db = Postgres::connect(
|
||||
{env("PGHOST"), {}, env("PGPORT"), env("PGDATABASE"), user, {}, {}}, 5s);
|
||||
auto db =
|
||||
Postgres::connect({env("PGHOST"), {}, env("PGPORT"), env("PGDATABASE"), user, {}, {}}, 5s);
|
||||
CHECK(db);
|
||||
return std::move(*db);
|
||||
}
|
||||
@@ -65,8 +65,8 @@ void cellular_birth_publication_is_durable() {
|
||||
CHECK(primitive);
|
||||
auto habitat = CellularHabitat::create({key.world, key.region, 1, 1'000, 1'000, {}});
|
||||
CHECK(habitat);
|
||||
auto opening = CellularLives::create(**primitive, std::move(*habitat),
|
||||
{{1'000, 1'000}, 0, 293'150});
|
||||
auto opening =
|
||||
CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 0, 293'150});
|
||||
CHECK(opening && (*opening)->lives().empty());
|
||||
auto objects = FilesystemObjectStore::open(env("PGHOST"), key, max_cellular_lives_bytes);
|
||||
CHECK(objects);
|
||||
@@ -75,8 +75,14 @@ void cellular_birth_publication_is_durable() {
|
||||
CHECK(genesis);
|
||||
CHECK(owner->query("INSERT INTO evolution.life_allocators VALUES(9758,1000)", {}, 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);
|
||||
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));
|
||||
@@ -86,8 +92,8 @@ void cellular_birth_publication_is_durable() {
|
||||
const auto authority = host->authority();
|
||||
CHECK(authority);
|
||||
const auto account = filled<16>(0x47);
|
||||
const auto control = claim_account_control(*runtime, key, *authority, account, 1, 1,
|
||||
20'000ms, 5s);
|
||||
const auto control =
|
||||
claim_account_control(*runtime, key, *authority, account, 1, 1, 20'000ms, 5s);
|
||||
CHECK(control);
|
||||
const auto requested = host->create_primitive_life(account, control->generation, 7);
|
||||
CHECK(requested.result == evo::network::PrimitiveLifeResult::pending &&
|
||||
@@ -99,8 +105,8 @@ void cellular_birth_publication_is_durable() {
|
||||
CellularBatch batch;
|
||||
const auto predecessor_digest = sha256(host->committed()->manifest);
|
||||
CHECK(predecessor_digest);
|
||||
batch.header = {key.world, key.region, 1, host->committed()->head.commit,
|
||||
*predecessor_digest, 0, 1};
|
||||
batch.header = {key.world, key.region, 1, host->committed()->head.commit,
|
||||
*predecessor_digest, 0, 1};
|
||||
CellularTickIntents tick;
|
||||
tick.births.push_back(reservation);
|
||||
batch.ticks.push_back(tick);
|
||||
@@ -109,25 +115,23 @@ void cellular_birth_publication_is_durable() {
|
||||
(*candidate)->lives()[0].identity.life == reservation.identity);
|
||||
auto published = host->publish(batch);
|
||||
CHECK(published && published->committed.head.sequence == 1 &&
|
||||
host->state()->snapshot() == (*candidate)->snapshot() &&
|
||||
host->queued_births().empty());
|
||||
host->state()->snapshot() == (*candidate)->snapshot() && host->queued_births().empty());
|
||||
const auto host_outcome = host->query_primitive_life(account, control->generation, 7);
|
||||
CHECK(host_outcome.result == evo::network::PrimitiveLifeResult::born &&
|
||||
host_outcome.life_identity == reservation.identity &&
|
||||
host_outcome.commit_sequence == 1);
|
||||
const auto outcome = query_primitive_life(*runtime, key, *authority, account,
|
||||
control->generation, 7, 5s);
|
||||
host_outcome.life_identity == reservation.identity && host_outcome.commit_sequence == 1);
|
||||
const auto outcome =
|
||||
query_primitive_life(*runtime, key, *authority, account, control->generation, 7, 5s);
|
||||
CHECK(outcome && outcome->has_value() && (*outcome)->published &&
|
||||
(*outcome)->published->identity == reservation.identity &&
|
||||
(*outcome)->published->born == 1);
|
||||
host->drain();
|
||||
host.reset();
|
||||
|
||||
auto restarted_objects = FilesystemObjectStore::open(env("PGHOST"), key,
|
||||
max_cellular_lives_bytes);
|
||||
auto restarted_objects =
|
||||
FilesystemObjectStore::open(env("PGHOST"), key, max_cellular_lives_bytes);
|
||||
CHECK(restarted_objects);
|
||||
auto restarted_made = CellularRegionHost::create(config, connect,
|
||||
std::move(*restarted_objects));
|
||||
auto restarted_made =
|
||||
CellularRegionHost::create(config, connect, std::move(*restarted_objects));
|
||||
CHECK(restarted_made);
|
||||
auto restarted = std::move(*restarted_made);
|
||||
CHECK(restarted->step().ready && restarted->state()->tick() == 1 &&
|
||||
@@ -145,35 +149,39 @@ void run_cellular_publication_tests() {
|
||||
{}, 5s));
|
||||
|
||||
constexpr RegionKey empty_key{9757, 1};
|
||||
auto empty_nursery = PrimitiveLives::create({empty_key.world, empty_key.region, 1, 17, {},
|
||||
{{0, 0}}});
|
||||
auto empty_nursery =
|
||||
PrimitiveLives::create({empty_key.world, empty_key.region, 1, 17, {}, {{0, 0}}});
|
||||
CHECK(empty_nursery);
|
||||
auto empty_habitat = evo::biology::CellularHabitat::create(
|
||||
{empty_key.world, empty_key.region, 1, 1'000, 1'000,
|
||||
{empty_key.world,
|
||||
empty_key.region,
|
||||
1,
|
||||
1'000,
|
||||
1'000,
|
||||
{{{0, 0}, 19, {{12'000}, {{{10}, {20}, {30}, {40}}}}}}});
|
||||
CHECK(empty_habitat);
|
||||
auto empty_opening = CellularLives::create(**empty_nursery, std::move(*empty_habitat),
|
||||
{{1'000, 1'000}, 0, 293'150});
|
||||
{{1'000, 1'000}, 0, 293'150});
|
||||
CHECK(empty_opening && (*empty_opening)->lives().empty());
|
||||
auto empty_objects = FilesystemObjectStore::open(env("PGHOST"), empty_key,
|
||||
max_cellular_lives_bytes);
|
||||
auto empty_objects =
|
||||
FilesystemObjectStore::open(env("PGHOST"), empty_key, max_cellular_lives_bytes);
|
||||
CHECK(empty_objects);
|
||||
const auto empty_commit = filled<16>(0x20);
|
||||
auto provisioned = provision_cellular_region(*owner, **empty_objects, empty_key, 1,
|
||||
**empty_opening, empty_commit, build, 5s);
|
||||
**empty_opening, empty_commit, build, 5s);
|
||||
CHECK(provisioned && provisioned->head.sequence == 0 && provisioned->head.end_tick == 0);
|
||||
auto empty_manifest = decode_manifest(provisioned->manifest);
|
||||
CHECK(empty_manifest && empty_manifest->profile == CheckpointProfile::cellular_lives_v1 &&
|
||||
empty_manifest->payload_bytes == (*empty_opening)->snapshot().size());
|
||||
auto genesis_payload = (*empty_objects)->get(
|
||||
{empty_manifest->payload_sha256, empty_manifest->payload_bytes});
|
||||
auto genesis_payload =
|
||||
(*empty_objects)->get({empty_manifest->payload_sha256, empty_manifest->payload_bytes});
|
||||
CHECK(genesis_payload);
|
||||
auto restored_genesis = restore_cellular_payload(*genesis_payload, *empty_manifest);
|
||||
CHECK(restored_genesis && (*restored_genesis)->lives().empty() &&
|
||||
(*restored_genesis)->nursery() == (*empty_opening)->nursery() &&
|
||||
(*restored_genesis)->habitat().snapshot() == (*empty_opening)->habitat().snapshot());
|
||||
auto exact_retry = provision_cellular_region(*owner, **empty_objects, empty_key, 1,
|
||||
**empty_opening, empty_commit, build, 5s);
|
||||
**empty_opening, empty_commit, build, 5s);
|
||||
CHECK(exact_retry && exact_retry->manifest == provisioned->manifest);
|
||||
CHECK(!provision_cellular_region(*owner, **empty_objects, empty_key, 1, **empty_opening,
|
||||
filled<16>(0x22), build, 5s));
|
||||
@@ -190,19 +198,18 @@ void run_cellular_publication_tests() {
|
||||
founder.account = filled<16>(0x43);
|
||||
founder.action = 7;
|
||||
CHECK((*primitive)->spawn(founder, {1, 101, 201, 301, {0}}));
|
||||
auto habitat = evo::biology::CellularHabitat::create(
|
||||
{key.world, key.region, 1, 1'000, 1'000, {}});
|
||||
auto habitat =
|
||||
evo::biology::CellularHabitat::create({key.world, key.region, 1, 1'000, 1'000, {}});
|
||||
CHECK(habitat);
|
||||
auto opening = CellularLives::create(**primitive, std::move(*habitat),
|
||||
{{1'000, 1'000}, 0, 293'150});
|
||||
auto opening =
|
||||
CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 0, 293'150});
|
||||
CHECK(opening && (*opening)->lives().size() == 1);
|
||||
|
||||
const auto payload = (*opening)->snapshot();
|
||||
const auto payload_digest = sha256(payload);
|
||||
CHECK(payload_digest);
|
||||
const auto genesis = genesis_manifest(key, 1, filled<16>(0x21), 50'000, build,
|
||||
payload.size(), *payload_digest,
|
||||
CheckpointProfile::cellular_lives_v1);
|
||||
const auto genesis = genesis_manifest(key, 1, filled<16>(0x21), 50'000, build, payload.size(),
|
||||
*payload_digest, CheckpointProfile::cellular_lives_v1);
|
||||
CHECK(genesis);
|
||||
const auto genesis_bytes = encode_manifest(*genesis);
|
||||
CHECK(genesis_bytes);
|
||||
@@ -211,8 +218,14 @@ void run_cellular_publication_tests() {
|
||||
CHECK(owner->query("SELECT evolution.provision_region_checkpoint($1::bytea)",
|
||||
std::array{hex(*genesis_bytes)}, 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);
|
||||
return Postgres::connect({env("PGHOST"),
|
||||
{},
|
||||
env("PGPORT"),
|
||||
env("PGDATABASE"),
|
||||
env("EVO_PG_RUNTIME_USER"),
|
||||
{},
|
||||
{}},
|
||||
5s);
|
||||
};
|
||||
CellularHostConfig config{key, 1, {}, build, {build}};
|
||||
auto made_host = CellularRegionHost::create(config, connect, std::move(*objects));
|
||||
@@ -222,8 +235,8 @@ void run_cellular_publication_tests() {
|
||||
CellularBatch batch;
|
||||
const auto predecessor_digest = sha256(host->committed()->manifest);
|
||||
CHECK(predecessor_digest);
|
||||
batch.header = {key.world, key.region, 1, host->committed()->head.commit,
|
||||
*predecessor_digest, 0, 2};
|
||||
batch.header = {key.world, key.region, 1, host->committed()->head.commit,
|
||||
*predecessor_digest, 0, 2};
|
||||
batch.ticks.resize(2);
|
||||
for (auto& tick : batch.ticks)
|
||||
tick.lives.push_back({(*opening)->lives()[0].identity.life, {}});
|
||||
@@ -238,16 +251,15 @@ void run_cellular_publication_tests() {
|
||||
CHECK(published && published->committed.head.sequence == 1 &&
|
||||
published->committed.head.end_tick == 2 &&
|
||||
host->state()->snapshot() == (**replay).snapshot());
|
||||
CHECK(host->take_finalized_actions() ==
|
||||
std::vector<FinalCellularAction>{{action, 1}});
|
||||
CHECK(host->take_finalized_actions() == std::vector<FinalCellularAction>{{action, 1}});
|
||||
host->drain();
|
||||
host.reset();
|
||||
|
||||
auto restarted_objects = FilesystemObjectStore::open(env("PGHOST"), key,
|
||||
max_cellular_lives_bytes);
|
||||
auto restarted_objects =
|
||||
FilesystemObjectStore::open(env("PGHOST"), key, max_cellular_lives_bytes);
|
||||
CHECK(restarted_objects);
|
||||
auto made_restarted = CellularRegionHost::create(config, connect,
|
||||
std::move(*restarted_objects));
|
||||
auto made_restarted =
|
||||
CellularRegionHost::create(config, connect, std::move(*restarted_objects));
|
||||
CHECK(made_restarted);
|
||||
auto restarted = std::move(*made_restarted);
|
||||
CHECK(restarted->step().ready && restarted->state()->tick() == 2 &&
|
||||
|
||||
@@ -90,8 +90,7 @@ void refusal_never_returns_partial_tick_state() {
|
||||
CHECK(result);
|
||||
CHECK(result->begin_tick == 4 && result->end_tick == 5);
|
||||
CHECK(result->lives.empty() && result->starved.size() == 1);
|
||||
CHECK(result->starved[0] ==
|
||||
CellularCorpseCandidate{2, {0, 0}, {{7}, {{{2}, {3}, {4}, {5}}}}});
|
||||
CHECK(result->starved[0] == CellularCorpseCandidate{2, {0, 0}, {{7}, {{{2}, {3}, {4}, {5}}}}});
|
||||
CHECK(result->heat_released.value == 17);
|
||||
CHECK(result->patches.empty());
|
||||
CHECK(map->patches()[0].stock == Inventory{{5}, {{{2}, {2}, {2}, {2}}}});
|
||||
|
||||
@@ -30,8 +30,7 @@ accounting::Inventory founder_price(std::uint64_t count) {
|
||||
}
|
||||
|
||||
void actions_bind_to_owned_life_and_preserve_other_inputs() {
|
||||
auto primitive = PrimitiveLives::create(
|
||||
{90, 1, 7, 17, founder_price(2), {{0, 0}, {20, 0}}});
|
||||
auto primitive = PrimitiveLives::create({90, 1, 7, 17, founder_price(2), {{0, 0}, {20, 0}}});
|
||||
CHECK(primitive);
|
||||
LifeRequest request{};
|
||||
request.account.back() = 1;
|
||||
@@ -50,8 +49,8 @@ void actions_bind_to_owned_life_and_preserve_other_inputs() {
|
||||
{{15'000, 15'000}, 30, {{10}, {{{10}, {10}, {10}, {10}}}}}}};
|
||||
auto habitat = biology::CellularHabitat::create(std::move(habitat_config));
|
||||
CHECK(habitat);
|
||||
auto state = CellularLives::create(**primitive, std::move(*habitat),
|
||||
{{20'000, 20'000}, 1, 293'150});
|
||||
auto state =
|
||||
CellularLives::create(**primitive, std::move(*habitat), {{20'000, 20'000}, 1, 293'150});
|
||||
CHECK(state && (*state)->lives().size() == 2);
|
||||
|
||||
const auto& controlled = (*state)->lives()[0];
|
||||
@@ -71,8 +70,7 @@ void actions_bind_to_owned_life_and_preserve_other_inputs() {
|
||||
CellularLifeIntent{controlled.identity.life,
|
||||
{{-3, 4}, biology::CellularPatchAddress{0, 0}}});
|
||||
CHECK(prepared->intents.lives[1] == baseline[1]);
|
||||
CHECK(prepared->actions[0] ==
|
||||
CellularActionRecord{controlled.account, 77, input});
|
||||
CHECK(prepared->actions[0] == CellularActionRecord{controlled.account, 77, input});
|
||||
|
||||
const auto guessed_input =
|
||||
network::encode_cellular_action_input({2, 0, 0, true, 15'000, 15'000});
|
||||
@@ -127,8 +125,9 @@ void actions_bind_to_owned_life_and_preserve_other_inputs() {
|
||||
|
||||
CHECK(prepare_cellular_session_tick(**state, 3, baseline, actions).error() ==
|
||||
CellularSessionBatchError::tick);
|
||||
CHECK(prepare_cellular_session_tick(**state, 2, std::span{baseline}.first(1), actions).error() ==
|
||||
CellularSessionBatchError::intents);
|
||||
CHECK(
|
||||
prepare_cellular_session_tick(**state, 2, std::span{baseline}.first(1), actions).error() ==
|
||||
CellularSessionBatchError::intents);
|
||||
|
||||
const std::array duplicate{action, action};
|
||||
CHECK(prepare_cellular_session_tick(**state, 2, baseline, duplicate).error() ==
|
||||
@@ -150,8 +149,8 @@ void builder_batches_reserved_birth_after_empty_tick() {
|
||||
CHECK(primitive);
|
||||
auto habitat = biology::CellularHabitat::create({93, 1, 1, 1'000, 1'000, {}});
|
||||
CHECK(habitat);
|
||||
auto state = CellularLives::create(**primitive, std::move(*habitat),
|
||||
{{1'000, 1'000}, 0, 293'150});
|
||||
auto state =
|
||||
CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 0, 293'150});
|
||||
CHECK(state && (*state)->lives().empty());
|
||||
persistence::RegionHead head{};
|
||||
head.frame = 1;
|
||||
|
||||
@@ -161,9 +161,8 @@ void store_rules() {
|
||||
auto found = find_region_action(*db, r.key, *lease, alice, 1, 5s);
|
||||
CHECK(found && *found == CommittedAction{131, 3, 1});
|
||||
const auto found_record = find_region_action_record(*db, r.key, *lease, alice, 1, 5s);
|
||||
CHECK(found_record && *found_record ==
|
||||
CommittedActionRecord{CommittedAction{131, 3, 1}, 1, 1,
|
||||
std::nullopt});
|
||||
CHECK(found_record &&
|
||||
*found_record == CommittedActionRecord{CommittedAction{131, 3, 1}, 1, 1, std::nullopt});
|
||||
CHECK(holds(find_region_action(*db, r.key, *lease, bob, 1, 5s),
|
||||
std::optional{CommittedAction{131, 3, 1}}));
|
||||
CHECK(holds(find_region_action(*db, r.key, *lease, alice, 2, 5s),
|
||||
|
||||
@@ -411,13 +411,15 @@ void cellular_profile() {
|
||||
CHECK(primitive);
|
||||
auto habitat = CellularHabitat::create({7, 3, 9, 1'000, 1'000, {}});
|
||||
CHECK(habitat);
|
||||
auto owner = CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 0, 293'150});
|
||||
auto owner =
|
||||
CellularLives::create(**primitive, std::move(*habitat), {{1'000, 1'000}, 0, 293'150});
|
||||
CHECK(owner && (*owner)->lives().empty() && (*owner)->tick() == 0);
|
||||
|
||||
const auto payload = (*owner)->snapshot();
|
||||
auto manifest = genesis_manifest(key, 9, filled<16>(0x02), 50000, build, payload.size(),
|
||||
filled<32>(0xA2), CheckpointProfile::cellular_lives_v1);
|
||||
CHECK(manifest && supported(*manifest) && manifest->history_profile == cellular_history_profile &&
|
||||
CHECK(manifest && supported(*manifest) &&
|
||||
manifest->history_profile == cellular_history_profile &&
|
||||
manifest->cellular_versions == cellular_v1_versions &&
|
||||
max_payload_bytes(CheckpointProfile::cellular_lives_v1) == max_cellular_lives_bytes);
|
||||
const auto encoded = encode_manifest(*manifest);
|
||||
@@ -425,9 +427,9 @@ void cellular_profile() {
|
||||
const auto restored = restore_cellular_payload(payload, *manifest);
|
||||
CHECK(restored && (*restored)->snapshot() == payload);
|
||||
CHECK(!restore_primitive_payload(payload, *manifest));
|
||||
const auto successor = successor_manifest(*manifest, filled<32>(0xA5), filled<16>(0x04),
|
||||
lease(), 1, build, payload.size(),
|
||||
filled<32>(0xA6), batch_for(1, 1));
|
||||
const auto successor =
|
||||
successor_manifest(*manifest, filled<32>(0xA5), filled<16>(0x04), lease(), 1, build,
|
||||
payload.size(), filled<32>(0xA6), batch_for(1, 1));
|
||||
CHECK(successor && supported(*successor) &&
|
||||
successor->cellular_versions == cellular_v1_versions);
|
||||
auto short_cellular_trace = *successor;
|
||||
|
||||
@@ -188,8 +188,8 @@ void cellular_publisher_adapter_rejects_malformed_requests() {
|
||||
const std::vector<std::uint8_t> empty;
|
||||
auto published = publish_cellular_checkpoint(*db, empty, empty, empty, empty, 5s);
|
||||
CHECK(failed(published, LeaseStoreError::invalid));
|
||||
auto resolved = resolve_cellular_region_commit(*db, {1, 999}, id(0xC1), empty, empty, empty,
|
||||
empty, 5s);
|
||||
auto resolved =
|
||||
resolve_cellular_region_commit(*db, {1, 999}, id(0xC1), empty, empty, empty, empty, 5s);
|
||||
CHECK(failed(resolved, LeaseStoreError::invalid));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user