ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.MiniProtocol.LeiosFetch.Jobs

Description

The unit of Leios tx-fetch work: LeiosJobs and the per-EB LeiosJobPool that schedules them.

The pool's structural operations -- greedy partition, least-requested selection, multiplicity bookkeeping -- stay together here, along with the JobCommitment a job carries.

The key benefit of jobs is to minimize the bookkeeping footprint and churn.

TO BE IMPORTED QUALIFIED

Synopsis

Jobs

data LeiosJob Source #

A unit of tx-fetch work: some of an EB's txs, fetched by one MsgLeiosBlockTxsRequest.

Constructors

MkLeiosJob 

Fields

  • !IntSet

    The txs' offsets in the EB body's tx vector

    TODO the offset set is immutable and only ever fully traversed, so a packed bitfield (a strict ByteString or unboxed Word64 vector) would be more compact than the IntSet Patricia tree.

  • !Word32

    The txs' total on-the-wire byte size, for the fetch byte budget

  • !JobCommitment

    What the response is validated against

Instances

Instances details
Eq LeiosJob Source # 
Instance details

Defined in Ouroboros.Consensus.MiniProtocol.LeiosFetch.Jobs

Methods

(==) ∷ LeiosJob → LeiosJob → Bool #

(/=) ∷ LeiosJob → LeiosJob → Bool #

Show LeiosJob Source # 
Instance details

Defined in Ouroboros.Consensus.MiniProtocol.LeiosFetch.Jobs

Methods

showsPrec ∷ Int → LeiosJob → ShowS #

show ∷ LeiosJob → String #

showList ∷ [LeiosJob] → ShowS #

newtype LeiosJobId Source #

Identifies a LeiosJob within its LeiosJobPool (0-based, stable for the pool's lifetime). A point's pool is built once, so a reply for a point names only that pool's jobs.

Constructors

MkLeiosJobId Int 

newtype JobCommitment Source #

A job's commitment to which txs it covers, at which sizes: the Blake2b-256 hash of each tx's hash followed by its size in four big-endian bytes (in ascending offset order), via jobCommitmentOfTxs. It lets an arriving MsgLeiosBlockTxs be validated against the job without retaining the EB body -- crucial, since up to ~10k EBs (each up to ~600 kB) could have txs in flight at once, far too much to hold in memory.

A tx that is not the size the body declares for it fails the validation, even if it is the tx the body names. So the validation cannot tell a peer that sends the wrong tx from an endorser block that declares the wrong size for the right one: the node never notices such an endorser block, and only disconnects each peer that serves it. Separate commitments to the hashes and to the sizes would tell the two apart, but they would double the commitments' footprint in the heap, which is already non-trivial, and they would only guard against a suboptimal adversary, which could send a tx with the wrong txhash instead of with the wrong size and have wasted the same resources.

Pools

data LeiosJobPool Source #

The unfinished jobs for one acquired EB, requested or not, plus a reverse index by multiplicity so a least-requested job is one minView away.

INVARIANT: jobsByMultiplicity is the exact inverse of the multiplicities in jobs -- every job id in jobs sits in exactly the bucket named by its LeiosJobState multiplicity.

mkJobPool ∷ Word32 → Int → IntMap (TxHash, Word32) → LeiosJobPool Source #

Partition the missing txs into jobs, greedily in offset order: a job grows until adding the next tx would exceed maxJobBytes or maxJobTxCount, but always holds at least one tx (so an oversized tx would form a solo job, in the unintended case of max tx size exceeding max job size).

Each miss is its offset within the EB body mapped to its tx hash and its on-the-wire byte size. Each job's JobCommitment is computed here via jobCommitmentOfTxs over its covered txs' hashes and sizes.

The jobs are numbered from 0.

emptyJobPool ∷ LeiosJobPool Source #

The pool with no jobs -- nothing left to fetch.

nullJobPool ∷ LeiosJobPool → Bool Source #

No unfinished jobs remain -- the EB's whole tx-closure has been fetched.

lookupJob ∷ LeiosJobId → LeiosJobPool → Maybe LeiosJob Source #

The bitfield of an unfinished job, if it is still in the pool.

restrictToPending ∷ IntMap a → LeiosJobPool → IntMap a Source #

Restrict a map keyed by LeiosJobId to the jobs still unfinished in the pool, dropping entries for jobs already completeJobd. Lets the tx-arrival handler pick out, from a request's covered jobs, the ones we still need to ingest (a redundant delivery of a completed job is dropped).

pickLeastRequestedJobExcept ∷ StdGen → IntSet → LeiosJobPool → Maybe (LeiosJobId, LeiosJob, LeiosJobPool, StdGen) Source #

Select a least-requested unfinished job (fewest in-flight requests; ties broken uniformly at random via the supplied PRNG) whose id is not in excluded, record one more in-flight request for it, and return its id, its bitfield, the updated pool, and the advanced PRNG. Nothing if every unfinished job is excluded (or the pool is empty), in which case the caller keeps its own PRNG (nothing was drawn).

The caller passes the job ids this peer already has in flight for the EB, so a peer is never asked for the same job twice.

unpickJob ∷ LeiosJobId → LeiosJobPool → LeiosJobPool Source #

Record one fewer in-flight request for a job (on disconnect). A no-op if the job is no longer in the pool: a peer disconnecting after its response already arrived and completeJob removed the job hits the Nothing branch below.

completeJob ∷ LeiosJobId → LeiosJobPool → LeiosJobPool Source #

Remove a job from the pool entirely (on its response arriving).

Inspecting pools

jobMultiplicities ∷ LeiosJobPool → IntMap Int Source #

How many peers have each unfinished job in flight.

hasExactReverseIndex ∷ LeiosJobPool → Bool Source #

Whether jobsByMultiplicity is the exact inverse of the multiplicities in jobs, as LeiosJobPool requires.