ouroboros-network icon indicating copy to clipboard operation
ouroboros-network copied to clipboard

Cleanup + rework of Ledger.Basics

Open dnadales opened this issue 3 years ago • 0 comments

The functions and types that are defined in Ledger.Basics can be somewhat specialized and allow for more precise constraints on several functions. In particular, we are referring to the rework described below.

Split ApplyMapKind

The ApplyMapKind is an all-purpose mapkind GADT but:

  1. Other mapkinds are defined outside of it
  2. The mapkinds defined there are intrinsically different

We propose splitting that GADT in two:

-- | MapKinds which make sense being used next to LedgerState 
-- on which we might want to refer to specific values directly
data BaseMapKind = DiffMK'
              | EmptyMK'
              | KeysMK'
              | TrackingMK'
              | ValuesMK'

-- | MapKinds which only live as `LedgerTables` and are mostly used just 
-- as collections of values to be applied onto some BaseMapKind maps
data MetaMapKind' = QueryMK'
              | SeqDiffMK'

data BaseMK :: BaseMapKind -> Type -> Type -> Type where
  ApplyDiffMK     :: !(UtxoDiff    k v)                    -> BaseMK DiffMK'       k v
  ApplyEmptyMK    ::                                          BaseMK EmptyMK'      k v
  ApplyKeysMK     :: !(UtxoKeys    k v)                    -> BaseMK KeysMK'       k v
  ApplyTrackingMK :: !(UtxoValues  k v) -> !(UtxoDiff k v) -> BaseMK TrackingMK'   k v
  ApplyValuesMK   :: !(UtxoValues  k v)                    -> BaseMK ValuesMK'     k v

data MetaMK :: MetaMapKind -> Type -> Type -> Type where
  ApplySeqDiffMK  :: !(SeqUtxoDiff k v) -> MetaMK SeqDiffMK'    k v
  ApplyQueryAllMK  ::                      MetaMK QueryMK' k v
  ApplyQuerySomeMK :: !(UtxoKeys k v)   -> MetaMK QueryMK' k v

Cleanup operations

The (forget/apply/reapply)LedgerTablesX[Ticked] families of functions can be removed or at least reorganised, as they are maybe too specific for each case and they can probably be defined at use site if we just provide the basic building blocks instead of the functions themselves

dnadales avatar Oct 13 '22 11:10 dnadales