ouroboros-consensus-0.1.0.1: Consensus layer for the Ouroboros blockchain protocol
Safe Haskell None
Language Haskell2010

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) :: Type -> Type Source #

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

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

type Rep ( LgrDB m blk) Source #
Instance details

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

Initialization

openDB Source #

Arguments

:: forall m blk. ( IOLike m, LedgerSupportsProtocol blk, LgrDbSerialiseConstraints blk, InspectLedger blk, HasCallStack )
=> LgrDbArgs Identity 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

setCurrent :: IOLike 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 .

Validation

validate Source #

Arguments

:: forall 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

garbageCollectPrevApplied :: IOLike m => LgrDB m blk -> SlotNo -> STM m () Source #

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

Re-exports

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

  • onDiskNumSnapshots :: Word

    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.
  • onDiskShouldTakeSnapshot :: TimeSinceLast DiffTime -> Word64 -> Bool

    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 defaultDiskPolicy

data DiskSnapshot Source #

Instances

Instances details
Eq DiskSnapshot Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Ord DiskSnapshot Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Show DiskSnapshot Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Generic DiskSnapshot Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

type Rep DiskSnapshot Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

type Rep DiskSnapshot = D1 (' MetaData "DiskSnapshot" "Ouroboros.Consensus.Storage.LedgerDB.OnDisk" "ouroboros-consensus-0.1.0.1-DT4Cvwf63DZKctsEvaJqCU" ' 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 AnnLedgerError l blk Source #

Annotated ledger errors

Constructors

AnnLedgerError

Fields

ledgerDbCurrent :: GetTip l => LedgerDB l -> l Source #

The ledger state at the tip of the chain

data TraceEvent blk Source #

Constructors

InvalidSnapshot DiskSnapshot ( InitFailure blk)

An on disk snapshot was skipped because it was invalid.

TookSnapshot DiskSnapshot ( RealPoint blk)

A snapshot was written to disk.

DeletedSnapshot DiskSnapshot

An old or invalid on-disk snapshot was deleted

Instances

Instances details
StandardHash blk => Eq ( TraceEvent blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

StandardHash blk => Show ( TraceEvent blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Generic ( TraceEvent blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Associated Types

type Rep ( TraceEvent blk) :: Type -> Type Source #

type Rep ( TraceEvent blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

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 ( ReplayGoal blk)

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

ReplayFromSnapshot

Fields

  • DiskSnapshot
  • ( RealPoint blk)
  • ( 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
( StandardHash blk, InspectLedger blk) => Eq ( TraceReplayEvent blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

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

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Generic ( TraceReplayEvent blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

type Rep ( TraceReplayEvent blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

type Rep ( TraceReplayEvent blk) = D1 (' MetaData "TraceReplayEvent" "Ouroboros.Consensus.Storage.LedgerDB.OnDisk" "ouroboros-consensus-0.1.0.1-DT4Cvwf63DZKctsEvaJqCU" ' False ) ( C1 (' MetaCons "ReplayFromGenesis" ' PrefixI ' False ) ( S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( ReplayGoal blk))) :+: ( C1 (' MetaCons "ReplayFromSnapshot" ' PrefixI ' False ) (( S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 DiskSnapshot ) :*: S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( RealPoint blk))) :*: ( S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( ReplayStart blk)) :*: S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( ReplayGoal blk)))) :+: C1 (' MetaCons "ReplayedBlock" ' PrefixI ' False ) (( S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( RealPoint blk)) :*: S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 [ LedgerEvent blk])) :*: ( S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( ReplayStart blk)) :*: S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( ReplayGoal blk))))))

Exported for testing purposes

mkLgrDB :: StrictTVar m ( LedgerDB' blk) -> StrictTVar m ( Set ( RealPoint blk)) -> ( RealPoint blk -> m blk) -> LgrDbArgs Identity m blk -> LgrDB m blk Source #

For testing purposes