pub struct SpendJournal { /* private fields */ }Expand description
A persistent spend journal. Clones share it.
Implementations§
Source§impl SpendJournal
impl SpendJournal
Sourcepub fn open(
path: impl AsRef<Path>,
kind: BudgetKind,
clock: Arc<dyn SpendClock>,
) -> Result<Self, JournalError>
pub fn open( path: impl AsRef<Path>, kind: BudgetKind, clock: Arc<dyn SpendClock>, ) -> Result<Self, JournalError>
Open the journal at path, creating it with a header for kind if
it does not exist. Migrates a testing header that names the
superseded cap (see the module documentation). Refuses a journal of
another budget, cap or schema, a journal another writer holds, and
complete lines that do not parse.
pub fn budget(&self) -> BudgetKind
pub fn path(&self) -> &Path
Sourcepub fn write_failures(&self) -> u64
pub fn write_failures(&self) -> u64
Lines that could not be written after a reservation (settlements, reconciliations, releases). Each leaves the journal counting more, never less.
Sourcepub fn reserve(
&self,
attempt_id: &str,
units: u64,
) -> Result<Reservation, SpendRefusal>
pub fn reserve( &self, attempt_id: &str, units: u64, ) -> Result<Reservation, SpendRefusal>
Reserve units for attempt_id in the current period, durably, or
refuse. Refused means: do not send.
Sourcepub fn settle(&self, r: Reservation, charge: Charge)
pub fn settle(&self, r: Reservation, charge: Charge)
Settle a reservation with the attempt’s charge: observed and
estimated charges replace it; unknown keeps it as liability.
Sourcepub fn release(&self, r: Reservation)
pub fn release(&self, r: Reservation)
Release a reservation whose request was never sent.
Sourcepub fn reconcile(&self, seq: u64, observed_units: u64) -> bool
pub fn reconcile(&self, seq: u64, observed_units: u64) -> bool
A later observed charge for a reservation held as liability (spec 003, 3.5.5). False when it holds none.
Sourcepub fn reconcile_billing(
&self,
journal_credential_reference: &str,
billing: &BillingSettlement,
) -> Result<(), Unresolved>
pub fn reconcile_billing( &self, journal_credential_reference: &str, billing: &BillingSettlement, ) -> Result<(), Unresolved>
Spec 022: settle production liability only from a provider billing line for the journal’s credential and the reservation’s own month. The host must retain the billing line as evidence; no credential value is accepted or recorded here.
Sourcepub fn summary(&self) -> SpendSummary
pub fn summary(&self) -> SpendSummary
The totals of the current period.
Sourcepub fn run_spend(&self, run_id: &str) -> u64
pub fn run_spend(&self, run_id: &str) -> u64
Committed units for attempt ids starting with live/<run_id>/.
Counts observed, estimated, liability and outstanding amounts across
periods; released reservations contribute nothing. Replayed reservation
state at open preserves this total across a restart.
Sourcepub fn reservations_for(&self, decision_id: &str) -> Vec<String>
pub fn reservations_for(&self, decision_id: &str) -> Vec<String>
Runtime attempt ids in reservation sequence order, including releases.
Sourcepub fn reservations_detail(&self, decision_id: &str) -> Vec<CaseSpend>
pub fn reservations_detail(&self, decision_id: &str) -> Vec<CaseSpend>
Reservation evidence for exactly this decision, in journal sequence order. Unsettled and crash liability remain unknown, never an inferred charge.
pub fn run_split(&self, run_id: &str) -> RunSpend
Sourcepub fn testing_header_digest() -> ContentDigest
pub fn testing_header_digest() -> ContentDigest
Schema-tagged digest of the serialized testing header, including newline.
Sourcepub fn superseded_testing_header_digest() -> ContentDigest
pub fn superseded_testing_header_digest() -> ContentDigest
Self::testing_header_digest of a testing journal under the
superseded cap, before its header was migrated (A-75).
Sourcepub fn runtime_cost_policy(&self) -> CostPolicy
pub fn runtime_cost_policy(&self) -> CostPolicy
The cost policy for a runtime’s shared ledger holding the current
headroom: estimates are reserved, so an attempt that does not fit is
recorded budget_exhausted{cost} by the runtime before it reaches
the adapter (spec 003, 3.5.3). The journal’s own check stays as the
backstop.
A runtime shared ledger seeded with the current headroom, for
RuntimeBuilder::shared_ledger.