ouroboros-consensus-0.1.0.2: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellNone
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 Source #

Methods

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

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

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

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

Methods

noThunks ∷ Context → LgrDB m blk → IO (Maybe ThunkInfo) #

wNoThunks ∷ Context → LgrDB m blk → IO (Maybe ThunkInfo) #

showTypeOfProxy (LgrDB m blk) → String #

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.1.0.2-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 (TopLevelConfig 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 (TraceEvent 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

data LgrDbArgs f m blk Source #

Constructors

LgrDbArgs 

Fields

defaultArgsApplicative m ⇒ SomeHasFS m → DiskPolicyLgrDbArgs Defaults m blk Source #

Default arguments

openDB Source #

Arguments

∷ ∀ 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

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 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 defaultDiskPolicy

Instances

Instances details
NoThunks DiskPolicy Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy

Methods

noThunks ∷ Context → DiskPolicyIO (Maybe ThunkInfo) #

wNoThunks ∷ Context → DiskPolicyIO (Maybe ThunkInfo) #

showTypeOfProxy DiskPolicyString #

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

Associated Types

type Rep DiskSnapshotTypeType Source #

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.2-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 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.InMemory

Methods

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

ledgerDbCurrentGetTip 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

Methods

(==)TraceEvent blk → TraceEvent blk → Bool Source #

(/=)TraceEvent blk → TraceEvent blk → Bool Source #

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

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Methods

showsPrecIntTraceEvent blk → ShowS Source #

showTraceEvent blk → String Source #

showList ∷ [TraceEvent blk] → ShowS Source #

Generic (TraceEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Associated Types

type Rep (TraceEvent blk) ∷ TypeType Source #

Methods

fromTraceEvent blk → Rep (TraceEvent blk) x Source #

toRep (TraceEvent blk) x → TraceEvent blk 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

Associated Types

type Rep (TraceReplayEvent blk) ∷ TypeType Source #

type Rep (TraceReplayEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Exported for testing purposes

mkLgrDBStrictTVar m (LedgerDB' blk) → StrictTVar m (Set (RealPoint blk)) → (RealPoint blk → m blk) → LgrDbArgs Identity m blk → LgrDB m blk Source #

For testing purposes