| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common
Synopsis
- class (CanHardFork xs, All SerialiseConstraintsHFC xs, All (Compose Show EraNodeToNodeVersion) xs, All (Compose Eq EraNodeToNodeVersion) xs, All (Compose Show EraNodeToClientVersion) xs, All (Compose Eq EraNodeToClientVersion) xs, All (EncodeDiskDepIx (NestedCtxt Header)) xs, All (DecodeDiskDepIx (NestedCtxt Header)) xs, All HasBinaryBlockInfo xs) => SerialiseHFC xs where
- encodeDiskHfcBlock :: CodecConfig (HardForkBlock xs) -> HardForkBlock xs -> Encoding
- decodeDiskHfcBlock :: CodecConfig (HardForkBlock xs) -> forall s. Decoder s (ByteString -> HardForkBlock xs)
- reconstructHfcPrefixLen :: proxy (Header (HardForkBlock xs)) -> PrefixLen
- reconstructHfcNestedCtxt :: proxy (Header (HardForkBlock xs)) -> ShortByteString -> SizeInBytes -> SomeSecond (NestedCtxt Header) (HardForkBlock xs)
- getHfcBinaryBlockInfo :: HardForkBlock xs -> BinaryBlockInfo
- estimateHfcBlockSize :: Header (HardForkBlock xs) -> SizeInBytes
- class (SingleEraBlock blk, SerialiseDiskConstraints blk, SerialiseNodeToNodeConstraints blk, SerialiseNodeToClientConstraints blk, HasNetworkProtocolVersion blk) => SerialiseConstraintsHFC blk
- pSHFC :: Proxy SerialiseConstraintsHFC
- data HardForkEncoderException where
- futureEraException :: SListI xs => NS SingleEraInfo xs -> HardForkEncoderException
- disabledEraException :: forall blk. SingleEraBlock blk => Proxy blk -> HardForkEncoderException
- type family FirstEra (xs :: [Type]) where ...
- type family LaterEra (xs :: [Type]) where ...
- isFirstEra :: forall f xs. All SingleEraBlock xs => NS f xs -> Either (NS SingleEraInfo (LaterEra xs)) (f (FirstEra xs))
- notFirstEra :: All SingleEraBlock xs => NS f xs -> NS SingleEraInfo xs
- data HardForkSpecificNodeToNodeVersion = HardForkSpecificNodeToNodeVersion1
- data HardForkSpecificNodeToClientVersion
- data HardForkNodeToNodeVersion xs where
- data HardForkNodeToClientVersion xs where
- data EraNodeToNodeVersion blk
- data EraNodeToClientVersion blk
- isHardForkNodeToNodeEnabled :: HardForkNodeToNodeVersion xs -> Bool
- isHardForkNodeToClientEnabled :: HardForkNodeToClientVersion xs -> Bool
- data AnnDecoder f blk = AnnDecoder {
- annDecoder :: forall s. Decoder s (ByteString -> f blk)
- encodeTelescope :: SListI xs => NP (f -.-> K Encoding) xs -> HardForkState f xs -> Encoding
- decodeTelescope :: NP (Decoder s :.: f) xs -> Decoder s (HardForkState f xs)
- encodeNS :: SListI xs => NP (f -.-> K Encoding) xs -> NS f xs -> Encoding
- decodeNS :: SListI xs => NP (Decoder s :.: f) xs -> Decoder s (NS f xs)
- decodeAnnNS :: SListI xs => NP (AnnDecoder f) xs -> forall s. Decoder s (ByteString -> NS f xs)
- encodeNestedCtxt :: All (EncodeDiskDepIx (NestedCtxt f)) xs => CodecConfig (HardForkBlock xs) -> SomeSecond (NestedCtxt f) (HardForkBlock xs) -> Encoding
- decodeNestedCtxt :: All (DecodeDiskDepIx (NestedCtxt f)) xs => CodecConfig (HardForkBlock xs) -> forall s. Decoder s (SomeSecond (NestedCtxt f) (HardForkBlock xs))
- encodeNested :: All (EncodeDiskDep (NestedCtxt f)) xs => CodecConfig (HardForkBlock xs) -> NestedCtxt f (HardForkBlock xs) a -> a -> Encoding
- decodeNested :: All (DecodeDiskDep (NestedCtxt f)) xs => CodecConfig (HardForkBlock xs) -> NestedCtxt f (HardForkBlock xs) a -> forall s. Decoder s (ByteString -> a)
- encodeEitherMismatch :: forall xs a. SListI xs => BlockNodeToClientVersion (HardForkBlock xs) -> (a -> Encoding) -> Either (MismatchEraInfo xs) a -> Encoding
- decodeEitherMismatch :: SListI xs => BlockNodeToClientVersion (HardForkBlock xs) -> Decoder s a -> Decoder s (Either (MismatchEraInfo xs) a)
- distribAnnTip :: SListI xs => AnnTip (HardForkBlock xs) -> NS AnnTip xs
- undistribAnnTip :: SListI xs => NS AnnTip xs -> AnnTip (HardForkBlock xs)
- distribSerialisedHeader :: SerialisedHeader (HardForkBlock xs) -> NS SerialisedHeader xs
- undistribSerialisedHeader :: NS SerialisedHeader xs -> SerialisedHeader (HardForkBlock xs)
- distribQueryIfCurrent :: Some (QueryIfCurrent xs) -> NS (SomeSecond Query) xs
- undistribQueryIfCurrent :: NS (SomeSecond Query) xs -> Some (QueryIfCurrent xs)
- newtype SerialiseNS f xs = SerialiseNS {
- getSerialiseNS :: NS f xs
Conditions required by the HFC to support serialisation
class (CanHardFork xs, All SerialiseConstraintsHFC xs, All (Compose Show EraNodeToNodeVersion) xs, All (Compose Eq EraNodeToNodeVersion) xs, All (Compose Show EraNodeToClientVersion) xs, All (Compose Eq EraNodeToClientVersion) xs, All (EncodeDiskDepIx (NestedCtxt Header)) xs, All (DecodeDiskDepIx (NestedCtxt Header)) xs, All HasBinaryBlockInfo xs) => SerialiseHFC xs where Source #
Conditions required by the HFC to provide serialisation
NOTE: Compatibility between HFC enabled and disabled:
- Node-to-node and node-to-client communication is versioned. When the HFC is disabled, we default to the instances for the first era, and so compatibility is preserved by construction.
- On-disk storage is not versioned, and here we make no attempt to be
compatible between non-HFC and HFC deployments, except for blocks: we
define two methods
encodeDiskHfcBlockanddecodeDiskHfcBlockwhich are used for on-disk serialisation of blocks. These methods have defaults which can and probably should be used for deployments that use the HFC from the get-go, but for deployments that only later change to use the HFC these functions can be overriden to provide an on-disk storage format for HFC blocks that is compatible with the on-disk storage of blocks from the first era. - The converse is NOT supported. Deployments that use the HFC from the start
should not use
HardForkNodeToNodeDisabledand/orHardForkNodeToClientDisabled. Doing so would result in opposite compatibility problems: the on-disk block would include the HFC tag, but sending blocks with the HFC disabled suggests that that tag is unexpected. This would then lead to problems with binary streaming, and we do not currently provide any provisions to resolve these.
Minimal complete definition
Nothing
Methods
encodeDiskHfcBlock :: CodecConfig (HardForkBlock xs) -> HardForkBlock xs -> Encoding Source #
decodeDiskHfcBlock :: CodecConfig (HardForkBlock xs) -> forall s. Decoder s (ByteString -> HardForkBlock xs) Source #
reconstructHfcPrefixLen :: proxy (Header (HardForkBlock xs)) -> PrefixLen Source #
Used as the implementation of reconstructPrefixLen for
HardForkBlock.
reconstructHfcNestedCtxt Source #
Arguments
| :: proxy (Header (HardForkBlock xs)) | |
| -> ShortByteString | First bytes ( |
| -> SizeInBytes | Block size |
| -> SomeSecond (NestedCtxt Header) (HardForkBlock xs) |
Used as the implementation of reconstructNestedCtxt for
HardForkBlock.
getHfcBinaryBlockInfo :: HardForkBlock xs -> BinaryBlockInfo Source #
Used as the implementation of getBinaryBlockInfo for
HardForkBlock.
estimateHfcBlockSize :: Header (HardForkBlock xs) -> SizeInBytes Source #
Used as the implementation of estimateBlockSize for HardForkBlock.
class (SingleEraBlock blk, SerialiseDiskConstraints blk, SerialiseNodeToNodeConstraints blk, SerialiseNodeToClientConstraints blk, HasNetworkProtocolVersion blk) => SerialiseConstraintsHFC blk Source #
data HardForkEncoderException where Source #
Exception thrown in the HFC encoders
Constructors
| HardForkEncoderFutureEra :: SingleEraInfo blk -> HardForkEncoderException | HFC disabled, but we saw a value from an era other than the first |
| HardForkEncoderDisabledEra :: SingleEraInfo blk -> HardForkEncoderException | HFC enabled, but we saw a value from a disabled era |
| HardForkEncoderQueryHfcDisabled :: HardForkEncoderException | HFC disabled, but we saw a query that is only supported by the HFC |
| HardForkEncoderQueryWrongVersion :: HardForkEncoderException | HFC enabled, but we saw a HFC query that is not supported by the HFC-specific version used |
Instances
futureEraException :: SListI xs => NS SingleEraInfo xs -> HardForkEncoderException Source #
disabledEraException :: forall blk. SingleEraBlock blk => Proxy blk -> HardForkEncoderException Source #
Distinguish first era from the rest
isFirstEra :: forall f xs. All SingleEraBlock xs => NS f xs -> Either (NS SingleEraInfo (LaterEra xs)) (f (FirstEra xs)) Source #
Arguments
| :: All SingleEraBlock xs | |
| => NS f xs |
|
| -> NS SingleEraInfo xs |
Used to construct FutureEraException
Versioning
data HardForkSpecificNodeToNodeVersion Source #
Versioning of the specific additions made by the HFC to the NodeToNode
protocols, e.g., the era tag.
Constructors
| HardForkSpecificNodeToNodeVersion1 |
Instances
data HardForkSpecificNodeToClientVersion Source #
Versioning of the specific additions made by the HFC to the NodeToClient
protocols, e.g., the era tag or the hard-fork specific queries.
Constructors
| HardForkSpecificNodeToClientVersion1 | |
| HardForkSpecificNodeToClientVersion2 | Enable the |
Instances
data HardForkNodeToNodeVersion xs where Source #
Constructors
| HardForkNodeToNodeDisabled :: BlockNodeToNodeVersion x -> HardForkNodeToNodeVersion (x ': xs) | Disable the HFC This means that only the first era ( |
| HardForkNodeToNodeEnabled :: HardForkSpecificNodeToNodeVersion -> NP EraNodeToNodeVersion xs -> HardForkNodeToNodeVersion xs | Enable the HFC Each era can be enabled or disabled individually by passing
|
Instances
| SerialiseHFC xs => Eq (HardForkNodeToNodeVersion xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common Methods (==) :: HardForkNodeToNodeVersion xs -> HardForkNodeToNodeVersion xs -> Bool # (/=) :: HardForkNodeToNodeVersion xs -> HardForkNodeToNodeVersion xs -> Bool # | |
| SerialiseHFC xs => Show (HardForkNodeToNodeVersion xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common Methods showsPrec :: Int -> HardForkNodeToNodeVersion xs -> ShowS # show :: HardForkNodeToNodeVersion xs -> String # showList :: [HardForkNodeToNodeVersion xs] -> ShowS # | |
data HardForkNodeToClientVersion xs where Source #
Constructors
| HardForkNodeToClientDisabled :: BlockNodeToClientVersion x -> HardForkNodeToClientVersion (x ': xs) | Disable the HFC |
| HardForkNodeToClientEnabled :: HardForkSpecificNodeToClientVersion -> NP EraNodeToClientVersion xs -> HardForkNodeToClientVersion xs | Enable the HFC |
Instances
| SerialiseHFC xs => Eq (HardForkNodeToClientVersion xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common Methods (==) :: HardForkNodeToClientVersion xs -> HardForkNodeToClientVersion xs -> Bool # (/=) :: HardForkNodeToClientVersion xs -> HardForkNodeToClientVersion xs -> Bool # | |
| SerialiseHFC xs => Show (HardForkNodeToClientVersion xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common Methods showsPrec :: Int -> HardForkNodeToClientVersion xs -> ShowS # show :: HardForkNodeToClientVersion xs -> String # showList :: [HardForkNodeToClientVersion xs] -> ShowS # | |
data EraNodeToNodeVersion blk Source #
Constructors
| EraNodeToNodeEnabled !(BlockNodeToNodeVersion blk) | |
| EraNodeToNodeDisabled |
Instances
| Eq (BlockNodeToNodeVersion blk) => Eq (EraNodeToNodeVersion blk) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common Methods (==) :: EraNodeToNodeVersion blk -> EraNodeToNodeVersion blk -> Bool # (/=) :: EraNodeToNodeVersion blk -> EraNodeToNodeVersion blk -> Bool # | |
| Show (BlockNodeToNodeVersion blk) => Show (EraNodeToNodeVersion blk) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common Methods showsPrec :: Int -> EraNodeToNodeVersion blk -> ShowS # show :: EraNodeToNodeVersion blk -> String # showList :: [EraNodeToNodeVersion blk] -> ShowS # | |
data EraNodeToClientVersion blk Source #
Constructors
| EraNodeToClientEnabled !(BlockNodeToClientVersion blk) | |
| EraNodeToClientDisabled |
Instances
| Eq (BlockNodeToClientVersion blk) => Eq (EraNodeToClientVersion blk) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common Methods (==) :: EraNodeToClientVersion blk -> EraNodeToClientVersion blk -> Bool # (/=) :: EraNodeToClientVersion blk -> EraNodeToClientVersion blk -> Bool # | |
| Show (BlockNodeToClientVersion blk) => Show (EraNodeToClientVersion blk) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common Methods showsPrec :: Int -> EraNodeToClientVersion blk -> ShowS # show :: EraNodeToClientVersion blk -> String # showList :: [EraNodeToClientVersion blk] -> ShowS # | |
Dealing with annotations
data AnnDecoder f blk Source #
Constructors
| AnnDecoder | |
Fields
| |
Serialisation of telescopes
encodeTelescope :: SListI xs => NP (f -.-> K Encoding) xs -> HardForkState f xs -> Encoding Source #
decodeTelescope :: NP (Decoder s :.: f) xs -> Decoder s (HardForkState f xs) Source #
Serialisation of sums
decodeAnnNS :: SListI xs => NP (AnnDecoder f) xs -> forall s. Decoder s (ByteString -> NS f xs) Source #
Dependent serialisation
encodeNestedCtxt :: All (EncodeDiskDepIx (NestedCtxt f)) xs => CodecConfig (HardForkBlock xs) -> SomeSecond (NestedCtxt f) (HardForkBlock xs) -> Encoding Source #
decodeNestedCtxt :: All (DecodeDiskDepIx (NestedCtxt f)) xs => CodecConfig (HardForkBlock xs) -> forall s. Decoder s (SomeSecond (NestedCtxt f) (HardForkBlock xs)) Source #
encodeNested :: All (EncodeDiskDep (NestedCtxt f)) xs => CodecConfig (HardForkBlock xs) -> NestedCtxt f (HardForkBlock xs) a -> a -> Encoding Source #
decodeNested :: All (DecodeDiskDep (NestedCtxt f)) xs => CodecConfig (HardForkBlock xs) -> NestedCtxt f (HardForkBlock xs) a -> forall s. Decoder s (ByteString -> a) Source #
MismatchEraInfo
encodeEitherMismatch :: forall xs a. SListI xs => BlockNodeToClientVersion (HardForkBlock xs) -> (a -> Encoding) -> Either (MismatchEraInfo xs) a -> Encoding Source #
decodeEitherMismatch :: SListI xs => BlockNodeToClientVersion (HardForkBlock xs) -> Decoder s a -> Decoder s (Either (MismatchEraInfo xs) a) Source #
Distributive properties
distribAnnTip :: SListI xs => AnnTip (HardForkBlock xs) -> NS AnnTip xs Source #
undistribAnnTip :: SListI xs => NS AnnTip xs -> AnnTip (HardForkBlock xs) Source #
distribSerialisedHeader :: SerialisedHeader (HardForkBlock xs) -> NS SerialisedHeader xs Source #
undistribSerialisedHeader :: NS SerialisedHeader xs -> SerialisedHeader (HardForkBlock xs) Source #
distribQueryIfCurrent :: Some (QueryIfCurrent xs) -> NS (SomeSecond Query) xs Source #
undistribQueryIfCurrent :: NS (SomeSecond Query) xs -> Some (QueryIfCurrent xs) Source #
Deriving-via support for tests
newtype SerialiseNS f xs Source #
Used for deriving via
Example
deriving via SerialiseNS Header SomeEras
instance Serialise (Header SomeSecond)Constructors
| SerialiseNS | |
Fields
| |
Instances
| All (Compose Serialise f) xs => Serialise (SerialiseNS f xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common Methods encode :: SerialiseNS f xs -> Encoding Source # decode :: Decoder s (SerialiseNS f xs) Source # encodeList :: [SerialiseNS f xs] -> Encoding Source # decodeList :: Decoder s [SerialiseNS f xs] Source # | |
Orphan instances
| SerialiseHFC xs => HasNetworkProtocolVersion (HardForkBlock xs) Source # | |
Associated Types type BlockNodeToNodeVersion (HardForkBlock xs) Source # type BlockNodeToClientVersion (HardForkBlock xs) Source # | |