ouroboros-consensus-0.1.0.0: 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) :: Type -> Type #

Methods

from :: LgrDB m blk -> Rep (LgrDB m blk) x #

to :: Rep (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

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.0-GfJNvFcM6lj2s5utKAUPEp" '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 'NoSourceStrictness 'DecidedLazy) (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

defaultArgs :: FilePath -> LgrDbArgs Defaults IO blk Source #

Default arguments

openDB Source #

Arguments

:: forall m blk. (IOLike m, LedgerSupportsProtocol blk, LgrDbSerialiseConstraints blk, InspectLedger blk, HasCallStack) 
=> LgrDbArgs Identity m blk

Stateless initializaton arguments

-> Tracer m (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

type TraceLedgerReplayEvent blk = TraceReplayEvent blk (Point blk) Source #

TraceReplayEvent instantiated with additional information.

The replayTo parameter is instantiated with the Point of the tip of the ImmutableDB.

decorateReplayTracer Source #

Arguments

:: Point blk

Tip of the ImmutableDB

-> Tracer m (TraceLedgerReplayEvent blk) 
-> Tracer m (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

getCurrent :: IOLike m => LgrDB m blk -> STM m (LedgerDB' blk) Source #

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.

getPastState :: (IOLike m, HasHeader blk) => LgrDB m blk -> Point blk -> STM m (Maybe (ExtLedgerState blk)) Source #

currentPoint :: forall blk. UpdateLedger blk => LedgerDB' blk -> Point blk Source #

takeSnapshot :: forall m blk. (IOLike m, LgrDbSerialiseConstraints blk) => LgrDB m blk -> m (DiskSnapshot, Point blk) Source #

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

-> [Header blk] 
-> m (ValidateResult blk) 

Previously applied blocks

getPrevApplied :: IOLike m => LgrDB m blk -> STM m (Set (RealPoint blk)) Source #

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 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 r Source #

Annotated ledger errors

Constructors

AnnLedgerError 

Fields

Instances

Instances details
Monad m => ThrowsLedgerError l r (ExceptT (AnnLedgerError l r) m) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.InMemory

Methods

throwLedgerError :: LedgerDB l r -> r -> LedgerErr l -> ExceptT (AnnLedgerError l r) m a Source #

newtype LedgerDbParams Source #

Constructors

LedgerDbParams 

Fields

Instances

Instances details
Eq LedgerDbParams Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.InMemory

Show LedgerDbParams Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.InMemory

Generic LedgerDbParams Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.InMemory

Associated Types

type Rep LedgerDbParams :: Type -> Type #

NoThunks LedgerDbParams Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.InMemory

type Rep LedgerDbParams Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.InMemory

type Rep LedgerDbParams = D1 ('MetaData "LedgerDbParams" "Ouroboros.Consensus.Storage.LedgerDB.InMemory" "ouroboros-consensus-0.1.0.0-GfJNvFcM6lj2s5utKAUPEp" 'True) (C1 ('MetaCons "LedgerDbParams" 'PrefixI 'True) (S1 ('MetaSel ('Just "ledgerDbSecurityParam") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SecurityParam)))

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 :: Maybe 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 Nothing if none was taken yet. Note that Nothing 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 #

On disk snapshots are numbered monotonically

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 DiskSnapshot :: Type -> Type #

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.0-GfJNvFcM6lj2s5utKAUPEp" 'True) (C1 ('MetaCons "DiskSnapshot" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

data TraceEvent blk Source #

Constructors

InvalidSnapshot DiskSnapshot (InitFailure blk)

An on disk snapshot was skipped because it was invalid.

TookSnapshot DiskSnapshot (Point 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 #

(/=) :: TraceEvent blk -> TraceEvent blk -> Bool #

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

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Methods

showsPrec :: Int -> TraceEvent blk -> ShowS #

show :: TraceEvent blk -> String #

showList :: [TraceEvent blk] -> ShowS #

Generic (TraceEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Associated Types

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

Methods

from :: TraceEvent blk -> Rep (TraceEvent blk) x #

to :: Rep (TraceEvent blk) x -> TraceEvent blk #

type Rep (TraceEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

data TraceReplayEvent blk replayTo 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.

The replayTo parameter is meant to be filled in by a higher layer, i.e., the ChainDB.

Constructors

ReplayFromGenesis replayTo

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

The replayTo parameter corresponds to the block at the tip of the ImmutableDB, i.e., the last block to replay.

ReplayFromSnapshot DiskSnapshot (Point blk) replayTo

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

The replayTo parameter corresponds to the block at the tip of the ImmutableDB, i.e., the last block to replay.

ReplayedBlock (RealPoint blk) [LedgerEvent blk] replayTo

We replayed the given block (reference) on the genesis snapshot during the initialisation of the LedgerDB.

The blockInfo parameter corresponds replayed block and the replayTo parameter corresponds to the block at the tip of the ImmutableDB, i.e., the last block to replay.

Instances

Instances details
Functor (TraceReplayEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Methods

fmap :: (a -> b) -> TraceReplayEvent blk a -> TraceReplayEvent blk b #

(<$) :: a -> TraceReplayEvent blk b -> TraceReplayEvent blk a #

Foldable (TraceReplayEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Methods

fold :: Monoid m => TraceReplayEvent blk m -> m #

foldMap :: Monoid m => (a -> m) -> TraceReplayEvent blk a -> m #

foldMap' :: Monoid m => (a -> m) -> TraceReplayEvent blk a -> m #

foldr :: (a -> b -> b) -> b -> TraceReplayEvent blk a -> b #

foldr' :: (a -> b -> b) -> b -> TraceReplayEvent blk a -> b #

foldl :: (b -> a -> b) -> b -> TraceReplayEvent blk a -> b #

foldl' :: (b -> a -> b) -> b -> TraceReplayEvent blk a -> b #

foldr1 :: (a -> a -> a) -> TraceReplayEvent blk a -> a #

foldl1 :: (a -> a -> a) -> TraceReplayEvent blk a -> a #

toList :: TraceReplayEvent blk a -> [a] #

null :: TraceReplayEvent blk a -> Bool #

length :: TraceReplayEvent blk a -> Int #

elem :: Eq a => a -> TraceReplayEvent blk a -> Bool #

maximum :: Ord a => TraceReplayEvent blk a -> a #

minimum :: Ord a => TraceReplayEvent blk a -> a #

sum :: Num a => TraceReplayEvent blk a -> a #

product :: Num a => TraceReplayEvent blk a -> a #

Traversable (TraceReplayEvent blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Methods

traverse :: Applicative f => (a -> f b) -> TraceReplayEvent blk a -> f (TraceReplayEvent blk b) #

sequenceA :: Applicative f => TraceReplayEvent blk (f a) -> f (TraceReplayEvent blk a) #

mapM :: Monad m => (a -> m b) -> TraceReplayEvent blk a -> m (TraceReplayEvent blk b) #

sequence :: Monad m => TraceReplayEvent blk (m a) -> m (TraceReplayEvent blk a) #

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

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Methods

(==) :: TraceReplayEvent blk replayTo -> TraceReplayEvent blk replayTo -> Bool #

(/=) :: TraceReplayEvent blk replayTo -> TraceReplayEvent blk replayTo -> Bool #

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

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Methods

showsPrec :: Int -> TraceReplayEvent blk replayTo -> ShowS #

show :: TraceReplayEvent blk replayTo -> String #

showList :: [TraceReplayEvent blk replayTo] -> ShowS #

Generic (TraceReplayEvent blk replayTo) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

Associated Types

type Rep (TraceReplayEvent blk replayTo) :: Type -> Type #

Methods

from :: TraceReplayEvent blk replayTo -> Rep (TraceReplayEvent blk replayTo) x #

to :: Rep (TraceReplayEvent blk replayTo) x -> TraceReplayEvent blk replayTo #

type Rep (TraceReplayEvent blk replayTo) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.OnDisk

ledgerDbCurrent :: LedgerDB l r -> l Source #

The ledger state at the tip of the chain

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