Bind durable mutation reservations to cellular ticks
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (checks) (push) Failing after 3m58s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (client) (push) Canceled after 6m18s
Foundation / checks (postgres) (push) Canceled after 2m23s
Foundation / checks (network) (push) Canceled after 4m19s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m56s
Foundation / checks (checks) (push) Failing after 3m58s
Foundation / checks (tsan) (push) Canceled after 0s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (client) (push) Canceled after 6m18s
Foundation / checks (postgres) (push) Canceled after 2m23s
Foundation / checks (network) (push) Canceled after 4m19s
This commit is contained in:
@@ -144,6 +144,95 @@ void actions_bind_to_owned_life_and_preserve_other_inputs() {
|
||||
CellularSessionBatchError::action);
|
||||
}
|
||||
|
||||
void durable_mutation_reservations_bind_to_the_exact_offer() {
|
||||
auto primitive = PrimitiveLives::create({93, 1, 1, 17, founder_price(1), {{0, 0}}});
|
||||
CHECK(primitive);
|
||||
LifeRequest request{};
|
||||
request.account.back() = 3;
|
||||
request.action = 1;
|
||||
CHECK((*primitive)->spawn(request, {1, 101, 201, 301, {1}}));
|
||||
accounting::Inventory stock{{1'000'000'000'000ULL},
|
||||
{{{1'000'000'000'000ULL},
|
||||
{1'000'000'000'000ULL},
|
||||
{1'000'000'000'000ULL},
|
||||
{1'000'000'000'000ULL}}}};
|
||||
auto habitat = biology::CellularHabitat::create(
|
||||
{93, 1, 1, 1'000, 1'000, {{{0, 0}, 29, stock}}});
|
||||
CHECK(habitat);
|
||||
auto created = CellularLives::create(**primitive, std::move(*habitat),
|
||||
{{1'000, 1'000}, 1, 293'150});
|
||||
CHECK(created && (*created)->lives().size() == 1);
|
||||
auto& owner = **created;
|
||||
const auto life_id = owner.lives()[0].identity.life;
|
||||
bool offered = false;
|
||||
for (std::size_t tick = 0; tick < 10'000 && !offered; ++tick) {
|
||||
const std::array intent{CellularLifeIntent{life_id, {{0, 0}, {{0, 0}}}}};
|
||||
CHECK(owner.advance_tick(intent));
|
||||
const auto current_offer = owner.mutation_offer(life_id);
|
||||
CHECK(current_offer);
|
||||
offered = current_offer->has_value();
|
||||
}
|
||||
CHECK(offered);
|
||||
auto revision_owner = owner.migrate_to_v3();
|
||||
CHECK(revision_owner);
|
||||
const auto offer = (*revision_owner)->mutation_offer(life_id);
|
||||
CHECK(offer && *offer && !(*offer)->candidates.empty());
|
||||
const auto& live = (*revision_owner)->lives()[0];
|
||||
const auto action_tick = (*revision_owner)->tick() + 1;
|
||||
const auto& candidate = (*offer)->candidates.front();
|
||||
persistence::CellularMutationReservation reservation;
|
||||
reservation.account = live.account;
|
||||
reservation.action_id = 42;
|
||||
reservation.region = (*revision_owner)->region();
|
||||
reservation.generation = 7;
|
||||
reservation.target_tick = action_tick;
|
||||
reservation.successor_identity = 999;
|
||||
const auto put_field = [&](std::size_t offset, std::uint64_t value, std::size_t bytes) {
|
||||
for (std::size_t i = 0; i < bytes; ++i)
|
||||
reservation.input[offset + i] = static_cast<std::uint8_t>(value >> (i * 8U));
|
||||
};
|
||||
put_field(0, action_tick, 8);
|
||||
put_field(8, life_id, 8);
|
||||
put_field(16, live.mutation.event_index, 8);
|
||||
put_field(24, live.mutation.offer_tick, 8);
|
||||
put_field(32, candidate.operator_id, 2);
|
||||
|
||||
persistence::RegionHead head{};
|
||||
head.frame = (*revision_owner)->frame();
|
||||
head.sequence = 3;
|
||||
head.end_tick = (*revision_owner)->tick();
|
||||
head.commit.fill(0x31);
|
||||
head.digest.fill(0x41);
|
||||
auto builder = CellularSessionBatchBuilder::create(**revision_owner, head);
|
||||
CHECK(builder);
|
||||
const std::array baseline{CellularLifeIntent{life_id, {}}};
|
||||
const std::array reservations{reservation};
|
||||
CHECK(builder->append(action_tick, baseline, {}, {}, reservations));
|
||||
const CellularMutationActionRecord expected_action{
|
||||
live.account, reservation.action_id, action_tick,
|
||||
{life_id, live.mutation.event_index, live.mutation.offer_tick, candidate.operator_id}};
|
||||
CHECK(builder->batch().ticks.back().mutations ==
|
||||
std::vector{CellularMutationSelection{life_id, live.mutation.event_index,
|
||||
live.mutation.offer_tick,
|
||||
reservation.successor_identity,
|
||||
candidate.operator_id}} &&
|
||||
builder->mutation_actions().size() == 1 &&
|
||||
builder->mutation_actions().front() == expected_action &&
|
||||
match_cellular_mutation_actions_to_trace(**revision_owner, builder->batch(),
|
||||
builder->mutation_actions()));
|
||||
const auto replayed = replay_cellular_batch(**revision_owner, builder->batch());
|
||||
CHECK(replayed && (*replayed)->snapshot() == builder->candidate().snapshot());
|
||||
|
||||
auto stale_builder = CellularSessionBatchBuilder::create(**revision_owner, head);
|
||||
CHECK(stale_builder);
|
||||
auto stale = reservation;
|
||||
stale.input[24] ^= 1U;
|
||||
const std::array stale_reservations{stale};
|
||||
CHECK(stale_builder->append(action_tick, baseline, {}, {}, stale_reservations).error() ==
|
||||
CellularSessionBatchError::mutation);
|
||||
CHECK(stale_builder->candidate().snapshot() == (*revision_owner)->snapshot());
|
||||
}
|
||||
|
||||
void builder_batches_reserved_birth_after_empty_tick() {
|
||||
auto primitive = PrimitiveLives::create({93, 1, 1, 17, founder_price(1), {{0, 0}}});
|
||||
CHECK(primitive);
|
||||
@@ -181,6 +270,7 @@ void builder_batches_reserved_birth_after_empty_tick() {
|
||||
|
||||
int main() try {
|
||||
actions_bind_to_owned_life_and_preserve_other_inputs();
|
||||
durable_mutation_reservations_bind_to_the_exact_offer();
|
||||
builder_batches_reserved_birth_after_empty_tick();
|
||||
std::puts("cellular session batch: ok");
|
||||
} catch (const std::exception& e) {
|
||||
|
||||
Reference in New Issue
Block a user