| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Storage.ChainDB.Impl.LgrDB
Description
Thin wrapper around the LedgerDB
Synopsis
- data LgrDB m blk
- type LedgerDB' blk = LedgerDB (ExtLedgerState blk) (RealPoint 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)))
- data LgrDbArgs f m blk = LgrDbArgs {
- lgrDiskPolicy :: HKD f DiskPolicy
- lgrGenesis :: HKD f (m (ExtLedgerState blk))
- lgrHasFS :: SomeHasFS m
- lgrParams :: HKD f LedgerDbParams
- lgrTopLevelConfig :: HKD f (TopLevelConfig blk)
- lgrTraceLedger :: Tracer m (LedgerDB' blk)
- lgrTracer :: Tracer m (TraceEvent blk)
- defaultArgs :: FilePath -> LgrDbArgs Defaults IO blk
- openDB :: forall m blk. (IOLike m, LedgerSupportsProtocol blk, LgrDbSerialiseConstraints blk, InspectLedger blk, HasCallStack) => LgrDbArgs Identity m blk -> Tracer m (TraceReplayEvent blk ()) -> ImmutableDB m blk -> (RealPoint blk -> m blk) -> m (LgrDB m blk, Word64)
- type TraceLedgerReplayEvent blk = TraceReplayEvent blk (Point blk)
- decorateReplayTracer :: Point blk -> Tracer m (TraceLedgerReplayEvent blk) -> Tracer m (TraceReplayEvent blk ())
- getCurrent :: IOLike m => LgrDB m blk -> STM m (LedgerDB' blk)
- setCurrent :: IOLike m => LgrDB m blk -> LedgerDB' blk -> STM m ()
- getCurrentState :: IOLike m => LgrDB m blk -> STM m (ExtLedgerState blk)
- getPastState :: (IOLike m, HasHeader blk) => LgrDB m blk -> Point blk -> STM m (Maybe (ExtLedgerState blk))
- getHeaderStateHistory :: IOLike m => LgrDB m blk -> STM m (HeaderStateHistory blk)
- currentPoint :: forall blk. UpdateLedger blk => LedgerDB' blk -> Point blk
- takeSnapshot :: forall m blk. (IOLike m, LgrDbSerialiseConstraints blk) => LgrDB m blk -> m (DiskSnapshot, Point blk)
- trimSnapshots :: MonadCatch m => LgrDB m blk -> m [DiskSnapshot]
- getDiskPolicy :: LgrDB m blk -> DiskPolicy
- validate :: forall m blk. (IOLike m, LedgerSupportsProtocol blk, HasCallStack) => LgrDB m blk -> LedgerDB' blk -> BlockCache blk -> Word64 -> [Header blk] -> m (ValidateResult blk)
- data ValidateResult blk
- getPrevApplied :: IOLike m => LgrDB m blk -> STM m (Set (RealPoint blk))
- garbageCollectPrevApplied :: IOLike m => LgrDB m blk -> SlotNo -> STM m ()
- data ExceededRollback = ExceededRollback {}
- data AnnLedgerError l r = AnnLedgerError {
- annLedgerState :: LedgerDB l r
- annLedgerErrRef :: r
- annLedgerErr :: LedgerErr l
- newtype LedgerDbParams = LedgerDbParams {}
- data DiskPolicy = DiskPolicy {}
- data DiskSnapshot
- data TraceEvent blk
- data TraceReplayEvent blk replayTo
- = ReplayFromGenesis replayTo
- | ReplayFromSnapshot DiskSnapshot (Point blk) replayTo
- | ReplayedBlock (RealPoint blk) [LedgerEvent blk] replayTo
- ledgerDbCurrent :: LedgerDB l r -> l
- mkLgrDB :: StrictTVar m (LedgerDB' blk) -> StrictTVar m (Set (RealPoint blk)) -> (RealPoint blk -> m blk) -> LgrDbArgs Identity m blk -> LgrDB m blk
Documentation
Thin wrapper around the ledger database
Instances
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
| |
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.
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
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.
getCurrentState :: IOLike m => LgrDB m blk -> STM m (ExtLedgerState blk) Source #
getPastState :: (IOLike m, HasHeader blk) => LgrDB m blk -> Point blk -> STM m (Maybe (ExtLedgerState blk)) Source #
getHeaderStateHistory :: IOLike m => LgrDB m blk -> STM m (HeaderStateHistory 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 #
trimSnapshots :: MonadCatch m => LgrDB m blk -> m [DiskSnapshot] Source #
getDiskPolicy :: LgrDB m blk -> DiskPolicy Source #
Validation
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 |
| -> BlockCache blk | |
| -> Word64 | How many blocks to roll back |
| -> [Header blk] | |
| -> m (ValidateResult blk) |
data ValidateResult blk Source #
Constructors
| ValidateSuccessful (LedgerDB' blk) | |
| ValidateLedgerError (AnnLedgerError' blk) | |
| ValidateExceededRollBack ExceededRollback |
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 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.
Constructors
| ExceededRollback | |
Fields | |
data AnnLedgerError l r Source #
Annotated ledger errors
Constructors
| AnnLedgerError | |
Fields
| |
Instances
| Monad m => ThrowsLedgerError l r (ExceptT (AnnLedgerError l r) m) Source # | |
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
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
| |
Instances
data DiskSnapshot Source #
On disk snapshots are numbered monotonically
Instances
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
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 |
| 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 |
| ReplayedBlock (RealPoint blk) [LedgerEvent blk] replayTo | We replayed the given block (reference) on the genesis snapshot during the initialisation of the LedgerDB. The |
Instances
ledgerDbCurrent :: LedgerDB l r -> l Source #
The ledger state at the tip of the chain