ouroboros-consensus-0.1.0.1: Consensus layer for the Ouroboros blockchain protocol
Safe Haskell None
Language Haskell2010

Ouroboros.Consensus.Storage.Serialisation

Description

Serialisation for on-disk storage.

We have separate classes for on-disk and on-the-wire serialisation, because the encoding formats of the same type may differ, depending on the context.

We separate the encoder from the decoder, because sometimes the encoded type will differ from the decoded one. For example, we encode a blk , but decode an ByteString -> blk (when reading something from disk, we have the precise bytestring that we can pass in as the annotation). If we coupled the encoder to the decoder, we wouldn't be able to cleanly model this use case. Moreover, sometimes we only need a single direction.

Synopsis

Serialisation to/from disk storage

class DecodeDisk blk a where Source #

Decode a type a read from disk.

There is no version negotiation for on disk serialisation. However, instances can still decide to perform versioning internally to maintain compatibility.

Minimal complete definition

Nothing

Instances

Instances details
DecodeDisk blk blk => DecodeDisk blk ( I blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

decodeDisk :: CodecConfig blk -> forall s. Decoder s ( I blk) Source #

DecodeDisk blk ( ChainDepState ( BlockProtocol blk)) => DecodeDisk blk ( WrapChainDepState blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

DecodeDiskDepIx ( NestedCtxt Header ) blk => DecodeDisk blk ( SerialisedHeader blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

( DecodeDiskDepIx f blk, DecodeDiskDep f blk) => DecodeDisk blk ( DepPair (f blk)) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

decodeDisk :: CodecConfig blk -> forall s. Decoder s ( DepPair (f blk)) Source #

DecodeDiskDepIx f blk => DecodeDisk blk ( GenDepPair Serialised (f blk)) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

DecodeDisk blk (a -> f blk) => DecodeDisk blk ((((->) a :: Type -> Type ) :.: f) blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

decodeDisk :: CodecConfig blk -> forall s. Decoder s (((->) a :.: f) blk) Source #

SerialiseHFC xs => DecodeDisk ( HardForkBlock xs) ( LedgerState ( HardForkBlock xs)) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk

SerialiseHFC xs => DecodeDisk ( HardForkBlock xs) ( HardForkChainDepState xs) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk

SerialiseHFC xs => DecodeDisk ( HardForkBlock xs) ( AnnTip ( HardForkBlock xs)) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk

SerialiseHFC xs => DecodeDisk ( HardForkBlock xs) ( ByteString -> HardForkBlock xs) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk

class EncodeDisk blk a where Source #

Encode a type a so that it can be stored on disk.

There is no version negotiation for on disk serialisation. However, instances can still decide to perform versioning internally to maintain compatibility.

Minimal complete definition

Nothing

Instances

Instances details
EncodeDisk blk blk => EncodeDisk blk ( I blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

EncodeDisk blk ( ChainDepState ( BlockProtocol blk)) => EncodeDisk blk ( WrapChainDepState blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

EncodeDiskDepIx ( NestedCtxt Header ) blk => EncodeDisk blk ( SerialisedHeader blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

( EncodeDiskDepIx f blk, EncodeDiskDep f blk) => EncodeDisk blk ( DepPair (f blk)) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

EncodeDiskDepIx f blk => EncodeDisk blk ( GenDepPair Serialised (f blk)) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

SerialiseHFC xs => EncodeDisk ( HardForkBlock xs) ( LedgerState ( HardForkBlock xs)) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk

SerialiseHFC xs => EncodeDisk ( HardForkBlock xs) ( HardForkChainDepState xs) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk

SerialiseHFC xs => EncodeDisk ( HardForkBlock xs) ( AnnTip ( HardForkBlock xs)) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk

SerialiseHFC xs => EncodeDisk ( HardForkBlock xs) ( HardForkBlock xs) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk

Support for dependent pairs

class DecodeDiskDep f blk where Source #

Decode a dependent value

Typical usage: f = NestedCtxt Header .

Minimal complete definition

Nothing

Serialised header

newtype SerialisedHeader blk Source #

A Serialised header along with context identifying what kind of header it is.

The SerialiseNodeToNodeDep for Header will decide how to actually encode this.

Instances

Instances details
Isomorphic SerialisedHeader Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Embed.Unary

Inject SerialisedHeader Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Embed.Nary

DecodeDiskDepIx ( NestedCtxt Header ) blk => DecodeDisk blk ( SerialisedHeader blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

EncodeDiskDepIx ( NestedCtxt Header ) blk => EncodeDisk blk ( SerialisedHeader blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

HasNestedContent Header blk => Show ( SerialisedHeader blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

StandardHash blk => StandardHash ( SerialisedHeader blk) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

ShowProxy blk => ShowProxy ( SerialisedHeader blk :: Type ) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

SerialiseHFC xs => SerialiseNodeToNode ( HardForkBlock xs) ( SerialisedHeader ( HardForkBlock xs)) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseNodeToNode

type HeaderHash ( SerialisedHeader blk) Source #

Only needed for the ChainSyncServer

Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

Reconstruct nested type

newtype PrefixLen Source #

Number of bytes from the start of a block needed to reconstruct the nested context.

See reconstructPrefixLen .

Instances

Instances details
Eq PrefixLen Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Common

Ord PrefixLen Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Common

Show PrefixLen Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Common

Generic PrefixLen Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Common

NoThunks PrefixLen Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Common

type Rep PrefixLen Source #
Instance details

Defined in Ouroboros.Consensus.Storage.Common

type Rep PrefixLen = D1 (' MetaData "PrefixLen" "Ouroboros.Consensus.Storage.Common" "ouroboros-consensus-0.1.0.1-DT4Cvwf63DZKctsEvaJqCU" ' True ) ( C1 (' MetaCons "PrefixLen" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getPrefixLen") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Word8 )))

class HasNestedContent f blk => ReconstructNestedCtxt f blk where Source #

Minimal complete definition

Nothing

Methods

reconstructPrefixLen :: proxy (f blk) -> PrefixLen Source #

Number of bytes required to reconstruct the nested context.

This will be the minimum length of the ShortByteString passed to reconstructNestedCtxt .

reconstructNestedCtxt Source #

Arguments

:: proxy (f blk)
-> ShortByteString

First bytes ( reconstructPrefixLen ) of the block

-> SizeInBytes

Block size

-> SomeSecond ( NestedCtxt f) blk

Reconstruct the type of nested contents

TODO: Allow to fail.

Binary block info

data BinaryBlockInfo Source #

Information about the serialised block.

Constructors

BinaryBlockInfo

Fields

  • headerOffset :: ! Word16

    The offset within the serialised block at which the header starts.

  • headerSize :: ! Word16

    How many bytes the header is long. Extracting the headerSize bytes from serialised block starting from headerOffset should yield the header. Before passing the extracted bytes to the decoder for headers, an envelope can be around using nodeAddHeaderEnvelope .

class HasBinaryBlockInfo blk where Source #

Methods

getBinaryBlockInfo :: blk -> BinaryBlockInfo Source #

Return information about the serialised block, i.e., how to extract the bytes corresponding to the header from the serialised block.

Instances

Instances details
SerialiseHFC xs => HasBinaryBlockInfo ( HardForkBlock xs) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk

HasBinaryBlockInfo m => HasBinaryBlockInfo ( DualBlock m a) Source #

The binary info just refers to the main block

This is sufficient, because we never need just the header of the auxiliary.

Instance details

Defined in Ouroboros.Consensus.Ledger.Dual

Re-exported for convenience

Exported for the benefit of tests