Wire M10.8c-1 region handoff: protocol v4, durable probes, crossing, ghosts
Foundation / checks (deploy) (push) Successful in 3m29s
Foundation / checks (ecs) (push) Successful in 2m0s
Foundation / checks (client) (push) Successful in 12m51s
Foundation / checks (network) (push) Successful in 13m0s
Foundation / checks (tsan) (push) Successful in 7m50s
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 32m4s
Foundation / checks (postgres) (push) Canceled after 19m13s

ADR-0096. Session protocol v4 (v3 is deployed and frozen) adds HandoffOffer,
SessionRedirect, close reasons handed_off and moved, and ghost marker records.
Sessions use the durable probe record: logins open it where it was saved
(redirected when it lives elsewhere), and session ends save it. A marker
crossing into a neighbour's area is frozen, prepared, its control released
and a signed ticket offered; uncommitted transfers are aborted after the
ticket's lifetime. The destination shows arriving probes as ghosts (schema
v13 incoming_probe_transfers) and opens the marker where it crossed.

Refreshes the dev session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-06 21:24:42 -04:00
co-authored by Claude Opus 5.5
parent 97a3756e46
commit a7a3d12283
39 changed files with 1315 additions and 68 deletions
+37 -3
View File
@@ -363,12 +363,12 @@ void session_codec() {
mutated.at(0) ^= 1;
CHECK(refused(decode_session(mutated), SessionCodecError::bad_magic));
mutated = bytes;
mutated.at(4) = 4; // A future version.
mutated.at(4) = 5; // A future version.
CHECK(refused(decode_session(mutated), SessionCodecError::unsupported_version));
mutated = bytes;
mutated.at(7) = 1;
CHECK(refused(decode_session(mutated), SessionCodecError::reserved_flags));
for (const auto type : std::array<std::uint8_t, 3>{0, 16, 255}) {
for (const auto type : std::array<std::uint8_t, 3>{0, 18, 255}) {
mutated = bytes;
mutated.at(6) = type;
CHECK(refused(decode_session(mutated), SessionCodecError::unknown_type));
@@ -377,7 +377,7 @@ void session_codec() {
CHECK(std::get<SessionWelcome>(*decode_session(encode_session(welcome))) == welcome);
CHECK(std::get<SessionHello>(*decode_session(encode_session(SessionHello{0, grant}))).grant ==
grant);
for (const auto reason : std::array<std::uint8_t, 4>{0, 14, 200, 255}) {
for (const auto reason : std::array<std::uint8_t, 4>{0, 16, 200, 255}) {
auto close = encode_session(SessionClose{SessionCloseReason::protocol});
close.back() = reason;
CHECK(refused(decode_session(close), SessionCodecError::invalid_value));
@@ -708,11 +708,45 @@ void handoff_tickets() {
CHECK(control.open(dev.verified(claims(alice, 4)), now + 2));
}
// Session protocol v4 (ADR-0096): HandoffOffer and SessionRedirect.
void handoff_codec() {
HandoffOffer offer;
offer.transfer.fill(0x5C);
offer.destination = {12, "void.aeternalisgames.com:7402", "dev-region.evolution.test"};
offer.ticket.fill(0xA1);
const auto bytes = encode_session(offer);
const auto decoded = decode_session(bytes);
CHECK(decoded && std::get<HandoffOffer>(*decoded) == offer);
const SessionRedirect redirect{{12, "10.0.0.2:7400", "region-12.test"}};
const auto r = decode_session(encode_session(redirect));
CHECK(r && std::get<SessionRedirect>(*r) == redirect);
CHECK(decode_session(encode_session(SessionClose{SessionCloseReason::handed_off})));
CHECK(decode_session(encode_session(SessionClose{SessionCloseReason::moved})));
auto beyond = encode_session(SessionClose{SessionCloseReason::moved});
beyond.back() = static_cast<std::uint8_t>(SessionCloseReason::moved) + 1;
CHECK(refused(decode_session(beyond), SessionCodecError::invalid_value));
// Text fields: printable, no spaces, padded with zeros; region and transfer nonzero.
for (const auto& bad : {RegionAddress{12, "has space:1", "n"}, RegionAddress{12, "", "n"},
RegionAddress{0, "h:1", "n"}, RegionAddress{12, "h:1", ""}})
CHECK(refused(decode_session(encode_session(SessionRedirect{bad})),
SessionCodecError::invalid_value));
auto padded = encode_session(redirect);
padded.at(session_header_bytes + 8 + 20) = 'x'; // A byte after the endpoint's end.
CHECK(refused(decode_session(padded), SessionCodecError::invalid_value));
auto zero = offer;
zero.transfer.fill(0);
CHECK(refused(decode_session(encode_session(zero)), SessionCodecError::invalid_value));
auto longer = bytes;
longer.push_back(0);
CHECK(refused(decode_session(longer), SessionCodecError::wrong_length));
}
void control_tests() {
grants();
identity_adapter();
control_rules();
handoff_tickets();
handoff_codec();
session_codec();
intent_admission();
durable_actions();
+48 -1
View File
@@ -306,7 +306,7 @@ void replicated_markers() {
const auto second = encode_record(m, -7, &area);
two_own.insert(two_own.end(), second.begin(), second.end());
auto bad_flag = encode_record(m, -7, nullptr);
bad_flag.back() = 2;
bad_flag.back() = 3; // 0 other, 1 own, 2 ghost (v4).
m.state.vector = {2000, 0};
const auto bad_vector = encode_record(m, -7, nullptr);
m = {};
@@ -316,6 +316,52 @@ void replicated_markers() {
CHECK(refused(c.accept(SnapshotChunk{5, ++t, 0, 0, 0, 0, -7, 0, 1, records}),
AssemblyError::malformed));
}
// Ghosts (ADR-0096): read-only markers of probes being handed to this region, stable per
// transfer, replicated as kind 2 to every session whose square holds them; frozen markers
// neither move nor take intentions; place and open_at clamp into the area.
void ghosts_and_freezing() {
ProbeMarkers m;
CHECK(m.set_area(area, 0, 0));
const auto own = m.open_at(1, 9'000'000, 100);
CHECK(own && m.of(1)->state.x == 5'000'000 && m.of(1)->state.y == 100);
m.place(1, -9'000'000, 7);
CHECK(m.of(1)->state == State{-5'000'000, 7, {}});
CHECK(m.schedule(1, 1, 5, {1000, 0}));
m.freeze(1);
CHECK(m.of(1)->frozen && refused(m.schedule(1, 2, 6, {1000, 0}), motion::MarkerError::invalid));
m.advance(10);
CHECK(m.of(1)->state.x == -5'000'000); // Frozen: the scheduled motion never happened.
motion::Ghost g{};
g.transfer.fill(0x61);
g.x = 100'000;
m.set_ghosts(std::span{&g, 1});
const auto ghost_id = std::ranges::find_if(m.markers(), &motion::Marker::ghost)->id;
m.set_ghosts(std::span{&g, 1}); // Same transfer, same id.
CHECK(std::ranges::count_if(m.markers(), &motion::Marker::ghost) == 1 &&
std::ranges::find_if(m.markers(), &motion::Marker::ghost)->id == ghost_id &&
!m.of(0)); // Ghosts belong to no session.
// Through replication and the codec: kind 2, not own.
constexpr world::WorldIdentity identity{11, 12};
auto made = ReplicationServer::create({});
CHECK(made);
auto server = std::move(*made);
CHECK(server.open(1, 5) && server.set_interest(1, {0, 0, -7, 7}));
const auto out = server.tick(1,
[&](const SessionInterest&) {
ReplicationSource s;
s.identity = identity;
s.markers = m.markers();
s.marker_area = m.area();
return s;
},
{});
SnapshotAssembler a{identity, 5};
CHECK(!deliver(a, chunks_of(out, 1)).empty());
const auto* seen = marker(a, ghost_id);
CHECK(seen && seen->ghost && !seen->own && seen->state.x == 100'000);
m.set_ghosts({});
CHECK(std::ranges::none_of(m.markers(), &motion::Marker::ghost));
}
} // namespace
void motion_tests() {
@@ -325,5 +371,6 @@ void motion_tests() {
predictor_rules();
smoothing_and_lead();
replicated_markers();
ghosts_and_freezing();
}
} // namespace evo::network_test
+2 -2
View File
@@ -121,8 +121,8 @@ void codec_v2() {
SnapshotChunk chunk{5, 9, 7, 3, 4, mask, -7, 1, 2, {1, 2, 3}};
auto bytes = encode_session(chunk);
CHECK(std::get<SnapshotChunk>(*decode_session(bytes)) == chunk);
// Versions 1 and 2 (frozen, deployed) are no longer accepted (v3, ADR-0094).
for (const std::uint8_t old : {std::uint8_t{1}, std::uint8_t{2}}) {
// Versions 1-3 (frozen, deployed) are no longer accepted (v4, ADR-0096).
for (const std::uint8_t old : {std::uint8_t{1}, std::uint8_t{2}, std::uint8_t{3}}) {
auto previous = encode_session(ack);
previous.at(4) = old;
CHECK(refused(decode_session(previous), SessionCodecError::unsupported_version));
+14 -2
View File
@@ -188,6 +188,14 @@ void ownership_and_happy_path(World& w) {
CHECK(state_of(stage_probe_transfer(db, w.b, w.lb, t1, 5s)) == TransferState::staged);
CHECK(state_of(stage_probe_transfer(db, w.b, w.lb, t1, 5s)) == TransferState::staged);
CHECK(failed(commit_probe_transfer(db, w.c, w.lc, t1, 5s), ProbeStoreError::fenced));
// Schema v13: the destination sees the open transfer addressed to it (for a ghost).
const auto incoming = incoming_probe_transfers(db, w.b, w.lb, 5s);
CHECK(incoming && incoming->size() == 1 && incoming->front().transfer == t1 &&
incoming->front().account == alice && incoming->front().source == 1 &&
incoming->front().x == 700'000);
CHECK(incoming_probe_transfers(db, w.c, w.lc, 5s)
.value_or(std::vector<IncomingTransfer>{1})
.empty());
// The one switch: owner B, next generation, the frozen final state, same inventory.
const auto committed = commit_probe_transfer(db, w.b, w.lb, t1, 5s);
CHECK(state_of(committed) == TransferState::committed);
@@ -199,6 +207,9 @@ void ownership_and_happy_path(World& w) {
CHECK(stage_probe_transfer(db, w.b, w.lb, t1, 5s) == *committed);
CHECK(prepare_probe_transfer(db, w.a, w.la, alice, 1, t1, 2, 0, 0, 0, 5s) == *committed);
CHECK(abort_probe_transfer(db, w.a, w.la, t1, 5s) == *committed);
CHECK(incoming_probe_transfers(db, w.b, w.lb, 5s)
.value_or(std::vector<IncomingTransfer>{1})
.empty()); // Decided transfers are no longer incoming.
const auto found = find_probe_transfer(db, w.c, w.lc, t1, 5s);
CHECK(found && *found == std::optional{*committed});
const auto missing = find_probe_transfer(db, w.c, w.lc, id(0x7F), 5s);
@@ -396,12 +407,13 @@ void handoff_ledger(World& w) {
ticket.source = 1;
ticket.destination = 2;
const auto admitted = ledger.admit(ticket, 41);
CHECK(admitted && admitted->generation == 2 && admitted->wait == 0ms);
CHECK(admitted && admitted->lease.generation == 2 && admitted->lease.wait == 0ms &&
admitted->generation == 2 && admitted->x == 3 && admitted->y == 4);
const auto r = w.open(w.b, w.lb, frank);
CHECK(r.region == 2 && r.generation == 2 && r.x == 3 && !r.transfer);
// A retried login after an undecided outcome converges (control moves on again).
const auto again = ledger.admit(ticket, 42);
CHECK(again && again->generation == 3);
CHECK(again && again->lease.generation == 3);
// Refusals: another account, an unknown transfer, an aborted transfer; no lease.
auto wrong = ticket;
wrong.account.bytes = id(0x48);
+319 -4
View File
@@ -6,6 +6,7 @@
#include "evo/network/dev_credentials.hpp"
#include "evo/network/handoff_ticket.hpp"
#include "evo/network/session_grant.hpp"
#include "evo/server/probe_ledger.hpp"
#include "evo/server/region_sessions.hpp"
#include <algorithm>
#include <chrono>
@@ -14,6 +15,7 @@
#include <filesystem>
#include <fstream>
#include <functional>
#include <map>
#include <optional>
#include <source_location>
#include <stdexcept>
@@ -311,7 +313,7 @@ void login_rules(const Files& f) {
CHECK(raw_peer(h, std::nullopt) == Reason::timeout);
CHECK(raw_peer(h, std::vector<std::uint8_t>{1, 2, 3}) == Reason::protocol);
auto future = encode_session(SessionHello{0, h.issuer.grant(carol, 2, start + 60)});
future.at(4) = 4;
future.at(4) = 5;
CHECK(raw_peer(h, future) == Reason::unsupported_version);
CHECK(raw_peer(h, encode_session(SessionClose{Reason::client_closed})) == Reason::protocol);
CHECK(raw_peer(h, encode_session(SessionHello{1, h.issuer.grant(carol, 3, start + 60)})) ==
@@ -552,12 +554,13 @@ void snapshots_over_quic(const Files& f) {
// M10.8b: a Hello carrying a handoff ticket (ADR-0096) instead of a grant.
struct FakeHandoff final : HandoffLedger {
std::expected<ControlLease, HandoffLedgerError> admit(const TicketClaims& ticket,
std::uint64_t session) override {
std::expected<HandoffAdmission, HandoffLedgerError> admit(const TicketClaims& ticket,
std::uint64_t session) override {
if (error)
return std::unexpected(*error);
admitted.emplace_back(ticket, session);
return ControlLease{100 + admitted.size(), {}, std::chrono::milliseconds{20000}};
return HandoffAdmission{
ControlLease{100 + admitted.size(), {}, std::chrono::milliseconds{20000}}, 2, 0, 0};
}
std::optional<HandoffLedgerError> error;
std::vector<std::pair<TicketClaims, std::uint64_t>> admitted;
@@ -625,6 +628,317 @@ void ticket_login(const Files& f) {
CHECK(a->state() == RegionSessionState::established && handoff.admitted.size() == 1);
}
// M10.8c (ADR-0096): two regions with adjacent areas in one process, over a fake world
// database with the same transfer state machine as schema v12.
struct WorldDb {
struct Probe {
std::uint64_t owner{}, generation{};
std::int64_t x{}, y{};
std::optional<TransferId> transfer;
};
enum class State : std::uint8_t { prepared, committed, aborted };
struct Transfer {
AccountId account;
std::uint64_t source{}, destination{}, generation{};
std::int64_t x{}, y{};
State state{};
};
std::map<AccountId, Probe> probes;
std::map<TransferId, Transfer> transfers;
};
struct RegionDb final : server::ProbeLedger, HandoffLedger, ControlLedger {
RegionDb(WorldDb& w, std::uint64_t r) : world{&w}, region{r} {}
std::expected<server::ProbeHome, server::ProbeLedgerError>
open(const AccountId& account, std::int64_t x, std::int64_t y, std::int64_t) override {
auto [it, created] =
world->probes.try_emplace(account, WorldDb::Probe{region, 1, x, y, std::nullopt});
const auto& p = it->second;
return server::ProbeHome{p.owner, p.generation, p.x, p.y, p.transfer.has_value()};
}
void save(const AccountId& account, std::uint64_t generation, std::int64_t x, std::int64_t y,
std::int64_t) override {
auto& p = world->probes.at(account);
if (p.owner == region && p.generation == generation && !p.transfer) {
p.x = x;
p.y = y;
++saves;
}
}
std::expected<void, server::ProbeLedgerError>
prepare(const AccountId& account, std::uint64_t generation, const TransferId& transfer,
std::uint64_t destination, std::int64_t x, std::int64_t y, std::int64_t) override {
auto& p = world->probes.at(account);
if (p.owner != region || p.generation != generation || p.transfer)
return std::unexpected(server::ProbeLedgerError::unavailable);
p.transfer = transfer;
p.x = x;
p.y = y;
world->transfers[transfer] = {
account, region, destination, generation, x, y, WorldDb::State::prepared};
return {};
}
std::expected<bool, server::ProbeLedgerError> abort(const TransferId& transfer) override {
auto& t = world->transfers.at(transfer);
if (t.state == WorldDb::State::prepared) {
t.state = WorldDb::State::aborted;
world->probes.at(t.account).transfer.reset();
}
return t.state == WorldDb::State::aborted;
}
std::expected<std::vector<server::IncomingProbe>, server::ProbeLedgerError>
incoming() override {
std::vector<server::IncomingProbe> out;
for (const auto& [id, t] : world->transfers)
if (t.destination == region && t.state == WorldDb::State::prepared)
out.push_back({id, t.x, t.y});
return out;
}
std::expected<HandoffAdmission, HandoffLedgerError> admit(const TicketClaims& ticket,
std::uint64_t) override {
const auto found = world->transfers.find(ticket.transfer);
if (found == world->transfers.end() || found->second.destination != region ||
found->second.account != ticket.account ||
found->second.state == WorldDb::State::aborted)
return std::unexpected(HandoffLedgerError::refused);
auto& t = found->second;
auto& p = world->probes.at(t.account);
if (t.state == WorldDb::State::prepared) { // Stage and commit: the switch.
t.state = WorldDb::State::committed;
p = {region, t.generation + 1, t.x, t.y, std::nullopt};
}
return HandoffAdmission{ControlLease{++control, {}, std::chrono::milliseconds{20000}},
p.generation, p.x, p.y};
}
std::expected<ControlLease, ControlLedgerError> claim(const AccountId&, std::uint64_t,
std::uint64_t) override {
return ControlLease{++control, {}, std::chrono::milliseconds{20000}};
}
std::expected<std::chrono::milliseconds, ControlLedgerError> renew(const AccountId&,
std::uint64_t) override {
return std::chrono::milliseconds{20000};
}
void release(const AccountId&, std::uint64_t) override {
++releases;
}
WorldDb* world;
std::uint64_t region;
std::uint64_t control{}, saves{}, releases{};
};
constexpr std::int64_t m_um = 1'000'000; // One metre (one cell) in micrometres.
// Region `id` owns x in [x0, x0 + 10 m), y in [0, 10 m) of slice 0.
network::motion::Area area_of(std::int64_t x0) {
return {x0, 0, x0 + (10 * m_um) - 1, (10 * m_um) - 1, 0};
}
struct Region {
Region(const Files& f, std::uint64_t id, std::int64_t x0, WorldDb& world,
std::shared_ptr<const HandoffSigningKey> key, const GrantPublicKey& neighbour_key,
std::uint64_t neighbour, std::int64_t neighbour_x0, std::uint16_t neighbour_port,
std::uint16_t own_port = 0)
: db{world, id} {
server::RegionSessionsConfig c;
c.transport.port = own_port;
c.transport.certificate_pem_file = f.certificate.string();
c.transport.key_pem_file = f.key.string();
c.control.environment = DeploymentEnvironment::dev;
c.control.world = world_id;
c.control.region = id;
c.control.epoch = 5;
c.control.max_account_attempts = 16;
c.issuer_keys.push_back({1, *Issuer{}.key.public_key()});
c.hello_deadline = std::chrono::milliseconds{2000};
c.close_flush = std::chrono::milliseconds{300};
c.ledger = &db;
c.handoff = &db;
c.probes = &db;
c.handoff_key = std::move(key);
c.handoff_keys.push_back(
{neighbour, static_cast<std::uint32_t>(neighbour + 40), neighbour_key});
c.neighbours.push_back(
{{neighbour, "127.0.0.1:" + std::to_string(neighbour_port), std::string{name}},
area_of(neighbour_x0)});
c.ticket_lifetime = 20;
c.ghost_poll = std::chrono::milliseconds{20};
auto made = RegionSessions::create(std::move(c));
CHECK(made.has_value());
sessions = std::move(*made);
CHECK(sessions->set_motion_area(area_of(x0), x0 + (5 * m_um), 5 * m_um));
sessions->set_default_interest({(x0 / m_um) + 5, 5, 0, 7});
}
void pump(std::uint64_t now_seconds) {
++tick;
sessions->poll({true, 5, tick}, now_seconds, Clock::now());
sessions->replicate(tick, [](const SessionInterest&) {
ReplicationSource s;
s.identity = world_id;
return s;
});
for (auto& e : sessions->take_events())
events.push_back(std::move(e));
}
RegionDb db;
std::unique_ptr<RegionSessions> sessions;
std::uint64_t tick{100};
std::vector<RegionSessionEvent> events;
};
void two_region_handoff(const Files& f) {
WorldDb world;
auto key1 = std::make_shared<const HandoffSigningKey>(
*HandoffSigningKey::generate(DeploymentEnvironment::dev, 41));
auto key2 = std::make_shared<const HandoffSigningKey>(
*HandoffSigningKey::generate(DeploymentEnvironment::dev, 42));
// Ports are only known once listening: region 1 dials region 2 at a port fixed below.
std::uint16_t port2 = 0;
{
// Find a free port for region 2 by binding a throwaway region first.
server::RegionSessionsConfig probe;
probe.transport.certificate_pem_file = f.certificate.string();
probe.transport.key_pem_file = f.key.string();
probe.control.environment = DeploymentEnvironment::dev;
probe.control.world = world_id;
probe.control.region = 2;
probe.control.epoch = 5;
probe.issuer_keys.push_back({1, *Issuer{}.key.public_key()});
auto made = RegionSessions::create(std::move(probe));
CHECK(made.has_value());
port2 = (*made)->port();
}
Region r1{f, 1, 0, world, key1, *key2->public_key(), 2, 10 * m_um, port2};
Region r2{f, 2, 10 * m_um, world, key2, *key1->public_key(), 1, 0, r1.sessions->port(), port2};
CHECK(r2.sessions->port() == port2);
std::uint64_t now_s = start;
Issuer issuer;
std::vector<RegionSessionClient*> clients;
const auto dial = [&](std::uint16_t port, const WireGrant& credential) {
client::RegionSessionClientConfig c;
c.transport.port = port;
c.transport.server_name = std::string{name};
c.transport.authority_pem = f.ca_pem;
c.transport.authority_pem_file = f.ca.string();
c.grant = credential;
auto made = RegionSessionClient::connect(std::move(c), Clock::now());
CHECK(made.has_value());
clients.push_back(made->get());
return std::move(*made);
};
const auto pump = [&](const std::function<bool()>& done,
std::chrono::milliseconds limit = std::chrono::milliseconds{15000}) {
const auto end = Clock::now() + limit;
while (Clock::now() < end) {
r1.pump(now_s);
r2.pump(now_s);
for (auto* c : clients)
c->poll(Clock::now());
if (done())
return true;
std::this_thread::sleep_for(std::chrono::milliseconds{2});
}
return done();
};
// Sends a held vector until the region admits it (ticks here are fast: a refused, late
// intention is simply sent again).
const auto walk = [&](RegionSessionClient& c, std::int16_t vx) {
return pump([&] {
for (const auto& r : c.take_intention_receipts())
if (r.status == AdmitStatus::admitted)
return true;
static_cast<void>(c.send_intention(c.server_tick() + 4, vx, 0));
return false;
});
};
const auto own = [](const RegionSessionClient& c) -> std::optional<ReplicatedMarker> {
if (const auto* v = c.view())
for (const auto& m : v->markers)
if (m.own)
return m;
return std::nullopt;
};
const auto alice = account(21), bob = account(22);
const auto grant = [&](const AccountId& who, std::uint64_t serial, std::uint64_t in_region) {
return issuer.grant(who, serial, start, 300, in_region);
};
// Bob watches the border from region 2.
auto b = dial(r2.sessions->port(), grant(bob, 1, 2));
CHECK(pump([&] { return b->state() == RegionSessionState::established; }));
// Alice logs in to region 1: her durable probe is created at the spawn.
auto a = dial(r1.sessions->port(), grant(alice, 1, 1));
CHECK(pump([&] { return own(*a).has_value(); }));
CHECK(must(own(*a)).state.x == 5 * m_um && world.probes.at(alice).owner == 1);
// She walks east (100 mm per tick) to the border: frozen, prepared, offered, closed.
CHECK(walk(*a, 1000));
std::optional<HandoffOffer> offer;
CHECK(pump([&] {
if (!offer)
offer = a->take_handoff();
return offer.has_value() && a->state() == RegionSessionState::closed;
}));
CHECK(a->close_reason() == SessionCloseReason::handed_off &&
must(offer).destination.region == 2 &&
must(offer).destination.endpoint == "127.0.0.1:" + std::to_string(r2.sessions->port()));
const auto& t = world.transfers.at(must(offer).transfer);
CHECK(t.state == WorldDb::State::prepared && t.x >= 10 * m_um && t.x < 11 * m_um &&
t.y == 5 * m_um && world.probes.at(alice).transfer == must(offer).transfer);
// Before the switch, Bob sees her as a read-only ghost at the transferred position.
const auto ghost = [&] {
if (const auto* v = b->view())
for (const auto& m : v->markers)
if (m.ghost && m.state.x == t.x)
return true;
return false;
};
CHECK(pump(ghost));
// Alice continues at region 2 with the ticket: no grant, her probe where it crossed.
auto a2 = dial(r2.sessions->port(), must(offer).ticket);
CHECK(pump([&] { return own(*a2).has_value(); }));
CHECK(must(own(*a2)).state.x == t.x && world.probes.at(alice).owner == 2 &&
world.probes.at(alice).generation == 2 &&
world.transfers.at(must(offer).transfer).state == WorldDb::State::committed);
CHECK(pump([&] { return !ghost(); })); // The ghost gave way to her marker.
// A login at region 1 is now redirected to region 2.
auto stale = dial(r1.sessions->port(), grant(alice, 2, 1));
CHECK(pump([&] { return stale->state() == RegionSessionState::closed; }));
CHECK(stale->close_reason() == SessionCloseReason::moved && stale->redirect() &&
must(stale->redirect()).region == 2);
// Crossing back west: region 1 owns her again, generation 3.
CHECK(walk(*a2, -1000));
std::optional<HandoffOffer> back;
CHECK(pump([&] {
if (!back)
back = a2->take_handoff();
return back.has_value() && a2->state() == RegionSessionState::closed;
}));
CHECK(must(back).destination.region == 1);
auto a3 = dial(r1.sessions->port(), must(back).ticket);
CHECK(pump([&] { return own(*a3).has_value(); }));
CHECK(world.probes.at(alice).owner == 1 && world.probes.at(alice).generation == 3 &&
must(own(*a3)).state.x < 10 * m_um);
// An abandoned handoff: Carol crosses but never arrives; after the ticket's lifetime the
// source aborts and she logs in at region 1 again, where she stopped.
const auto carol = account(23);
auto c = dial(r1.sessions->port(), grant(carol, 1, 1));
CHECK(pump([&] { return own(*c).has_value(); }));
CHECK(walk(*c, 1000));
std::optional<HandoffOffer> unused;
CHECK(pump([&] {
if (!unused)
unused = c->take_handoff();
return unused.has_value() && c->state() == RegionSessionState::closed;
}));
const auto frozen_at = world.transfers.at(must(unused).transfer).x;
CHECK(pump([&] {
++now_s; // A second per round: the ticket's lifetime and the abort deadline pass.
return !world.probes.at(carol).transfer.has_value();
}));
CHECK(world.transfers.at(must(unused).transfer).state == WorldDb::State::aborted);
auto c2 = dial(r1.sessions->port(), grant(carol, 2, 1));
CHECK(pump([&] { return own(*c2).has_value(); }));
CHECK(must(own(*c2)).state.x <= 10 * m_um - 1 && world.probes.at(carol).x == frozen_at);
// The late ticket is refused: expired by now (and its transfer aborted).
auto late = dial(r2.sessions->port(), must(unused).ticket);
CHECK(pump([&] { return late->state() == RegionSessionState::closed; }));
CHECK(late->close_reason() == SessionCloseReason::expired);
CHECK(b->state() == RegionSessionState::established && r1.db.releases > 0);
}
void durable_control(const Files& f) {
FakeLedger ledger;
Harness h{f, 4, 64, &ledger};
@@ -702,6 +1016,7 @@ int main() try {
intentions_and_actions(files);
snapshots_over_quic(files);
ticket_login(files);
two_region_handoff(files);
std::filesystem::remove_all(files.dir);
std::puts("quic session tests passed");
return 0;
+2 -1
View File
@@ -178,6 +178,7 @@ void upgrade_across_migration_and_barrier() {
" -v migration_sha_10=$(s 0010_account_control.sql)"
" -v migration_sha_11=$(s 0011_region_actions.sql)"
" -v migration_sha_12=$(s 0012_probe_handoff.sql)"
" -v migration_sha_13=$(s 0013_probe_incoming.sql)"
" -v runtime_role=evo_runtime_test -f migrations/apply.sql"
" > /dev/null 2>&1") != 0);
CHECK(history(*owner_db) == "1,2,3,4,5,6,7");
@@ -193,7 +194,7 @@ void upgrade_across_migration_and_barrier() {
CHECK(shell("PGDATABASE=" + database +
" EVO_PG_RUNTIME_ROLE=evo_runtime_test bash \"$EVO_SOURCE_ROOT/"
"tools/migrate-postgres.sh\" > /dev/null") == 0);
CHECK(history(*owner_db) == "1,2,3,4,5,6,7,8,9,10,11,12");
CHECK(history(*owner_db) == "1,2,3,4,5,6,7,8,9,10,11,12,13");
CHECK(renew_region_lease(*runtime, r.key, *lease, 20000ms, 5s));
confirm(publish_next(20)); // 41..60, now v8.
CHECK(head.head.end_tick == 60);