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

Ouroboros.Consensus.Storage.ChainDB.Impl.LgrDB

Description

Thin wrapper around the LedgerDB

Synopsis

Documentation

data LgrDB m blk Source #

Thin wrapper around the ledger database

Instances

Instances details
Generic (LgrDB m blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.ChainDB.Impl.LgrDB

Associated Types

type Rep (LgrDB m blk) ∷ TypeType #

Methods

fromLgrDB m blk → Rep (LgrDB m blk) x #

toRep (LgrDB m blk) x → LgrDB m blk #

(IOLike m, LedgerSupportsProtocol blk) ⇒ NoThunks (LgrDB m blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.ChainDB.Impl.LgrDB

Methods

noThunksContextLgrDB m blk → IO (Maybe ThunkInfo) Source #

wNoThunksContextLgrDB m blk → IO (Maybe ThunkInfo) Source #

showTypeOfProxy (LgrDB m blk) → String Source #

type Rep (LgrDB m blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.ChainDB.Impl.LgrDB

type Rep (LgrDB m blk) = D1 ('MetaData "LgrDB" "Ouroboros.Consensus.Storage.ChainDB.Impl.LgrDB" "ouroboros-consensus-0.21.0.0-inplace" 'False) (C1 ('MetaCons "LgrDB" 'PrefixI 'True) ((S1 ('MetaSel ('Just "varDB") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (StrictTVar m (LedgerDB' blk))) :*: (S1 ('MetaSel ('Just "varPrevApplied") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (StrictTVar m (Set (RealPoint blk)))) :*: S1 ('MetaSel ('Just "resolveBlock") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (RealPoint blk → m blk)))) :*: ((S1 ('MetaSel ('Just "cfg") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (LedgerDbCfg (ExtLedgerState blk))) :*: S1 ('MetaSel ('Just "diskPolicy") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DiskPolicy)) :*: (S1 ('MetaSel ('Just "hasFS") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (SomeHasFS m)) :*: S1 ('MetaSel ('Just "tracer") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Tracer m (TraceSnapshotEvent blk)))))))

type LgrDbSerialiseConstraints blk = (Serialise (HeaderHash blk), EncodeDisk blk (LedgerState blk), DecodeDisk blk (LedgerState blk), EncodeDisk blk (AnnTip blk), DecodeDisk blk (AnnTip blk), EncodeDisk blk (ChainDepState (BlockProtocol blk)), DecodeDisk blk (ChainDepState (BlockProtocol blk))) Source #

EncodeDisk and DecodeDisk constraints needed for the LgrDB.

Initialization

defaultArgsApplicative m ⇒ Incomplete LgrDbArgs m blk Source #

Default arguments

openDB Source #

Arguments

∷ ∀ m blk. (IOLike m, LedgerSupportsProtocol blk, LgrDbSerialiseConstraints blk, InspectLedger blk, HasCallStack) 
Complete LgrDbArgs m blk

Stateless initializaton arguments

Tracer m (ReplayGoal blk → TraceReplayEvent blk)

Used to trace the progress while replaying blocks against the ledger.

ImmutableDB m blk

Reference to the immutable DB

After reading a snapshot from disk, the ledger DB will be brought up to date with tip of the immutable DB. The corresponding ledger state can then be used as the starting point for chain selection in the ChainDB driver.

→ (RealPoint blk → m blk)

Read a block from disk

The block may be in the immutable DB or in the volatile DB; the ledger DB does not know where the boundary is at any given point.

→ m (LgrDB m blk, Word64) 

Open the ledger DB

In addition to the ledger DB also returns the number of immutable blocks that were replayed.

TraceReplayEvent decorator

decorateReplayTracerWithGoal Source #

Arguments

Point blk

Tip of the ImmutableDB

Tracer m (TraceReplayEvent blk) 
Tracer m (ReplayGoal blk → TraceReplayEvent blk) 

Add the tip of the Immutable DB to the trace event

Between the tip of the immutable DB and the point of the starting block, the node could (if it so desired) easily compute a "percentage complete".

Wrappers

currentPoint ∷ ∀ blk. UpdateLedger blk ⇒ LedgerDB' blk → Point blk Source #

getCurrentIOLike m ⇒ LgrDB m blk → STM m (LedgerDB' blk) Source #

setCurrentIOLike m ⇒ LgrDB m blk → LedgerDB' blk → STM m () Source #

PRECONDITION: The new LedgerDB must be the result of calling either ledgerDbSwitch or ledgerDbPushMany on the current LedgerDB.

trimSnapshots ∷ ∀ m blk. (MonadCatch m, HasHeader blk) ⇒ LgrDB m blk → m [DiskSnapshot] Source #

Validation

validate Source #

Arguments

∷ ∀ m blk. (IOLike m, LedgerSupportsProtocol blk, HasCallStack) 
LgrDB m blk 
LedgerDB' blk

This is used as the starting point for validation, not the one in the LgrDB.

BlockCache blk 
Word64

How many blocks to roll back

→ (UpdateLedgerDbTraceEvent blk → m ()) 
→ [Header blk] 
→ m (ValidateResult blk) 

Previously applied blocks

garbageCollectPrevAppliedIOLike m ⇒ LgrDB m blk → SlotNoSTM m () Source #

Remove all points with a slot older than the given slot from the set of previously applied points.

getPrevAppliedIOLike m ⇒ LgrDB m blk → STM m (Set (RealPoint blk)) Source #

Re-exports

data AnnLedgerError l blk Source #

Annotated ledger errors

Constructors

AnnLedgerError 

Fields

Instances

Instances details
Monad m ⇒ ThrowsLedgerError (ExceptT (AnnLedgerError l blk) m) l blk Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Update

Methods

throwLedgerErrorLedgerDB l → RealPoint blk → LedgerErr l → ExceptT (AnnLedgerError l blk) m a Source #

data DiskPolicy Source #

On-disk policy

We only write ledger states that are older than k blocks to disk (that is, snapshots that are guaranteed valid). The on-disk policy determines how often we write to disk and how many checkpoints we keep.

Constructors

DiskPolicy 

Fields

  • onDiskNumSnapshotsWord

    How many snapshots do we want to keep on disk?

    A higher number of on-disk snapshots is primarily a safe-guard against disk corruption: it trades disk space for reliability.

    Examples:

    • 0: Delete the snapshot immediately after writing. Probably not a useful value :-D
    • 1: Delete the previous snapshot immediately after writing the next Dangerous policy: if for some reason the deletion happens before the new snapshot is written entirely to disk (we don't fsync), we have no choice but to start at the genesis snapshot on the next startup.
    • 2: Always keep 2 snapshots around. This means that when we write the next snapshot, we delete the oldest one, leaving the middle one available in case of truncation of the write. This is probably a sane value in most circumstances.
  • onDiskShouldTakeSnapshotTimeSinceLast DiffTimeWord64Bool

    Should we write a snapshot of the ledger state to disk?

    This function is passed two bits of information:

    • The time since the last snapshot, or NoSnapshotTakenYet if none was taken yet. Note that NoSnapshotTakenYet merely means no snapshot had been taking yet since the node was started; it does not necessarily mean that none exist on disk.
    • The distance in terms of blocks applied to the oldest ledger snapshot in memory. During normal operation, this is the number of blocks written to the ImmutableDB since the last snapshot. On startup, it is computed by counting how many immutable blocks we had to reapply to get to the chain tip. This is useful, as it allows the policy to decide to take a snapshot on node startup if a lot of blocks had to be replayed.

    See also mkDiskPolicy

data DiskSnapshot Source #

Instances

Instances details
Generic DiskSnapshot Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots

Associated Types

type Rep DiskSnapshotTypeType #

Show DiskSnapshot Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots

Eq DiskSnapshot Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots

Ord DiskSnapshot Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots

type Rep DiskSnapshot Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots

type Rep DiskSnapshot = D1 ('MetaData "DiskSnapshot" "Ouroboros.Consensus.Storage.LedgerDB.Snapshots" "ouroboros-consensus-0.21.0.0-inplace" 'False) (C1 ('MetaCons "DiskSnapshot" 'PrefixI 'True) (S1 ('MetaSel ('Just "dsNumber") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64) :*: S1 ('MetaSel ('Just "dsSuffix") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe String))))

data ExceededRollback Source #

Exceeded maximum rollback supported by the current ledger DB state

Under normal circumstances this will not arise. It can really only happen in the presence of data corruption (or when switching to a shorter fork, but that is disallowed by all currently known Ouroboros protocols).

Records both the supported and the requested rollback.

data TraceReplayEvent blk Source #

Events traced while replaying blocks against the ledger to bring it up to date w.r.t. the tip of the ImmutableDB during initialisation. As this process takes a while, we trace events to inform higher layers of our progress.

Constructors

ReplayFromGenesis

There were no LedgerDB snapshots on disk, so we're replaying all blocks starting from Genesis against the initial ledger.

Fields

  • (ReplayGoal blk)

    the block at the tip of the ImmutableDB | There was a LedgerDB snapshot on disk corresponding to the given tip. We're replaying more recent blocks against it.

ReplayFromSnapshot 

Fields

  • DiskSnapshot
     
  • (ReplayStart blk)

    the block at which this replay started

  • (ReplayGoal blk)

    the block at the tip of the ImmutableDB | We replayed the given block (reference) on the genesis snapshot during the initialisation of the LedgerDB. Used during ImmutableDB replay.

ReplayedBlock 

Fields

Instances

Instances details
Generic (TraceReplayEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Init

Associated Types

type Rep (TraceReplayEvent blk) ∷ TypeType #

Methods

fromTraceReplayEvent blk → Rep (TraceReplayEvent blk) x #

toRep (TraceReplayEvent blk) x → TraceReplayEvent blk #

(StandardHash blk, InspectLedger blk) ⇒ Show (TraceReplayEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Init

(StandardHash blk, InspectLedger blk) ⇒ Eq (TraceReplayEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Init

Methods

(==)TraceReplayEvent blk → TraceReplayEvent blk → Bool #

(/=)TraceReplayEvent blk → TraceReplayEvent blk → Bool #

type Rep (TraceReplayEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Init

data TraceSnapshotEvent blk Source #

Constructors

InvalidSnapshot DiskSnapshot (SnapshotFailure blk)

An on disk snapshot was skipped because it was invalid.

TookSnapshot DiskSnapshot (RealPoint blk) EnclosingTimed

A snapshot was written to disk.

DeletedSnapshot DiskSnapshot

An old or invalid on-disk snapshot was deleted

Instances

Instances details
Generic (TraceSnapshotEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots

Associated Types

type Rep (TraceSnapshotEvent blk) ∷ TypeType #

StandardHash blk ⇒ Show (TraceSnapshotEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots

StandardHash blk ⇒ Eq (TraceSnapshotEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots

type Rep (TraceSnapshotEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.Snapshots

ledgerDbCurrentGetTip l ⇒ LedgerDB l → l Source #

The ledger state at the tip of the chain

Exported for testing purposes

mkLgrDBStrictTVar m (LedgerDB' blk) → StrictTVar m (Set (RealPoint blk)) → (RealPoint blk → m blk) → Complete LgrDbArgs m blk → SecurityParamLgrDB m blk Source #

For testing purposes