| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Leios.TxCache.Reference
Contents
Description
The reference implementation of the LeiosTxCache: a bounded, in-memory index over the bodies of recent Leios EBs the node took in, and the txs it holds that those bodies reference, with incremental eviction. Simple and obviously correct, so that a faster implementation can be tested for observational equivalence to it.
This is deliberately independent of the on-disk LeiosDb: the two are
separate caches with different eviction policies. This index retains only
what is referenced by the bodies taken in at the
freshest points, so it stays small enough to keep resident in memory (a
lookup is disk-latency-free); the LeiosDb retains far more (everything
referenced by the acquired EBs younger than the immutable tip). Because they
are independent stores, sometimes the node will re-fetch and re-validate a tx
that has been evicted from the LeiosTxCache even while the LeiosDb still holds
it; that is acceptable.maxLeiosPointCount
The type parameters are payloads the index does not interpret:
ais what we record for a tx that has been inserted (fetched) but not yet applied;()in the node, or the tx's bytes in a test.vis what we record for a tx that has been applied. Kept polymorphic so the index is not coupled to any ledger type.bis the body taken in at a point. It must at least carry the body'sTxHashes, viaReferencesTxsByHash, so eviction can find its txs without touching storage.
Synopsis
- data LeiosTxCacheIndex a v b = MkLeiosTxCacheIndex {
- prunedSlot ∷ !SlotNo
- pointState ∷ !(Map LeiosPoint b)
- txState ∷ !(Map TxHash (TrackedTx a v))
- data TrackedTx a v = MkTrackedTx {
- ttYoungestReference ∷ !LeiosPoint
- ttState ∷ !(TxState a v)
- ttLocation ∷ !(StrictMaybe TxLocation)
- emptyLeiosTxCacheIndex ∷ LeiosTxCacheIndex a v b
- evictOlderThanFoldl' ∷ ReferencesTxsByHash b ⇒ SlotNo → w → (w → TxHash → w) → LeiosTxCacheIndex a v b → (LeiosTxCacheIndex a v b, Set LeiosPoint, w)
- insertBodyAndFoldl' ∷ ReferencesTxsByHash b ⇒ Int → LeiosPoint → b → w → (w → TxOffset → TxHash → BytesSize → Maybe TxLocation → w) → LeiosTxCacheIndex a v b → (LeiosTxCacheIndex a v b, (Maybe LeiosTxCacheInsertBodySummary, w))
- insertLandedTx ∷ LeiosPoint → TxOffset → TxHash → TxState a v → LeiosTxCacheIndex a v b → (LeiosTxCacheIndex a v b, TxArrivalPrior)
- lookupTx ∷ TxHash → LeiosTxCacheIndex a v b → StrictMaybe (TxState a v)
- lookupTxLocation ∷ TxHash → LeiosTxCacheIndex a v b → Maybe TxLocation
Index
data LeiosTxCacheIndex a v b Source #
The index.
Constructors
| MkLeiosTxCacheIndex | |
Fields
| |
A tx the index holds.
Constructors
| MkTrackedTx | |
Fields
| |
Operations
evictOlderThanFoldl' ∷ ReferencesTxsByHash b ⇒ SlotNo → w → (w → TxHash → w) → LeiosTxCacheIndex a v b → (LeiosTxCacheIndex a v b, Set LeiosPoint, w) Source #
Evict every retained point whose slot is strictly older than the boundary,
oldest first, as insertBodyAndFoldl' evicts the oldest point. Returns the
evicted points, and folds over the txs forgotten with them, walking each
evicted body from its first tx to its last and visiting each forgotten tx
once: at its first offset in the body of its youngest reference. Advances
prunedSlot to the boundary (monotonically), after which
insertBodyAndFoldl' retains no point that old.
Arguments
| ∷ ReferencesTxsByHash b | |
| ⇒ Int | The capacity to report as |
| → LeiosPoint | |
| → b | |
| → w | |
| → (w → TxOffset → TxHash → BytesSize → Maybe TxLocation → w) | |
| → LeiosTxCacheIndex a v b | |
| → (LeiosTxCacheIndex a v b, (Maybe LeiosTxCacheInsertBodySummary, w)) |
Retain this point with its body, make it the youngest reference of each tx
the body references that the index holds, if it is younger, and summarise
that. A no-op when the point is already retained, when it is strictly older
than prunedSlot (one the cache has already been pruned past; see
evictOlderThanFoldl'), or when maxLeiosPointCount points are retained and
it is older than all of them. Otherwise, when maxLeiosPointCount points are
retained, it first evicts the oldest (least slot, then least EB hash).
Either way, fold over its txs with their locations, as they are after any eviction and before the insertion.
insertLandedTx ∷ LeiosPoint → TxOffset → TxHash → TxState a v → LeiosTxCacheIndex a v b → (LeiosTxCacheIndex a v b, TxArrivalPrior) Source #
Record that this point now holds this tx, the one its body lists at this offset, with its state. A no-op if the index does not (still) retain the point.
A tx the index does not hold is recorded with this point as its youngest reference and its location. For one it holds, this point becomes its youngest reference if it is younger than the tx's existing youngest reference, and its location if it is younger than the tx's existing location or the tx has none. Either way, the tx is recorded as validated if it already has been, or if this says so.
lookupTx ∷ TxHash → LeiosTxCacheIndex a v b → StrictMaybe (TxState a v) Source #
The state of this tx, if the index holds it.
lookupTxLocation ∷ TxHash → LeiosTxCacheIndex a v b → Maybe TxLocation Source #
Where this tx landed, if it landed at a retained point.