Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- ltprj ∷ ∀ l (l' ∷ LedgerStateKind) (mk ∷ MapKind). (HasLedgerTables l, SameUtxoTypes l l', CanMapMK mk, CanMapKeysMK mk, ZeroableMK mk) ⇒ l mk → LedgerTables l' mk
- ltwith ∷ ∀ l (mk' ∷ MapKind) (mk ∷ MapKind). (HasLedgerTables l, CanMapMK mk', CanMapKeysMK mk', ZeroableMK mk') ⇒ l mk → LedgerTables l mk' → l mk'
- emptyLedgerTables ∷ ∀ (mk ∷ MapKind) (l ∷ LedgerStateKind). (ZeroableMK mk, LedgerTableConstraints l) ⇒ LedgerTables l mk
- forgetLedgerTables ∷ ∀ l (mk ∷ MapKind). HasLedgerTables l ⇒ l mk → l EmptyMK
- applyDiffForKeys ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l ValuesMK → LedgerTables l KeysMK → l' DiffMK → l' ValuesMK
- applyDiffForKeysOnTables ∷ ∀ (l ∷ LedgerStateKind) l'. (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ LedgerTables l ValuesMK → LedgerTables l KeysMK → l' DiffMK → l' ValuesMK
- applyDiffs ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l ValuesMK → l' DiffMK → l' ValuesMK
- calculateDifference ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l ValuesMK → l' ValuesMK → l' TrackingMK
- noNewTickingDiffs ∷ ∀ l (any ∷ MapKind). HasLedgerTables l ⇒ l any → l DiffMK
- valuesAsDiffs ∷ (LedgerTableConstraints l, HasLedgerTables l) ⇒ l ValuesMK → l DiffMK
- prependDiffs ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l DiffMK → l' DiffMK → l' DiffMK
- attachAndApplyDiffs ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l ValuesMK → l' DiffMK → l' TrackingMK
- attachEmptyDiffs ∷ HasLedgerTables l ⇒ l ValuesMK → l TrackingMK
- prependTrackingDiffs ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l TrackingMK → l' TrackingMK → l' TrackingMK
- trackingToDiffs ∷ (HasLedgerTables l, LedgerTableConstraints l) ⇒ l TrackingMK → l DiffMK
- trackingToValues ∷ (LedgerTableConstraints l, HasLedgerTables l) ⇒ l TrackingMK → l ValuesMK
- unionValues ∷ Ord k ⇒ ValuesMK k v → ValuesMK k v → ValuesMK k v
- applyDiffsMK ∷ Ord k ⇒ ValuesMK k v → DiffMK k v → ValuesMK k v
- restrictValuesMK ∷ Ord k ⇒ ValuesMK k v → KeysMK k v → ValuesMK k v
- applyDiffs' ∷ ∀ l (l'' ∷ LedgerStateKind) l'. (SameUtxoTypes l l'', SameUtxoTypes l' l'', HasLedgerTables l, HasLedgerTables l', HasLedgerTables l'') ⇒ l ValuesMK → l' DiffMK → LedgerTables l'' ValuesMK
- rawAttachAndApplyDiffs ∷ Ord k ⇒ ValuesMK k v → DiffMK k v → TrackingMK k v
- rawCalculateDifference ∷ (Ord k, Eq v) ⇒ ValuesMK k v → ValuesMK k v → TrackingMK k v
- restrictValues' ∷ ∀ l (l'' ∷ LedgerStateKind) l'. (SameUtxoTypes l l'', SameUtxoTypes l' l'', HasLedgerTables l, HasLedgerTables l', HasLedgerTables l'') ⇒ l ValuesMK → l' KeysMK → LedgerTables l'' ValuesMK
Projection and injection
ltprj ∷ ∀ l (l' ∷ LedgerStateKind) (mk ∷ MapKind). (HasLedgerTables l, SameUtxoTypes l l', CanMapMK mk, CanMapKeysMK mk, ZeroableMK mk) ⇒ l mk → LedgerTables l' mk Source #
ltwith ∷ ∀ l (mk' ∷ MapKind) (mk ∷ MapKind). (HasLedgerTables l, CanMapMK mk', CanMapKeysMK mk', ZeroableMK mk') ⇒ l mk → LedgerTables l mk' → l mk' Source #
Basic operations
emptyLedgerTables ∷ ∀ (mk ∷ MapKind) (l ∷ LedgerStateKind). (ZeroableMK mk, LedgerTableConstraints l) ⇒ LedgerTables l mk Source #
Empty values for every table
forgetLedgerTables ∷ ∀ l (mk ∷ MapKind). HasLedgerTables l ⇒ l mk → l EmptyMK Source #
Remove the ledger tables
Operations on DiffMK
Apply diffs
applyDiffForKeys ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l ValuesMK → LedgerTables l KeysMK → l' DiffMK → l' ValuesMK Source #
Apply diffs in l3
for keys in l2
and l1
on values from l1
. Returns l3
.
applyDiffForKeysOnTables ∷ ∀ (l ∷ LedgerStateKind) l'. (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ LedgerTables l ValuesMK → LedgerTables l KeysMK → l' DiffMK → l' ValuesMK Source #
Apply diffs in l3
for keys in l2
and l1
on values from l1
. Returns l3
.
applyDiffs ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l ValuesMK → l' DiffMK → l' ValuesMK Source #
Apply diffs from l2
on values from l1
. Returns l2
.
Create diffs
calculateDifference ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l ValuesMK → l' ValuesMK → l' 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 (any ∷ MapKind). HasLedgerTables l ⇒ l any → l DiffMK Source #
Replace tables with an empty diff. Can be used to specify that a ledger state tick produces no new UTXO entries.
valuesAsDiffs ∷ (LedgerTableConstraints l, HasLedgerTables l) ⇒ l ValuesMK → l 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 ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l DiffMK → l' DiffMK → l' DiffMK Source #
Prepend the diffs from l1
to l2
. Returns l2
.
Operations on TrackingMK
Augment
attachAndApplyDiffs ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l ValuesMK → l' DiffMK → l' 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.
attachEmptyDiffs ∷ HasLedgerTables l ⇒ l ValuesMK → l TrackingMK Source #
Make a TrackingMK
with empty diffs.
prependTrackingDiffs ∷ (SameUtxoTypes l l', HasLedgerTables l, HasLedgerTables l') ⇒ l TrackingMK → l' TrackingMK → l' 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
trackingToDiffs ∷ (HasLedgerTables l, LedgerTableConstraints l) ⇒ l TrackingMK → l DiffMK Source #
trackingToValues ∷ (LedgerTableConstraints l, HasLedgerTables l) ⇒ l TrackingMK → l ValuesMK Source #
Union values
unionValues ∷ Ord 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
Testing
applyDiffs' ∷ ∀ l (l'' ∷ LedgerStateKind) l'. (SameUtxoTypes l l'', SameUtxoTypes l' l'', HasLedgerTables l, HasLedgerTables l', HasLedgerTables l'') ⇒ l ValuesMK → l' DiffMK → LedgerTables l'' ValuesMK Source #
Apply diffs from the second ledger state to the values of the first ledger state. Returns ledger tables.
rawAttachAndApplyDiffs ∷ Ord k ⇒ ValuesMK k v → DiffMK k v → TrackingMK k v Source #
rawCalculateDifference ∷ (Ord k, Eq v) ⇒ ValuesMK k v → ValuesMK k v → TrackingMK k v Source #
restrictValues' ∷ ∀ l (l'' ∷ LedgerStateKind) l'. (SameUtxoTypes l l'', SameUtxoTypes l' l'', HasLedgerTables l, HasLedgerTables l', HasLedgerTables l'') ⇒ l ValuesMK → l' KeysMK → LedgerTables l'' ValuesMK Source #