ouroboros-consensus-0.18.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ouroboros.Consensus.Storage.ImmutableDB.Impl.Parser

Synopsis

Documentation

data BlockSummary blk Source #

Information about a block returned by the parser.

The fields of this record are strict to make sure that by evaluating this record to WHNF, we no longer hold on to the entire block. Otherwise, we might accidentally keep all blocks in a single file in memory during parsing.

Constructors

BlockSummary 

data ChunkFileError blk Source #

Defined here instead of in the Parser module because TraceEvent depends on it.

Constructors

ChunkErrRead ReadIncrementalErr

A block could not be decoded

ChunkErrHashMismatch

The previous hash of a block did not match the hash of the previous block.

Fields

ChunkErrCorrupt (Point blk)

The integrity verification of the block with the given point returned False, indicating that the block got corrupted.

Instances

Instances details
StandardHash blk ⇒ Show (ChunkFileError blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.ImmutableDB.Impl.Types

Methods

showsPrecIntChunkFileError blk → ShowS #

showChunkFileError blk → String #

showList ∷ [ChunkFileError blk] → ShowS #

StandardHash blk ⇒ Eq (ChunkFileError blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.ImmutableDB.Impl.Types

Methods

(==)ChunkFileError blk → ChunkFileError blk → Bool #

(/=)ChunkFileError blk → ChunkFileError blk → Bool #

parseChunkFile Source #

Arguments

∷ ∀ m blk h r. (IOLike m, GetPrevHash blk, HasBinaryBlockInfo blk, DecodeDisk blk (ByteString → blk)) 
CodecConfig blk 
HasFS m h 
→ (blk → Bool)

Check integrity of the block. False = corrupt.

FsPath 
→ [CRC] 
→ (Stream (Of (BlockSummary blk, ChainHash blk)) m (Maybe (ChunkFileError blk, Word64)) → m r) 
→ m r 

Parse the contents of a chunk file.

  • The parser decodes each block in the chunk. When one of them fails to decode, a ChunkErrRead error is returned.
  • Each block's checksum is checked against its given expected checksum (coming from the secondary index). When a checksum doesn't match, a ChunkErrCorrupt error is returned. When the secondary index is missing or corrupt, and there are no or fewer expected checksums, we use the given (more expensive) integrity checking function instead of checksum comparison.
  • We check that each block fits onto the previous one by checking the hashes. If not, we return a ChunkErrHashMismatch error.
  • An error is returned in the form of:
'Maybe' ('ChunkFileError' blk, 'Word64')

The Word64 corresponds to the offset in the file where the last valid entry ends. Truncating to this offset will remove all invalid data from the file and just leave the valid entries before it. Note that we are not using Either because the error might occur after some valid entries have been parsed successfully, in which case we still want these valid entries, but also want to know about the error so we can truncate the file to get rid of the unparseable data.