| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Storage.ChainDB.Impl.Types
Description
Types used throughout the implementation: handle, state, environment, types, trace types, etc.
Synopsis
- class (ImmutableDbSerialiseConstraints blk, LgrDbSerialiseConstraints blk, VolatileDbSerialiseConstraints blk, EncodeDiskDep (NestedCtxt Header) blk) => SerialiseDiskConstraints blk
- newtype ChainDbHandle m blk = CDBHandle (StrictTVar m (ChainDbState m blk))
- getEnv :: forall m blk r. (IOLike m, HasCallStack) => ChainDbHandle m blk -> (ChainDbEnv m blk -> m r) -> m r
- getEnv1 :: (IOLike m, HasCallStack) => ChainDbHandle m blk -> (ChainDbEnv m blk -> a -> m r) -> a -> m r
- getEnv2 :: (IOLike m, HasCallStack) => ChainDbHandle m blk -> (ChainDbEnv m blk -> a -> b -> m r) -> a -> b -> m r
- getEnvSTM :: forall m blk r. (IOLike m, HasCallStack) => ChainDbHandle m blk -> (ChainDbEnv m blk -> STM m r) -> STM m r
- getEnvSTM1 :: (IOLike m, HasCallStack) => ChainDbHandle m blk -> (ChainDbEnv m blk -> a -> STM m r) -> a -> STM m r
- data ChainDbState m blk
- = ChainDbOpen !(ChainDbEnv m blk)
- | ChainDbClosed
- data ChainDbEnv m blk = CDB {
- cdbImmutableDB :: !(ImmutableDB m blk)
- cdbVolatileDB :: !(VolatileDB m blk)
- cdbLgrDB :: !(LgrDB m blk)
- cdbChain :: !(StrictTVar m (AnchoredFragment (Header blk)))
- cdbIterators :: !(StrictTVar m (Map IteratorKey (m ())))
- cdbReaders :: !(StrictTVar m (Map ReaderKey (ReaderHandle m blk)))
- cdbTopLevelConfig :: !(TopLevelConfig blk)
- cdbInvalid :: !(StrictTVar m (WithFingerprint (InvalidBlocks blk)))
- cdbNextIteratorKey :: !(StrictTVar m IteratorKey)
- cdbNextReaderKey :: !(StrictTVar m ReaderKey)
- cdbCopyLock :: !(StrictMVar m ())
- cdbTracer :: !(Tracer m (TraceEvent blk))
- cdbTraceLedger :: !(Tracer m (LedgerDB' blk))
- cdbRegistry :: !(ResourceRegistry m)
- cdbGcDelay :: !DiffTime
- cdbGcInterval :: !DiffTime
- cdbKillBgThreads :: !(StrictTVar m (m ()))
- cdbChunkInfo :: !ChunkInfo
- cdbCheckIntegrity :: !(blk -> Bool)
- cdbCheckInFuture :: !(CheckInFuture m blk)
- cdbBlocksToAdd :: !(BlocksToAdd m blk)
- cdbFutureBlocks :: !(StrictTVar m (FutureBlocks blk))
- data Internal m blk = Internal {
- intCopyToImmutableDB :: m (WithOrigin SlotNo)
- intGarbageCollect :: SlotNo -> m ()
- intUpdateLedgerSnapshots :: m ()
- intAddBlockRunner :: m Void
- intKillBgThreads :: StrictTVar m (m ())
- newtype IteratorKey = IteratorKey Word
- newtype ReaderKey = ReaderKey Word
- data ReaderHandle m blk = ReaderHandle {
- rhSwitchFork :: Point blk -> AnchoredFragment (Header blk) -> STM m ()
- rhClose :: m ()
- data ReaderState m blk b
- = ReaderInit
- | ReaderInImmutableDB !(ReaderRollState blk) !(Iterator m blk (Point blk, b))
- | ReaderInMem !(ReaderRollState blk)
- data ReaderRollState blk
- = RollBackTo !(Point blk)
- | RollForwardFrom !(Point blk)
- readerRollStatePoint :: ReaderRollState blk -> Point blk
- type InvalidBlocks blk = Map (HeaderHash blk) (InvalidBlockInfo blk)
- data InvalidBlockInfo blk = InvalidBlockInfo {
- invalidBlockReason :: !(InvalidBlockReason blk)
- invalidBlockSlotNo :: !SlotNo
- type FutureBlocks blk = Map (HeaderHash blk) (Header blk)
- data BlocksToAdd m blk
- data BlockToAdd m blk = BlockToAdd {
- blockToAdd :: !blk
- varBlockWrittenToDisk :: !(StrictTMVar m Bool)
- varBlockProcessed :: !(StrictTMVar m (Point blk))
- newBlocksToAdd :: IOLike m => Word -> m (BlocksToAdd m blk)
- addBlockToAdd :: (IOLike m, HasHeader blk) => Tracer m (TraceAddBlockEvent blk) -> BlocksToAdd m blk -> blk -> m (AddBlockPromise m blk)
- getBlockToAdd :: IOLike m => BlocksToAdd m blk -> m (BlockToAdd m blk)
- data TraceEvent blk
- = TraceAddBlockEvent (TraceAddBlockEvent blk)
- | TraceReaderEvent (TraceReaderEvent blk)
- | TraceCopyToImmutableDBEvent (TraceCopyToImmutableDBEvent blk)
- | TraceGCEvent (TraceGCEvent blk)
- | TraceInitChainSelEvent (TraceInitChainSelEvent blk)
- | TraceOpenEvent (TraceOpenEvent blk)
- | TraceIteratorEvent (TraceIteratorEvent blk)
- | TraceLedgerEvent (TraceEvent blk)
- | TraceLedgerReplayEvent (TraceLedgerReplayEvent blk)
- | TraceImmutableDBEvent (TraceEvent blk)
- | TraceVolatileDBEvent (TraceEvent blk)
- data NewTipInfo blk = NewTipInfo {
- newTipPoint :: RealPoint blk
- newTipEpoch :: EpochNo
- newTipSlotInEpoch :: Word64
- newTipTrigger :: RealPoint blk
- data TraceAddBlockEvent blk
- = IgnoreBlockOlderThanK (RealPoint blk)
- | IgnoreBlockAlreadyInVolatileDB (RealPoint blk)
- | IgnoreInvalidBlock (RealPoint blk) (InvalidBlockReason blk)
- | AddedBlockToQueue (RealPoint blk) Word
- | BlockInTheFuture (RealPoint blk) SlotNo
- | AddedBlockToVolatileDB (RealPoint blk) BlockNo IsEBB
- | TryAddToCurrentChain (RealPoint blk)
- | TrySwitchToAFork (RealPoint blk) (ChainDiff (HeaderFields blk))
- | StoreButDontChange (RealPoint blk)
- | AddedToCurrentChain [LedgerEvent blk] (NewTipInfo blk) (AnchoredFragment (Header blk)) (AnchoredFragment (Header blk))
- | SwitchedToAFork [LedgerEvent blk] (NewTipInfo blk) (AnchoredFragment (Header blk)) (AnchoredFragment (Header blk))
- | AddBlockValidation (TraceValidationEvent blk)
- | ChainSelectionForFutureBlock (RealPoint blk)
- data TraceReaderEvent blk
- = NewReader
- | ReaderNoLongerInMem (ReaderRollState blk)
- | ReaderSwitchToMem (Point blk) (WithOrigin SlotNo)
- | ReaderNewImmIterator (Point blk) (WithOrigin SlotNo)
- data TraceCopyToImmutableDBEvent blk
- data TraceGCEvent blk
- data TraceValidationEvent blk
- = InvalidBlock (ExtValidationError blk) (RealPoint blk)
- | InvalidCandidate (AnchoredFragment (Header blk))
- | ValidCandidate (AnchoredFragment (Header blk))
- | CandidateContainsFutureBlocks (AnchoredFragment (Header blk)) [Header blk]
- | CandidateContainsFutureBlocksExceedingClockSkew (AnchoredFragment (Header blk)) [Header blk]
- data TraceInitChainSelEvent blk = InitChainSelValidation (TraceValidationEvent blk)
- data TraceOpenEvent blk
- = OpenedDB (Point blk) (Point blk)
- | ClosedDB (Point blk) (Point blk)
- | OpenedImmutableDB (Point blk) ChunkNo
- | OpenedVolatileDB
- | OpenedLgrDB
- data TraceIteratorEvent blk
- = UnknownRangeRequested (UnknownRange blk)
- | StreamFromVolatileDB (StreamFrom blk) (StreamTo blk) [RealPoint blk]
- | StreamFromImmutableDB (StreamFrom blk) (StreamTo blk)
- | StreamFromBoth (StreamFrom blk) (StreamTo blk) [RealPoint blk]
- | BlockMissingFromVolatileDB (RealPoint blk)
- | BlockWasCopiedToImmutableDB (RealPoint blk)
- | BlockGCedFromVolatileDB (RealPoint blk)
- | SwitchBackToVolatileDB
Documentation
class (ImmutableDbSerialiseConstraints blk, LgrDbSerialiseConstraints blk, VolatileDbSerialiseConstraints blk, EncodeDiskDep (NestedCtxt Header) blk) => SerialiseDiskConstraints blk Source #
All the serialisation related constraints needed by the ChainDB.
Instances
newtype ChainDbHandle m blk Source #
A handle to the internal ChainDB state
Constructors
| CDBHandle (StrictTVar m (ChainDbState m blk)) |
getEnv :: forall m blk r. (IOLike m, HasCallStack) => ChainDbHandle m blk -> (ChainDbEnv m blk -> m r) -> m r Source #
Check if the ChainDB is open, if so, executing the given function on the
ChainDbEnv, otherwise, throw a CloseDBError.
getEnv1 :: (IOLike m, HasCallStack) => ChainDbHandle m blk -> (ChainDbEnv m blk -> a -> m r) -> a -> m r Source #
Variant 'of getEnv for functions taking one argument.
getEnv2 :: (IOLike m, HasCallStack) => ChainDbHandle m blk -> (ChainDbEnv m blk -> a -> b -> m r) -> a -> b -> m r Source #
Variant 'of getEnv for functions taking two arguments.
getEnvSTM :: forall m blk r. (IOLike m, HasCallStack) => ChainDbHandle m blk -> (ChainDbEnv m blk -> STM m r) -> STM m r Source #
getEnvSTM1 :: (IOLike m, HasCallStack) => ChainDbHandle m blk -> (ChainDbEnv m blk -> a -> STM m r) -> a -> STM m r Source #
data ChainDbState m blk Source #
Constructors
| ChainDbOpen !(ChainDbEnv m blk) | |
| ChainDbClosed |
Instances
| Generic (ChainDbState m blk) Source # | |
Defined in Ouroboros.Consensus.Storage.ChainDB.Impl.Types Associated Types type Rep (ChainDbState m blk) :: Type -> Type # Methods from :: ChainDbState m blk -> Rep (ChainDbState m blk) x # to :: Rep (ChainDbState m blk) x -> ChainDbState m blk # | |
| (IOLike m, LedgerSupportsProtocol blk) => NoThunks (ChainDbState m blk) Source # | |
| type Rep (ChainDbState m blk) Source # | |
Defined in Ouroboros.Consensus.Storage.ChainDB.Impl.Types type Rep (ChainDbState m blk) = D1 ('MetaData "ChainDbState" "Ouroboros.Consensus.Storage.ChainDB.Impl.Types" "ouroboros-consensus-0.1.0.0-GfJNvFcM6lj2s5utKAUPEp" 'False) (C1 ('MetaCons "ChainDbOpen" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (ChainDbEnv m blk))) :+: C1 ('MetaCons "ChainDbClosed" 'PrefixI 'False) (U1 :: Type -> Type)) | |
data ChainDbEnv m blk Source #
Constructors
| CDB | |
Fields
| |
Instances
Exposed internals for testing purposes
Constructors
| Internal | |
Fields
| |
Iterator-related
newtype IteratorKey Source #
We use this internally to track iterators in a map (cdbIterators) in
the ChainDB state so that we can remove them from the map when the iterator
is closed.
We store them in the map so that the ChainDB can close all open iterators when it is closed itself.
Constructors
| IteratorKey Word |
Instances
Reader-related
We use this internally to track reader in a map (cdbReaders) in the
ChainDB state so that we can remove them from the map when the reader is
closed.
We store them in the map so that the ChainDB can close all open readers when it is closed itself and to update the readers in case we switch to a different chain.
Instances
| Enum ReaderKey Source # | |
Defined in Ouroboros.Consensus.Storage.ChainDB.Impl.Types Methods succ :: ReaderKey -> ReaderKey # pred :: ReaderKey -> ReaderKey # fromEnum :: ReaderKey -> Int # enumFrom :: ReaderKey -> [ReaderKey] # enumFromThen :: ReaderKey -> ReaderKey -> [ReaderKey] # enumFromTo :: ReaderKey -> ReaderKey -> [ReaderKey] # enumFromThenTo :: ReaderKey -> ReaderKey -> ReaderKey -> [ReaderKey] # | |
| Eq ReaderKey Source # | |
| Ord ReaderKey Source # | |
| Show ReaderKey Source # | |
| NoThunks ReaderKey Source # | |
data ReaderHandle m blk Source #
Internal handle to a Reader without an explicit b (blk, , etc.) parameter so Header
blkReaders with different' bs can be stored
together in cdbReaders.
Constructors
| ReaderHandle | |
Fields
| |
Instances
| NoThunks (ReaderHandle m blk) Source # | |
data ReaderState m blk b Source #
b corresponds to the BlockComponent that is being read.
Constructors
| ReaderInit | The This is equivalent to having a Therefore, we have this extra initial state, that avoids this cost. When the user doesn't move the Reader forward, an iterator is opened. |
| ReaderInImmutableDB !(ReaderRollState blk) !(Iterator m blk (Point blk, b)) | The Note that the iterator includes 'Point blk' in addition to INVARIANT: for all |
| ReaderInMem !(ReaderRollState blk) | The |
Instances
data ReaderRollState blk Source #
Similar to ReaderState.
Constructors
| RollBackTo !(Point blk) | We don't know at which point the user is, but the next message we'll send is to roll back to this point. |
| RollForwardFrom !(Point blk) | We know that the reader is at this point and the next message we'll send is to roll forward to the point after this point on our chain. |
Instances
readerRollStatePoint :: ReaderRollState blk -> Point blk Source #
Get the point the ReaderRollState should roll back to or roll forward
from.
Invalid blocks
type InvalidBlocks blk = Map (HeaderHash blk) (InvalidBlockInfo blk) Source #
Hashes corresponding to invalid blocks. This is used to ignore these blocks during chain selection.
data InvalidBlockInfo blk Source #
In addition to the reason why a block is invalid, the slot number of the
block is stored, so that whenever a garbage collection is performed on the
VolatileDB for some slot s, the hashes older or equal to s can be
removed from this map.
Constructors
| InvalidBlockInfo | |
Fields
| |
Instances
Future blocks
type FutureBlocks blk = Map (HeaderHash blk) (Header blk) Source #
Blocks from the future for which we still need to trigger chain selection.
See cdbFutureBlocks for more info.
Blocks to add
data BlocksToAdd m blk Source #
FIFO queue used to add blocks asynchronously to the ChainDB. Blocks are read from this queue by a background thread, which processes the blocks synchronously.
Instances
| NoThunks (BlocksToAdd m blk) Source # | |
data BlockToAdd m blk Source #
Entry in the BlocksToAdd queue: a block together with the TMVars used
to implement AddBlockPromise.
Constructors
| BlockToAdd | |
Fields
| |
newBlocksToAdd :: IOLike m => Word -> m (BlocksToAdd m blk) Source #
Create a new BlocksToAdd with the given size.
addBlockToAdd :: (IOLike m, HasHeader blk) => Tracer m (TraceAddBlockEvent blk) -> BlocksToAdd m blk -> blk -> m (AddBlockPromise m blk) Source #
Add a block to the BlocksToAdd queue. Can block when the queue is full.
getBlockToAdd :: IOLike m => BlocksToAdd m blk -> m (BlockToAdd m blk) Source #
Get the oldest block from the BlocksToAdd queue. Can block when the
queue is empty.
Trace types
data TraceEvent blk Source #
Trace type for the various events of the ChainDB.
Constructors
Instances
data NewTipInfo blk Source #
Information about the new tip of the current chain.
NOTE: the fields of this record are intentionally lazy to prevent the forcing of this information in case it doesn't have to be traced. However, this means that the tracer processing this message must not hold on to it, otherwise it leaks memory.
Constructors
| NewTipInfo | |
Fields
| |
Instances
data TraceAddBlockEvent blk Source #
Trace type for the various events that occur when adding a block.
Constructors
| IgnoreBlockOlderThanK (RealPoint blk) | A block with a |
| IgnoreBlockAlreadyInVolatileDB (RealPoint blk) | A block that is already in the Volatile DB was ignored. |
| IgnoreInvalidBlock (RealPoint blk) (InvalidBlockReason blk) | A block that is know to be invalid was ignored. |
| AddedBlockToQueue (RealPoint blk) Word | The block was added to the queue and will be added to the ChainDB by the background thread. The size of the queue is included. |
| BlockInTheFuture (RealPoint blk) SlotNo | The block is from the future, i.e., its slot number is greater than the current slot (the second argument). |
| AddedBlockToVolatileDB (RealPoint blk) BlockNo IsEBB | A block was added to the Volatile DB |
| TryAddToCurrentChain (RealPoint blk) | The block fits onto the current chain, we'll try to use it to extend our chain. |
| TrySwitchToAFork (RealPoint blk) (ChainDiff (HeaderFields blk)) | The block fits onto some fork, we'll try to switch to that fork (if it is preferable to our chain). |
| StoreButDontChange (RealPoint blk) | The block doesn't fit onto any other block, so we store it and ignore it. |
| AddedToCurrentChain [LedgerEvent blk] (NewTipInfo blk) (AnchoredFragment (Header blk)) (AnchoredFragment (Header blk)) | The new block fits onto the current chain (first fragment) and we have successfully used it to extend our (new) current chain (second fragment). |
| SwitchedToAFork [LedgerEvent blk] (NewTipInfo blk) (AnchoredFragment (Header blk)) (AnchoredFragment (Header blk)) | The new block fits onto some fork and we have switched to that fork (second fragment), as it is preferable to our (previous) current chain (first fragment). |
| AddBlockValidation (TraceValidationEvent blk) | An event traced during validating performed while adding a block. |
| ChainSelectionForFutureBlock (RealPoint blk) | Run chain selection for a block that was previously from the future. This is done for all blocks from the future each time a new block is added. |
Instances
data TraceReaderEvent blk Source #
Constructors
| NewReader | A new reader was created. |
| ReaderNoLongerInMem (ReaderRollState blk) | The reader was in the |
| ReaderSwitchToMem | The reader was in the |
Fields
| |
| ReaderNewImmIterator | The reader is in the |
Fields
| |
Instances
data TraceCopyToImmutableDBEvent blk Source #
Constructors
| CopiedBlockToImmutableDB (Point blk) | A block was successfully copied to the ImmutableDB. |
| NoBlocksToCopyToImmutableDB | There are no block to copy to the ImmutableDB. |
Instances
data TraceGCEvent blk Source #
Constructors
| ScheduledGC SlotNo Time | A garbage collection for the given |
| PerformedGC SlotNo | A garbage collection for the given |
Instances
data TraceValidationEvent blk Source #
Constructors
| InvalidBlock (ExtValidationError blk) (RealPoint blk) | A point was found to be invalid. |
| InvalidCandidate (AnchoredFragment (Header blk)) | A candidate chain was invalid. |
| ValidCandidate (AnchoredFragment (Header blk)) | A candidate chain was valid. |
| CandidateContainsFutureBlocks | Candidate contains headers from the future which do no exceed the clock skew. |
| CandidateContainsFutureBlocksExceedingClockSkew | Candidate contains headers from the future which exceed the clock skew, making them invalid. |
Instances
data TraceInitChainSelEvent blk Source #
Constructors
| InitChainSelValidation (TraceValidationEvent blk) | An event traced during validation performed while performing initial chain selection. |
Instances
data TraceOpenEvent blk Source #
Constructors
| OpenedDB | The ChainDB was opened. |
| ClosedDB | The ChainDB was closed. |
| OpenedImmutableDB | The ImmutableDB was opened. |
| OpenedVolatileDB | The VolatileDB was opened. |
| OpenedLgrDB | The LedgerDB was opened. |
Instances
data TraceIteratorEvent blk Source #
Constructors
| UnknownRangeRequested (UnknownRange blk) | An unknown range was requested, see |
| StreamFromVolatileDB (StreamFrom blk) (StreamTo blk) [RealPoint blk] | Stream only from the VolatileDB. |
| StreamFromImmutableDB (StreamFrom blk) (StreamTo blk) | Stream only from the ImmutableDB. |
| StreamFromBoth (StreamFrom blk) (StreamTo blk) [RealPoint blk] | Stream from both the VolatileDB and the ImmutableDB. |
| BlockMissingFromVolatileDB (RealPoint blk) | A block is no longer in the VolatileDB because it has been garbage collected. It might now be in the ImmutableDB if it was part of the current chain. |
| BlockWasCopiedToImmutableDB (RealPoint blk) | A block that has been garbage collected from the VolatileDB is now found and streamed from the ImmutableDB. |
| BlockGCedFromVolatileDB (RealPoint blk) | A block is no longer in the VolatileDB and isn't in the ImmutableDB either; it wasn't part of the current chain. |
| SwitchBackToVolatileDB | We have streamed one or more blocks from the ImmutableDB that were part of the VolatileDB when initialising the iterator. Now, we have to look back in the VolatileDB again because the ImmutableDB doesn't have the next block we're looking for. |