singular-registry
LicenseApache-2.0
Safe HaskellNone
LanguageGHC2021

Singular.Registry.FoldSelection

Description

Pull request 1 of #518 judges every pending request alone and settles one per fold. This module is the pure selection: it takes the pending requests, the live facts, the clock and a capacity bound as arguments and returns, for every pending request, exactly one of settled or excluded-with-reason. It reads no file, no clock and no provider, and imports no command-line module and no application module, so both the command line and the conformance suite can use it.

The seven checks run in the spec's order; the first one a request fails names its reason:

  1. it decodes as a request, otherwise undecodable
  2. its edge is one the model admits, otherwise edge-inadmissible
  3. its processing window is open beyond the fold margin, otherwise window-closed
  4. the model's approval check accepts it, otherwise no-approval or approval-mismatch
  5. the model's leaf check accepts it from the live state, otherwise key-exists, token-missing, key-unknown, not-booked or terminal-immutable
  6. the application step's verdict carried on the request is ready, otherwise application-datum-unreadable or application-required
  7. no earlier included request names the same key, otherwise key-in-batch

Requests that pass all seven keep ledger input order; the first ones up to the capacity bound are settled and each remaining one is named capacity. The window rule mirrors the command line's processing-window rule: open only while the time left is beyond the margin. The approval and leaf checks follow the model's refusal order: excluded edges first, then approval, then the leaf from the live state.

Synopsis

Documentation

data EdgeKind Source #

The edge a pending request names. Only the two edges the model admits settle; any other edge is refused edge-inadmissible.

Instances

Instances details
Show EdgeKind Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

showsPrec :: Int -> EdgeKind -> ShowS Source #

show :: EdgeKind -> String Source #

showList :: [EdgeKind] -> ShowS Source #

Eq EdgeKind Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

(==) :: EdgeKind -> EdgeKind -> Bool Source #

(/=) :: EdgeKind -> EdgeKind -> Bool Source #

data Leaf Source #

The live leaf for a key, read from the registry state before the decision.

Instances

Instances details
Show Leaf Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

showsPrec :: Int -> Leaf -> ShowS Source #

show :: Leaf -> String Source #

showList :: [Leaf] -> ShowS Source #

Eq Leaf Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

(==) :: Leaf -> Leaf -> Bool Source #

(/=) :: Leaf -> Leaf -> Bool Source #

data ApprovalCheck Source #

The model's approval check, decided by the caller from the live state: a missing approval, an approval under another policy (both no-approval), an approval whose tuple does not match (approval-mismatch), or a match.

Instances

Instances details
Show ApprovalCheck Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

showsPrec :: Int -> ApprovalCheck -> ShowS Source #

show :: ApprovalCheck -> String Source #

showList :: [ApprovalCheck] -> ShowS Source #

Eq ApprovalCheck Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

(==) :: ApprovalCheck -> ApprovalCheck -> Bool Source #

(/=) :: ApprovalCheck -> ApprovalCheck -> Bool Source #

data AppVerdict Source #

The application step's verdict, asked through the application value and carried on the pending request: the settlement inputs are ready, the carried datum does not read, or the value carries no holding rules for a termination, naming the application's executable.

Instances

Instances details
Show AppVerdict Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

showsPrec :: Int -> AppVerdict -> ShowS Source #

show :: AppVerdict -> String Source #

showList :: [AppVerdict] -> ShowS Source #

Eq AppVerdict Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

(==) :: AppVerdict -> AppVerdict -> Bool Source #

(/=) :: AppVerdict -> AppVerdict -> Bool Source #

data PendingRequest Source #

One pending request with everything the seven checks need. The application verdict arrives as a field, like the decode verdict does: the selection never calls the application value.

Constructors

PendingRequest 

Fields

Instances

Instances details
Show PendingRequest Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

showsPrec :: Int -> PendingRequest -> ShowS Source #

show :: PendingRequest -> String Source #

showList :: [PendingRequest] -> ShowS Source #

Eq PendingRequest Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

(==) :: PendingRequest -> PendingRequest -> Bool Source #

(/=) :: PendingRequest -> PendingRequest -> Bool Source #

data SelectedRequest Source #

A request that passed all seven checks.

Constructors

SelectedRequest 

Fields

Instances

Instances details
Show SelectedRequest Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

showsPrec :: Int -> SelectedRequest -> ShowS Source #

show :: SelectedRequest -> String Source #

showList :: [SelectedRequest] -> ShowS Source #

Eq SelectedRequest Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

(==) :: SelectedRequest -> SelectedRequest -> Bool Source #

(/=) :: SelectedRequest -> SelectedRequest -> Bool Source #

data Reason Source #

Every exclusion reason: eight model refusals in the model's own words, six selection-policy reasons of the processor.

Instances

Instances details
Bounded Reason Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

minBound :: Reason Source #

maxBound :: Reason Source #

Enum Reason Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

succ :: Reason -> Reason Source #

pred :: Reason -> Reason Source #

toEnum :: Int -> Reason Source #

fromEnum :: Reason -> Int Source #

enumFrom :: Reason -> [Reason] Source #

enumFromThen :: Reason -> Reason -> [Reason] Source #

enumFromTo :: Reason -> Reason -> [Reason] Source #

enumFromThenTo :: Reason -> Reason -> Reason -> [Reason] Source #

Show Reason Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

showsPrec :: Int -> Reason -> ShowS Source #

show :: Reason -> String Source #

showList :: [Reason] -> ShowS Source #

Eq Reason Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

(==) :: Reason -> Reason -> Bool Source #

(/=) :: Reason -> Reason -> Bool Source #

data Exclusion Source #

Why a pending request is left out: its reason and a detail text. The detail of application-required names the application's executable.

Constructors

Exclusion 

Fields

Instances

Instances details
Show Exclusion Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

showsPrec :: Int -> Exclusion -> ShowS Source #

show :: Exclusion -> String Source #

showList :: [Exclusion] -> ShowS Source #

Eq Exclusion Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

(==) :: Exclusion -> Exclusion -> Bool Source #

(/=) :: Exclusion -> Exclusion -> Bool Source #

data Selection Source #

The selection: the settled requests and the excluded requests, each in ledger input order, with the capacity bound used and its provenance.

Instances

Instances details
Show Selection Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

showsPrec :: Int -> Selection -> ShowS Source #

show :: Selection -> String Source #

showList :: [Selection] -> ShowS Source #

Eq Selection Source # 
Instance details

Defined in Singular.Registry.FoldSelection

Methods

(==) :: Selection -> Selection -> Bool Source #

(/=) :: Selection -> Selection -> Bool Source #

type LiveFacts = Map Int (Leaf, Bool) Source #

The live facts: per key, the leaf and whether a live output holds the key's one active token.

selectFold :: Int -> Integer -> Integer -> LiveFacts -> [PendingRequest] -> Selection Source #

Judge every pending request alone, keep ledger input order, and settle the first included requests up to the capacity bound. The only cross-request rule is the seventh check, which reads earlier included requests of the same key; the capacity cut runs after every request has its own verdict. Both lists keep ledger input order.

judgeAlone :: Integer -> Integer -> LiveFacts -> PendingRequest -> Either Exclusion SelectedRequest Source #

Judge one request alone against the live facts: the six per-request checks in the spec's order. No argument names any other pending request, so a request's verdict never depends on requests on other keys. The seventh check, ReasonKeyInBatch, needs the earlier verdicts and runs in selectFold.

foldCapacity :: Int Source #

The capacity bound of a fold: nine requests per fold, an estimate under preprod's execution budget of 14 million memory units, bound by trie-proof verification. The number is not measured under preprod parameters.

foldCapacityProvenance :: Text Source #

an estimate, not a measurement: about nine requests fit in a fold under preprod's execution budget of 14 million memory units, bound by trie-proof verification

exclusionName :: Exclusion -> Text Source #

The reason's name in the receipt's vocabulary.

exclusionSource :: Exclusion -> Text Source #

Which vocabulary the reason belongs to: a refusal of the model or the processor's own selection policy.