ouroboros-consensus-0.18.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

Contents

Synopsis

LedgerDB

newtype Checkpoint l Source #

Internal newtype wrapper around a ledger state l so that we can define a non-blanket Anchorable instance.

Constructors

Checkpoint 

Fields

Instances

Instances details
Generic (Checkpoint l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

Associated Types

type Rep (Checkpoint l) ∷ TypeType #

Methods

fromCheckpoint l → Rep (Checkpoint l) x #

toRep (Checkpoint l) x → Checkpoint l #

Show l ⇒ Show (Checkpoint l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

Methods

showsPrecIntCheckpoint l → ShowS #

showCheckpoint l → String #

showList ∷ [Checkpoint l] → ShowS #

Eq l ⇒ Eq (Checkpoint l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

Methods

(==)Checkpoint l → Checkpoint l → Bool #

(/=)Checkpoint l → Checkpoint l → Bool #

NoThunks l ⇒ NoThunks (Checkpoint l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

GetTip l ⇒ Anchorable (WithOrigin SlotNo) (Checkpoint l) (Checkpoint l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

type Rep (Checkpoint l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

type Rep (Checkpoint l) = D1 ('MetaData "Checkpoint" "Ouroboros.Consensus.Storage.LedgerDB.LedgerDB" "ouroboros-consensus-0.18.0.0-inplace" 'True) (C1 ('MetaCons "Checkpoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "unCheckpoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 l)))

newtype LedgerDB l Source #

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 |> []

Constructors

LedgerDB 

Instances

Instances details
Generic (LedgerDB l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

Associated Types

type Rep (LedgerDB l) ∷ TypeType #

Methods

fromLedgerDB l → Rep (LedgerDB l) x #

toRep (LedgerDB l) x → LedgerDB l #

Show l ⇒ Show (LedgerDB l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

Methods

showsPrecIntLedgerDB l → ShowS #

showLedgerDB l → String #

showList ∷ [LedgerDB l] → ShowS #

Eq l ⇒ Eq (LedgerDB l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

Methods

(==)LedgerDB l → LedgerDB l → Bool #

(/=)LedgerDB l → LedgerDB l → Bool #

NoThunks l ⇒ NoThunks (LedgerDB l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

IsLedger l ⇒ GetTip (LedgerDB l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

Methods

getTipLedgerDB l → Point (LedgerDB l) Source #

type HeaderHash (LedgerDB l ∷ Type) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

type Rep (LedgerDB l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

type Rep (LedgerDB l) = D1 ('MetaData "LedgerDB" "Ouroboros.Consensus.Storage.LedgerDB.LedgerDB" "ouroboros-consensus-0.18.0.0-inplace" 'True) (C1 ('MetaCons "LedgerDB" 'PrefixI 'True) (S1 ('MetaSel ('Just "ledgerDbCheckpoints") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (AnchoredSeq (WithOrigin SlotNo) (Checkpoint l) (Checkpoint l)))))

data LedgerDbCfg l Source #

Instances

Instances details
Generic (LedgerDbCfg l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

Associated Types

type Rep (LedgerDbCfg l) ∷ TypeType #

Methods

fromLedgerDbCfg l → Rep (LedgerDbCfg l) x #

toRep (LedgerDbCfg l) x → LedgerDbCfg l #

NoThunks (LedgerCfg l) ⇒ NoThunks (LedgerDbCfg l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

type Rep (LedgerDbCfg l) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.LedgerDB

type Rep (LedgerDbCfg l) = D1 ('MetaData "LedgerDbCfg" "Ouroboros.Consensus.Storage.LedgerDB.LedgerDB" "ouroboros-consensus-0.18.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))))