Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Checkpoint l = Checkpoint {
- unCheckpoint ∷ l
- newtype LedgerDB l = LedgerDB {
- ledgerDbCheckpoints ∷ AnchoredSeq (WithOrigin SlotNo) (Checkpoint l) (Checkpoint l)
- type LedgerDB' blk = LedgerDB (ExtLedgerState blk)
- data LedgerDbCfg l = LedgerDbCfg {}
- configLedgerDb ∷ ConsensusProtocol (BlockProtocol blk) ⇒ TopLevelConfig blk → LedgerDbCfg (ExtLedgerState blk)
LedgerDB
newtype Checkpoint l Source #
Internal newtype wrapper around a ledger state l
so that we can define a
non-blanket Anchorable
instance.
Instances
Internal state of the ledger DB
The ledger DB looks like
anchor |> snapshots <| current
where anchor
records the oldest known snapshot and current
the most
recent. The anchor is the oldest point we can roll back to.
We take a snapshot after each block is applied and keep in memory a window
of the last k
snapshots. We have verified empirically (#1936) that the
overhead of keeping k
snapshots in memory is small, i.e., about 5%
compared to keeping a snapshot every 100 blocks. This is thanks to sharing
between consecutive snapshots.
As an example, suppose we have k = 6
. The ledger DB grows as illustrated
below, where we indicate the anchor number of blocks, the stored snapshots,
and the current ledger.
anchor |> # [ snapshots ] <| tip --------------------------------------------------------------------------- G |> (0) [ ] <| G G |> (1) [ L1] <| L1 G |> (2) [ L1, L2] <| L2 G |> (3) [ L1, L2, L3] <| L3 G |> (4) [ L1, L2, L3, L4] <| L4 G |> (5) [ L1, L2, L3, L4, L5] <| L5 G |> (6) [ L1, L2, L3, L4, L5, L6] <| L6 L1 |> (6) [ L2, L3, L4, L5, L6, L7] <| L7 L2 |> (6) [ L3, L4, L5, L6, L7, L8] <| L8 L3 |> (6) [ L4, L5, L6, L7, L8, L9] <| L9 (*) L4 |> (6) [ L5, L6, L7, L8, L9, L10] <| L10 L5 |> (6) [*L6, L7, L8, L9, L10, L11] <| L11 L6 |> (6) [ L7, L8, L9, L10, L11, L12] <| L12 L7 |> (6) [ L8, L9, L10, L12, L12, L13] <| L13 L8 |> (6) [ L9, L10, L12, L12, L13, L14] <| L14
The ledger DB must guarantee that at all times we are able to roll back k
blocks. For example, if we are on line (*), and roll back 6 blocks, we get
L3 |> []
LedgerDB | |
|
Instances
Generic (LedgerDB l) Source # | |
Show l ⇒ Show (LedgerDB l) Source # | |
Eq l ⇒ Eq (LedgerDB l) Source # | |
NoThunks l ⇒ NoThunks (LedgerDB l) Source # | |
IsLedger l ⇒ GetTip (LedgerDB l) Source # | |
type HeaderHash (LedgerDB l ∷ Type) Source # | |
type Rep (LedgerDB l) Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB type Rep (LedgerDB l) = D1 ('MetaData "LedgerDB" "Ouroboros.Consensus.Storage.LedgerDB.LedgerDB" "ouroboros-consensus-0.21.0.0-inplace" 'True) (C1 ('MetaCons "LedgerDB" 'PrefixI 'True) (S1 ('MetaSel ('Just "ledgerDbCheckpoints") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (AnchoredSeq (WithOrigin SlotNo) (Checkpoint l) (Checkpoint l))))) |
type LedgerDB' blk = LedgerDB (ExtLedgerState blk) Source #
data LedgerDbCfg l Source #
Instances
Generic (LedgerDbCfg l) Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB type Rep (LedgerDbCfg l) ∷ Type → Type # from ∷ LedgerDbCfg l → Rep (LedgerDbCfg l) x # to ∷ Rep (LedgerDbCfg l) x → LedgerDbCfg l # | |
NoThunks (LedgerCfg l) ⇒ NoThunks (LedgerDbCfg l) Source # | |
type Rep (LedgerDbCfg l) Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB type Rep (LedgerDbCfg l) = D1 ('MetaData "LedgerDbCfg" "Ouroboros.Consensus.Storage.LedgerDB.LedgerDB" "ouroboros-consensus-0.21.0.0-inplace" 'False) (C1 ('MetaCons "LedgerDbCfg" 'PrefixI 'True) (S1 ('MetaSel ('Just "ledgerDbCfgSecParam") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SecurityParam) :*: S1 ('MetaSel ('Just "ledgerDbCfg") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (LedgerCfg l)))) |
configLedgerDb ∷ ConsensusProtocol (BlockProtocol blk) ⇒ TopLevelConfig blk → LedgerDbCfg (ExtLedgerState blk) Source #