ouroboros-consensus-0.26.0.0: Consensus layer for the Ouroboros blockchain protocol
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 (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 ValuesMKLedgerTables 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 ValuesMKLedgerTables 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.

attachEmptyDiffsHasLedgerTables 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

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' ∷ ∀ l (l'' ∷ LedgerStateKind) l'. (SameUtxoTypes l l'', SameUtxoTypes l' l'', HasLedgerTables l, HasLedgerTables l', HasLedgerTables l'') ⇒ l ValuesMK → l' DiffMKLedgerTables l'' 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 #