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:
@@ -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 ||
|
||||
|
||||
Reference in New Issue
Block a user