ouroboros-consensus-0.1.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellNone
LanguageHaskell2010

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

Methods

decodeDiskCodecConfig blk → ∀ s. Decoder s a Source #

default decodeDiskSerialise a ⇒ CodecConfig blk → ∀ s. Decoder s a Source #

Instances

Instances details
DecodeDisk blk blk ⇒ DecodeDisk blk (I blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

decodeDiskCodecConfig blk → ∀ s. Decoder s (I blk) Source #

DecodeDisk blk (ChainDepState (BlockProtocol blk)) ⇒ DecodeDisk blk (WrapChainDepState blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

decodeDiskCodecConfig blk → ∀ s. Decoder s (WrapChainDepState blk) Source #

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

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

decodeDiskCodecConfig blk → ∀ s. Decoder s (SerialisedHeader blk) Source #

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

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

decodeDiskCodecConfig blk → ∀ 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

Methods

decodeDiskCodecConfig blk → ∀ s. Decoder s (GenDepPair Serialised (f blk)) Source #

DecodeDisk blk (a → f blk) ⇒ DecodeDisk blk ((((->) a ∷ TypeType) :.: f) blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

decodeDiskCodecConfig blk → ∀ 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

Methods

decodeDiskCodecConfig (HardForkBlock xs) → ∀ s. Decoder s (LedgerState (HardForkBlock xs)) Source #

SerialiseHFC xs ⇒ DecodeDisk (HardForkBlock xs) (HardForkChainDepState xs) Source # 
Instance details

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

Methods

decodeDiskCodecConfig (HardForkBlock xs) → ∀ s. Decoder s (HardForkChainDepState xs) Source #

SerialiseHFC xs ⇒ DecodeDisk (HardForkBlock xs) (AnnTip (HardForkBlock xs)) Source # 
Instance details

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

Methods

decodeDiskCodecConfig (HardForkBlock xs) → ∀ s. Decoder s (AnnTip (HardForkBlock xs)) Source #

SerialiseHFC xs ⇒ DecodeDisk (HardForkBlock xs) (ByteStringHardForkBlock xs) Source # 
Instance details

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

Methods

decodeDiskCodecConfig (HardForkBlock xs) → ∀ s. Decoder s (ByteStringHardForkBlock xs) Source #

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

Methods

encodeDiskCodecConfig blk → a → Encoding Source #

default encodeDiskSerialise a ⇒ CodecConfig blk → a → Encoding Source #

Instances

Instances details
EncodeDisk blk blk ⇒ EncodeDisk blk (I blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

encodeDiskCodecConfig blk → I blk → Encoding Source #

EncodeDisk blk (ChainDepState (BlockProtocol blk)) ⇒ EncodeDisk blk (WrapChainDepState blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

encodeDiskCodecConfig blk → WrapChainDepState blk → Encoding Source #

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

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

encodeDiskCodecConfig blk → SerialisedHeader blk → Encoding Source #

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

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

encodeDiskCodecConfig blk → DepPair (f blk) → Encoding Source #

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

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

encodeDiskCodecConfig blk → GenDepPair Serialised (f blk) → Encoding Source #

SerialiseHFC xs ⇒ EncodeDisk (HardForkBlock xs) (LedgerState (HardForkBlock xs)) Source # 
Instance details

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

Methods

encodeDiskCodecConfig (HardForkBlock xs) → LedgerState (HardForkBlock xs) → Encoding Source #

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

Methods

encodeDiskCodecConfig (HardForkBlock xs) → AnnTip (HardForkBlock xs) → Encoding Source #

SerialiseHFC xs ⇒ EncodeDisk (HardForkBlock xs) (HardForkBlock xs) Source # 
Instance details

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

Methods

encodeDiskCodecConfig (HardForkBlock xs) → HardForkBlock xs → Encoding Source #

Support for dependent pairs

class DecodeDiskDep f blk where Source #

Decode a dependent value

Typical usage: f = NestedCtxt Header.

Minimal complete definition

Nothing

Methods

decodeDiskDepCodecConfig blk → f blk a → ∀ s. Decoder s (ByteString → a) Source #

default decodeDiskDep ∷ (TrivialDependency (f blk), DecodeDisk blk (ByteStringTrivialIndex (f blk))) ⇒ CodecConfig blk → f blk a → ∀ s. Decoder s (ByteString → a) Source #

Instances

Instances details
SerialiseHFC xs ⇒ DecodeDiskDep (NestedCtxt Header) (HardForkBlock xs) Source # 
Instance details

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

Methods

decodeDiskDepCodecConfig (HardForkBlock xs) → NestedCtxt Header (HardForkBlock xs) a → ∀ s. Decoder s (ByteString → a) Source #

class DecodeDiskDepIx f blk where Source #

Decode dependent index

Minimal complete definition

Nothing

Methods

decodeDiskDepIxCodecConfig blk → Decoder s (SomeSecond f blk) Source #

default decodeDiskDepIxTrivialDependency (f blk) ⇒ CodecConfig blk → Decoder s (SomeSecond f blk) Source #

class EncodeDiskDep f blk where Source #

Encode a dependent value

Minimal complete definition

Nothing

Methods

encodeDiskDepCodecConfig blk → f blk a → a → Encoding Source #

default encodeDiskDep ∷ (TrivialDependency (f blk), EncodeDisk blk (TrivialIndex (f blk))) ⇒ CodecConfig blk → f blk a → a → Encoding Source #

class EncodeDiskDepIx f blk where Source #

Encode dependent index

Minimal complete definition

Nothing

Methods

encodeDiskDepIxCodecConfig blk → SomeSecond f blk → Encoding Source #

default encodeDiskDepIxTrivialDependency (f blk) ⇒ CodecConfig blk → SomeSecond f blk → Encoding Source #

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

Methods

inject ∷ ∀ x (xs ∷ [Type]). CanHardFork xs ⇒ Exactly xs BoundIndex xs x → SerialisedHeader x → SerialisedHeader (HardForkBlock xs) Source #

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

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

decodeDiskCodecConfig blk → ∀ s. Decoder s (SerialisedHeader blk) Source #

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

Defined in Ouroboros.Consensus.Storage.Serialisation

Methods

encodeDiskCodecConfig blk → SerialisedHeader blk → Encoding Source #

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

encodeTrivialSerialisedHeader ∷ ∀ blk. TrivialDependency (NestedCtxt_ blk Header) ⇒ SerialisedHeader blk → Encoding Source #

Encode the header without the NestedCtxt

Uses CBOR-in-CBOR

Reconstruct nested type

newtype PrefixLen Source #

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

See reconstructPrefixLen.

Constructors

PrefixLen 

Fields

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

Associated Types

type Rep PrefixLenTypeType Source #

NoThunks PrefixLen Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.Common

Methods

noThunks ∷ Context → PrefixLenIO (Maybe ThunkInfo) #

wNoThunks ∷ Context → PrefixLenIO (Maybe ThunkInfo) #

showTypeOfProxy PrefixLenString #

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.0-inplace" '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.

default reconstructPrefixLenTrivialDependency (NestedCtxt_ blk f) ⇒ proxy (f blk) → PrefixLen Source #

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.

Instances

Instances details
Eq BinaryBlockInfo Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.Common

Show BinaryBlockInfo Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.Common

Generic BinaryBlockInfo Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.Common

Associated Types

type Rep BinaryBlockInfoTypeType Source #

type Rep BinaryBlockInfo Source # 
Instance details

Defined in Ouroboros.Consensus.Storage.Common

type Rep BinaryBlockInfo = D1 ('MetaData "BinaryBlockInfo" "Ouroboros.Consensus.Storage.Common" "ouroboros-consensus-0.1.0.0-inplace" 'False) (C1 ('MetaCons "BinaryBlockInfo" 'PrefixI 'True) (S1 ('MetaSel ('Just "headerOffset") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word16) :*: S1 ('MetaSel ('Just "headerSize") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word16)))

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

decodeDepPairDecodeDiskDep f blk ⇒ CodecConfig blk → GenDepPair Serialised (f blk) → Decoder s (DepPair (f blk)) Source #

encodeDepPairEncodeDiskDep f blk ⇒ CodecConfig blk → DepPair (f blk) → GenDepPair Serialised (f blk) Source #