ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Leios.TxCache

Description

The LeiosTxCache tracks txs that were acquired because a recent EB referenced them.

The LeiosTxCacheIndex records two facts about each tx it holds: whether it has already been validated (by the Mempool or by the LeiosVoting thread), and where a LeiosDB write of it landed.

The index is in-memory so that latency-critical consumers (LeiosFetch, LeiosVoting) can query it with constantly low latency; it supplants the by-hash membership check that the fetch logic would otherwise do against the LeiosDb. The size of the LeiosTxCache is bounded first and foremost by the requirement that its index fits comfortably in-memory, even in a worst case.

This module is the umbrella: it re-exports the Ouroboros.Consensus.Leios.TxCache.API interface and the handle factory newPureLeiosTxCache, which wraps Ouroboros.Consensus.Leios.TxCache.Reference.

What it promises about the LeiosDb

Nothing: its records are hints. A location it records for a tx need not hold that tx in the LeiosDb. Once a point is older than the LeiosDb's promoted slot, the LeiosDb's garbage collection deletes the point's txs, and a later write of txs to that point stores none of them, though it settles as usual. The cache evicts that point when LeiosFetch prunes to the immutable tip (evictOlderThanFoldl'), which can come after either.

Offering a recorded location to the LeiosDb as a fill is safe anyway: the LeiosDb copies a fill only if its bytes hash to the tx the body lists at that offset (see writeEbBody), so a stale or wrong location costs a fetch, never a wrong tx.

Synopsis

Documentation

newPureLeiosTxCache ∷ (IOLike m, ReferencesTxsByHash b) ⇒ Int → m (LeiosTxCache m a v b) Source #

A handle backed by the pure reference index behind an MVar.

The table shift only sizes ibsCacheCapacity reporting -- the pure index has no allocation of its own: pass defaultLeiosTxCacheShift.

nullLeiosTxCache ∷ ∀ (m ∷ Type → Type) a v b. Monad m ⇒ LeiosTxCache m a v b Source #

A handle whose every operation is inert: bodies are never retained, summarised nor their txs folded over, landed txs are counted evicted, and lookups always miss. For contexts that don't maintain the cache, such as tools that replay or forge blocks.