ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Ledger.Tables.Utils

Description

A collection of useful combinators to shorten the code in other places.

This whole module provides ways to combine tables of two ledger states to produce another one. It is written very much ad-hoc and we should probably think of some way to make this more ergonomic. In particular for functions that take two ledger states, it is unclear if it will keep the in-memory part of the first or the second one.

Synopsis

Projection and injection

ltprj ∷ ∀ l blk (mk ∷ MapKind). (HasLedgerTables l blk, CanMapMK mk, CanMapKeysMK mk, ZeroableMK mk) ⇒ l blk mk → LedgerTables blk mk Source #

ltwith ∷ ∀ l blk (mk' ∷ MapKind) (mk ∷ MapKind). (HasLedgerTables l blk, CanMapMK mk', CanMapKeysMK mk', ZeroableMK mk') ⇒ l blk mk → LedgerTables blk mk' → l blk mk' Source #

Basic operations

emptyLedgerTables ∷ ∀ (mk ∷ MapKind) blk. (ZeroableMK mk, LedgerTableConstraints blk) ⇒ LedgerTables blk mk Source #

Empty values for every table

forgetLedgerTables ∷ ∀ l blk (mk ∷ MapKind). HasLedgerTables l blk ⇒ l blk mk → l blk EmptyMK Source #

Remove the ledger tables

Operations on DiffMK

Apply diffs

applyDiffForKeys ∷ (HasLedgerTables l blk, HasLedgerTables l' blk) ⇒ l blk ValuesMKLedgerTables blk KeysMK → l' blk DiffMK → l' blk ValuesMK Source #

Apply diffs in l3 for keys in l2 and l1 on values from l1. Returns l3.

applyDiffForKeysOnTablesHasLedgerTables l blk ⇒ LedgerTables blk ValuesMKLedgerTables blk KeysMK → l blk DiffMK → l blk ValuesMK Source #

Apply diffs in l3 for keys in l2 and l1 on values from l1. Returns l3.

applyDiffs ∷ (HasLedgerTables l blk, HasLedgerTables l' blk) ⇒ l blk ValuesMK → l' blk DiffMK → l' blk ValuesMK Source #

Apply diffs from l2 on values from l1. Returns l2.

Create diffs

calculateDifference ∷ (HasLedgerTables l blk, HasLedgerTables l' blk) ⇒ l blk ValuesMK → l' blk ValuesMK → l' blk TrackingMK Source #

Calculate the differences between two ledger states. The first ledger state is considered before, the second ledger state is considered after. Returns the second ledger state.

noNewTickingDiffs ∷ ∀ l blk (any ∷ MapKind). HasLedgerTables l blk ⇒ l blk any → l blk DiffMK Source #

Replace tables with an empty diff. Can be used to specify that a ledger state tick produces no new UTXO entries.

valuesAsDiffsHasLedgerTables l blk ⇒ l blk ValuesMK → l blk DiffMK Source #

Promote values to diffs, for cases in which all existing values must be considered diffs. In particular this is used when populating the ledger tables for the first time.

Combining diffs

prependDiffs ∷ (HasLedgerTables l blk, HasLedgerTables l' blk) ⇒ l blk DiffMK → l' blk DiffMK → l' blk DiffMK Source #

Prepend the diffs from l1 to l2. Returns l2.

rawPrependDiffs Source #

Arguments

Ord k 
DiffMK k v

Earlier differences

DiffMK k v

Later differences

DiffMK k v 

Operations on TrackingMK

Augment

attachAndApplyDiffs ∷ (HasLedgerTables l blk, HasLedgerTables l' blk) ⇒ l blk ValuesMK → l' blk DiffMK → l' blk TrackingMK Source #

Apply the differences from the first ledger state to the values of the second ledger state. Returns the second ledger state with a TrackingMK of the final values and all the diffs.

attachEmptyDiffsHasLedgerTables l blk ⇒ l blk ValuesMK → l blk TrackingMK Source #

Make a TrackingMK with empty diffs.

prependTrackingDiffs ∷ (HasLedgerTables l blk, HasLedgerTables l' blk) ⇒ l blk TrackingMK → l' blk TrackingMK → l' blk TrackingMK Source #

Prepend tracking diffs from the first ledger state to the tracking diffs from the second ledger state. Keep the tracking values of the second ledger state. Returns the second ledger state.

PRECONDITION: See rawPrependTrackingDiffs.

Reduce

Union values

unionValuesOrd k ⇒ ValuesMK k v → ValuesMK k v → ValuesMK k v Source #

For this first UTxO-HD iteration, there can't be two keys with different values on the tables, thus there will never be conflicting collisions.

Exposed for cardano-api

applyDiffsMK Source #

Arguments

Ord k 
ValuesMK k v

Values to which differences are applied

DiffMK k v

Differences to apply

ValuesMK k v 

restrictValuesMKOrd k ⇒ ValuesMK k v → KeysMK k v → ValuesMK k v Source #

Testing

applyDiffs' ∷ (HasLedgerTables l blk, HasLedgerTables l' blk) ⇒ l blk ValuesMK → l' blk DiffMKLedgerTables blk ValuesMK Source #

Apply diffs from the second ledger state to the values of the first ledger state. Returns ledger tables.

rawCalculateDifference ∷ (Ord k, Eq v) ⇒ ValuesMK k v → ValuesMK k v → TrackingMK k v Source #