| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.MiniProtocol.LeiosFetch.Jobs
Contents
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
- data LeiosJob = MkLeiosJob !IntSet !Word32 !JobCommitment
- newtype LeiosJobId = MkLeiosJobId Int
- newtype JobCommitment = MkJobCommitment ByteString
- jobCommitmentOfTxs ∷ [(TxHash, Word32)] → JobCommitment
- data LeiosJobPool
- mkJobPool ∷ Word32 → Int → IntMap (TxHash, Word32) → LeiosJobPool
- emptyJobPool ∷ LeiosJobPool
- nullJobPool ∷ LeiosJobPool → Bool
- lookupJob ∷ LeiosJobId → LeiosJobPool → Maybe LeiosJob
- restrictToPending ∷ IntMap a → LeiosJobPool → IntMap a
- pickLeastRequestedJobExcept ∷ StdGen → IntSet → LeiosJobPool → Maybe (LeiosJobId, LeiosJob, LeiosJobPool, StdGen)
- unpickJob ∷ LeiosJobId → LeiosJobPool → LeiosJobPool
- completeJob ∷ LeiosJobId → LeiosJobPool → LeiosJobPool
- jobMultiplicities ∷ LeiosJobPool → IntMap Int
- hasExactReverseIndex ∷ LeiosJobPool → Bool
Jobs
A unit of tx-fetch work: some of an EB's txs, fetched by one
MsgLeiosBlockTxsRequest.
Constructors
| MkLeiosJob | |
Fields
| |
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 |
Instances
| Eq LeiosJobId Source # | |
| Ord LeiosJobId Source # | |
Defined in Ouroboros.Consensus.MiniProtocol.LeiosFetch.Jobs Methods compare ∷ LeiosJobId → LeiosJobId → Ordering # (<) ∷ LeiosJobId → LeiosJobId → Bool # (<=) ∷ LeiosJobId → LeiosJobId → Bool # (>) ∷ LeiosJobId → LeiosJobId → Bool # (>=) ∷ LeiosJobId → LeiosJobId → Bool # max ∷ LeiosJobId → LeiosJobId → LeiosJobId # min ∷ LeiosJobId → LeiosJobId → LeiosJobId # | |
| Show LeiosJobId Source # | |
Defined in Ouroboros.Consensus.MiniProtocol.LeiosFetch.Jobs Methods showsPrec ∷ Int → LeiosJobId → ShowS # show ∷ LeiosJobId → String # showList ∷ [LeiosJobId] → ShowS # | |
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.
Constructors
| MkJobCommitment ByteString |
Instances
| Eq JobCommitment Source # | |
| Show JobCommitment Source # | |
Defined in Ouroboros.Consensus.MiniProtocol.LeiosFetch.Jobs Methods showsPrec ∷ Int → JobCommitment → ShowS # show ∷ JobCommitment → String # showList ∷ [JobCommitment] → ShowS # | |
jobCommitmentOfTxs ∷ [(TxHash, Word32)] → JobCommitment Source #
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.
Instances
| Eq LeiosJobPool Source # | |
| Show LeiosJobPool Source # | |
Defined in Ouroboros.Consensus.MiniProtocol.LeiosFetch.Jobs Methods showsPrec ∷ Int → LeiosJobPool → ShowS # show ∷ LeiosJobPool → String # showList ∷ [LeiosJobPool] → ShowS # | |
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.