Add cellular durable action record lookup
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 40s
Foundation / checks (ecs) (push) Successful in 1m50s
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 (postgres) (push) Canceled after 26s
Foundation / checks (network) (push) Canceled after 1m49s
Foundation / checks (client) (push) Canceled after 2m29s

This commit is contained in:
dingo
2026-10-10 23:05:10 -04:00
parent c607c032b9
commit 08519b66af
13 changed files with 341 additions and 9 deletions
@@ -1,5 +1,7 @@
#include "evo/server/postgres_action_ledger.hpp"
#include <algorithm>
namespace evo::server {
std::expected<std::optional<network::ActionOutcome>, network::ActionLedgerError>
PostgresActionLedger::find(const network::AccountId& account, std::uint64_t action_id) {
@@ -26,6 +28,95 @@ PostgresActionLedger::find(const network::AccountId& account, std::uint64_t acti
record.value().tick, record.value().commit_sequence}};
}
std::expected<std::optional<network::DurableActionRecord>, network::ActionLedgerError>
PostgresActionLedger::find_record(const network::AccountId& account, std::uint64_t action_id) {
const auto lease = lease_();
if (!lease)
return std::unexpected(network::ActionLedgerError::unavailable);
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_);
if (!found.has_value()) {
const auto kind = found.error().kind;
if (kind == persistence::LeaseStoreError::store ||
kind == persistence::LeaseStoreError::unknown)
db_->broken();
return std::unexpected(network::ActionLedgerError::unavailable);
}
if (!found.value())
return std::optional<network::DurableActionRecord>{};
const auto& row = *found.value();
const auto result = static_cast<network::ActionResult>(row.result);
network::DurableActionRecord record{
network::ActionOutcome{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 ||
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());
record.cellular_input = canonical;
} else if (result != network::ActionResult::committed_no_effect) {
return std::unexpected(network::ActionLedgerError::unavailable);
}
return std::optional<network::DurableActionRecord>{std::move(record)};
}
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())
return out;
const auto lease = lease_();
if (!lease)
return std::unexpected(network::ActionLedgerError::unavailable);
auto* db = db_->get();
if (!db)
return std::unexpected(network::ActionLedgerError::unavailable);
std::vector<persistence::ActionRef> refs;
refs.reserve(keys.size());
for (const auto& key : keys)
refs.push_back({key.account.bytes, key.action_id});
const auto found = persistence::find_region_action_records(*db, key_, *lease, refs, timeout_);
if (!found.has_value()) {
const auto kind = found.error().kind;
if (kind == persistence::LeaseStoreError::store ||
kind == persistence::LeaseStoreError::unknown)
db_->broken();
return std::unexpected(network::ActionLedgerError::unavailable);
}
if (found->size() != keys.size())
return std::unexpected(network::ActionLedgerError::unavailable);
for (std::size_t i = 0; i < keys.size(); ++i) {
if (!(*found)[i])
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};
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)
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());
record.cellular_input = canonical;
} else if (result != network::ActionResult::committed_no_effect) {
return std::unexpected(network::ActionLedgerError::unavailable);
}
out[i] = std::move(record);
}
return out;
}
std::expected<std::vector<std::optional<network::ActionOutcome>>, network::ActionLedgerError>
PostgresActionLedger::find_all(std::span<const network::ActionKey> keys) {
const auto lease = lease_();