pub struct Engine { /* private fields */ }Expand description
The engine: answers the value of a cell as of a time. See the crate documentation.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn builder(
store: Arc<dyn Store + Send + Sync>,
host: impl Into<String>,
) -> EngineBuilder
pub fn builder( store: Arc<dyn Store + Send + Sync>, host: impl Into<String>, ) -> EngineBuilder
A builder for an engine on store, signing as the mesh host.
Sourcepub fn set_accepted_licences(&self, licences: BTreeSet<String>)
pub fn set_accepted_licences(&self, licences: BTreeSet<String>)
Replaces the set of accepted restricted licences (engine 0.6.1, E1), for the next
request: a long-running serve or mcp picks up an acceptance made by another process
this way. Safe to call from any thread. It waits for a running evaluation to finish, then
drops the memo (its answers were judged under the old set), so a memoised answer whose
licence the new set no longer gives is refused, not answered (see
EngineBuilder::accepted_licences).
Sourcepub fn get(
&self,
cell: &CellRef,
asof: Option<&str>,
) -> Result<Answer, EngineError>
pub fn get( &self, cell: &CellRef, asof: Option<&str>, ) -> Result<Answer, EngineError>
The value of the cell cell denotes, as of asof (else cell.asof, else now).
The function name resolves as of the asof; with no binding then, the answer is
Answer::NotCovered. See the crate documentation for the answers and errors.
Past or current (CONTRACT-guard-patch G10): a read with no asof is current; a named asof
earlier than the clock at the call’s start is a past read, which stores nothing but slice
definitions (when store_past_reads is off). For a request fixed before it is evaluated, see
get_cell_current.
Sourcepub fn resolve(
&self,
cell: &CellRef,
asof: Option<&str>,
) -> Result<Option<Cell>, EngineError>
pub fn resolve( &self, cell: &CellRef, asof: Option<&str>, ) -> Result<Option<Cell>, EngineError>
The cell cell denotes, its function name resolved as of asof (else cell.asof,
else now), as get resolves it; None when the name has no binding
then (SPEC 5.5 E_NAME_UNBOUND: it may be bound later), where get answers
Answer::NotCovered. With the cell, get_cell answers as get
would. Malformed requests are the errors get gives. Since 0.3.2.
Sourcepub fn get_cell(
&self,
cell: &Cell,
asof: Option<&str>,
) -> Result<Answer, EngineError>
pub fn get_cell( &self, cell: &Cell, asof: Option<&str>, ) -> Result<Answer, EngineError>
The value of cell (its function pinned by fn_hash), as of asof (else now). The
form for a reference that already carries the function hash. An unknown function
hash is Answer::NotCovered.
Sourcepub fn get_cell_current(
&self,
cell: &Cell,
arrival: &str,
) -> Result<Answer, EngineError>
pub fn get_cell_current( &self, cell: &Cell, arrival: &str, ) -> Result<Answer, EngineError>
The value of cell as of arrival, a current read whatever the clock reads when it is
evaluated: it stores as a current read does (its version and its member-set row, as of the
arrival), though the clock has moved on (CONTRACT-guard-patch G10; the mesh’s requests pin
their arrival). get_cell with a named asof before the clock is a past read instead.
Sourcepub fn stored_version_added(&self, cell_id: &str)
pub fn stored_version_added(&self, cell_id: &str)
Tells the engine that a stored version of cell_id was added: the memoised answers
that depend on the cell are dropped.
Since 0.3.0 also the answers that read a slice the cell falls into (a late sample, a correction, a new member), and nothing else: when some memoised answer read a slice over a stored function (or an evaluation is running), the engine reads the cell’s latest receipt from the store to match it against their patterns. If that read fails, every answer that read such a slice is dropped.
Sourcepub fn manifest_asof(
&self,
entry: &str,
asof: &str,
) -> Result<Option<Vec<u8>>, EngineError>
pub fn manifest_asof( &self, entry: &str, asof: &str, ) -> Result<Option<Vec<u8>>, EngineError>
The manifest of the slice entry entry as of asof (CONTRACT-guard-patch G5, G10): the held
bytes when a manifest is stored, else the members rebuilt from the slice’s definition as of
asof (the canonical bytes a stored manifest holds). Nothing is stored. Ok(None) when no
manifest is held and the mesh has no definition of the slice (or the entry is malformed).
Errors: BudgetExceeded over the fuel; Invalid when the members do not hash to the
entry’s members hash, or a member cannot be listed (a false asof is refused, not guessed).
Sourcepub fn manifest_asof_until(
&self,
entry: &str,
asof: &str,
deadline: Instant,
) -> Result<Option<Vec<u8>>, EngineError>
pub fn manifest_asof_until( &self, entry: &str, asof: &str, deadline: Instant, ) -> Result<Option<Vec<u8>>, EngineError>
manifest_asof with a deadline (CONTRACT-guard-patch, the time budget of
a request, DATUMESH_BUDGET_MS): BudgetExceeded once deadline has passed, checked before and
after the listing and while listing or hashing the members. Nothing is stored.
Sourcepub fn resolver_for(&self, asof: &str) -> ReceiptResolver<'_>
pub fn resolver_for(&self, asof: &str) -> ReceiptResolver<'_>
The resolver for one receipt being verified, whose asof is the receipt’s (R2): the public
Resolver of the engine, with a manifest held, else the rebuild from the member-set row,
else the rebuild as of this asof (so a receipt with no row, such as a past read’s, verifies).
Nothing is stored. The engine’s own Resolver keeps its row-only answer.
Sourcepub fn clear_memo(&self)
pub fn clear_memo(&self)
Drops every memoised answer.
Sourcepub fn memo_stats(&self) -> MemoStats
pub fn memo_stats(&self) -> MemoStats
Sizes of the memo and of the dirty set.
Source§impl Engine
impl Engine
Sourcepub fn whatif(
&self,
cell: &CellRef,
asof: Option<&str>,
overrides: &Overrides,
solve: Option<&Solve>,
) -> Result<ScenarioAnswer, EngineError>
pub fn whatif( &self, cell: &CellRef, asof: Option<&str>, overrides: &Overrides, solve: Option<&Solve>, ) -> Result<ScenarioAnswer, EngineError>
The value of cell as of asof (else cell.asof, else now) with overrides in place.
With solve, vary is first set to the value that makes its target equal its equals
(bisection within its interval; see Solve), and cell’s value is then that under the
solved vary; the answer’s solved says what was found.
The overridden cells answer their values; a slice override changes a stored slice’s
members. A cell that does not depend on the overrides answers from the memo and the
store as get would; a dependent cell is evaluated in the request’s scope.
Nothing is written: no receipt, computed version, memo entry or signature. The answer
is labelled a scenario, not a fact.
Errors: EngineError::Override for overrides that are not valid (or more than 64),
EngineError::NotCovered when the cell has no value (a fault in scope included), and
EngineError::WhatifNoSolution for a solve without a solution or out of fuel. The
usual request errors (asof, arguments, unlicensed, budget) are those of get.
Trait Implementations§
Source§impl Resolver for Engine
impl Resolver for Engine
Source§fn manifest(&self, entry: &str) -> Option<Cow<'_, [u8]>>
fn manifest(&self, entry: &str) -> Option<Cow<'_, [u8]>>
The manifest of a slice entry, from the store (the engine stores the manifest of every slice its receipts and evaluations read).
Source§fn evaluate(&self, cell: &Cell, asof: &str) -> Option<Scalar>
fn evaluate(&self, cell: &Cell, asof: &str) -> Option<Scalar>
The value of cell as of asof by the engine’s answering rule (a receipt answers at
A when its tx and its asof are both at or before A): a stored cell’s is looked up; a
computed cell’s function is evaluated (its inputs answered as for get, and stored
when new), never read back from its own receipts. None when there is none or the
evaluation fails (logged with tracing, target datumesh_engine).
Source§fn evaluation(&self, cell: &Cell, asof: &str) -> Option<Evaluation>
fn evaluation(&self, cell: &Cell, asof: &str) -> Option<Evaluation>
evaluate’s value with, for a computed cell, its lineage: the
inputs entries the evaluation read (receipt hashes and slice entries, whose receipts
and manifests the engine serves), so that a verifier can report E_INPUT_SUPERSEDED
(SPEC 10.1 step 7.6). A stored cell’s has none.
Source§fn descriptor(&self, fn_hash: &str) -> Option<Cow<'_, [u8]>>
fn descriptor(&self, fn_hash: &str) -> Option<Cow<'_, [u8]>>
fn_hash, or None if unavailable
(E_FN_UNAVAILABLE). Only None is unavailability: the text is parsed strictly
(unparseable text reports its parse code), and any other JSON value, null included,
is a descriptor offered that fails the hash check (E_FN_HASH_MISMATCH, SPEC 10.1
step 7.1).