ouroboros-network-0.1.0.1: A networking layer for the Ouroboros blockchain protocol
Safe Haskell None
Language Haskell2010

Ouroboros.Network.Block

Description

Abstract view over blocks

The network layer does not make any concrete assumptions about what blocks look like.

Synopsis

Documentation

newtype SlotNo Source #

The 0-based index for the Ourboros time slot.

Constructors

SlotNo

Instances

Instances details
Bounded SlotNo
Instance details

Defined in Cardano.Slotting.Slot

Enum SlotNo
Instance details

Defined in Cardano.Slotting.Slot

Eq SlotNo
Instance details

Defined in Cardano.Slotting.Slot

Num SlotNo
Instance details

Defined in Cardano.Slotting.Slot

Ord SlotNo
Instance details

Defined in Cardano.Slotting.Slot

Show SlotNo
Instance details

Defined in Cardano.Slotting.Slot

Generic SlotNo
Instance details

Defined in Cardano.Slotting.Slot

Hashable SlotNo Source #
Instance details

Defined in Ouroboros.Network.Testing.ConcreteBlock

ToJSON SlotNo
Instance details

Defined in Cardano.Slotting.Slot

FromJSON SlotNo
Instance details

Defined in Cardano.Slotting.Slot

ToCBOR SlotNo
Instance details

Defined in Cardano.Slotting.Slot

FromCBOR SlotNo
Instance details

Defined in Cardano.Slotting.Slot

NFData SlotNo
Instance details

Defined in Cardano.Slotting.Slot

NoThunks SlotNo
Instance details

Defined in Cardano.Slotting.Slot

Serialise SlotNo
Instance details

Defined in Cardano.Slotting.Slot

HasHeader block => Anchorable ( WithOrigin SlotNo ) ( Anchor block) block Source #
Instance details

Defined in Ouroboros.Network.AnchoredFragment

type Rep SlotNo
Instance details

Defined in Cardano.Slotting.Slot

type Rep SlotNo = D1 (' MetaData "SlotNo" "Cardano.Slotting.Slot" "cardano-slotting-0.1.0.2-j5NuF73p5IFfcfvmth6tS" ' True ) ( C1 (' MetaCons "SlotNo" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "unSlotNo") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Word64 )))

newtype BlockNo Source #

The 0-based index of the block in the blockchain. BlockNo is <= SlotNo and is only equal at slot N if there is a block for every slot where N <= SlotNo.

Constructors

BlockNo

Instances

Instances details
Bounded BlockNo
Instance details

Defined in Cardano.Slotting.Block

Enum BlockNo
Instance details

Defined in Cardano.Slotting.Block

Eq BlockNo
Instance details

Defined in Cardano.Slotting.Block

Num BlockNo
Instance details

Defined in Cardano.Slotting.Block

Ord BlockNo
Instance details

Defined in Cardano.Slotting.Block

Show BlockNo
Instance details

Defined in Cardano.Slotting.Block

Generic BlockNo
Instance details

Defined in Cardano.Slotting.Block

Hashable BlockNo Source #
Instance details

Defined in Ouroboros.Network.Testing.ConcreteBlock

ToCBOR BlockNo
Instance details

Defined in Cardano.Slotting.Block

FromCBOR BlockNo
Instance details

Defined in Cardano.Slotting.Block

NFData BlockNo
Instance details

Defined in Cardano.Slotting.Block

NoThunks BlockNo
Instance details

Defined in Cardano.Slotting.Block

Serialise BlockNo
Instance details

Defined in Cardano.Slotting.Block

type Rep BlockNo
Instance details

Defined in Cardano.Slotting.Block

type Rep BlockNo = D1 (' MetaData "BlockNo" "Cardano.Slotting.Block" "cardano-slotting-0.1.0.2-j5NuF73p5IFfcfvmth6tS" ' True ) ( C1 (' MetaCons "BlockNo" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "unBlockNo") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Word64 )))

data HeaderFields b Source #

Header fields we expect to be present in a block

These fields are lazy because they are extracted from a block or block header; this type is not intended for storage.

Constructors

HeaderFields

Fields

Instances

Instances details
StandardHash b => Eq ( HeaderFields b) Source #
Instance details

Defined in Ouroboros.Network.Block

StandardHash b => Ord ( HeaderFields b) Source #
Instance details

Defined in Ouroboros.Network.Block

StandardHash b => Show ( HeaderFields b) Source #
Instance details

Defined in Ouroboros.Network.Block

Generic ( HeaderFields b) Source #
Instance details

Defined in Ouroboros.Network.Block

Associated Types

type Rep ( HeaderFields b) :: Type -> Type Source #

Serialise ( HeaderHash b) => Serialise ( HeaderFields b) Source #
Instance details

Defined in Ouroboros.Network.Block

StandardHash b => StandardHash ( HeaderFields b) Source #
Instance details

Defined in Ouroboros.Network.Block

( StandardHash b, Typeable b) => HasHeader ( HeaderFields b) Source #
Instance details

Defined in Ouroboros.Network.Block

type Rep ( HeaderFields b) Source #
Instance details

Defined in Ouroboros.Network.Block

type HeaderHash ( HeaderFields b) Source #
Instance details

Defined in Ouroboros.Network.Block

class ( Eq ( HeaderHash b), Ord ( HeaderHash b), Show ( HeaderHash b), Typeable ( HeaderHash b), NoThunks ( HeaderHash b)) => StandardHash b Source #

StandardHash summarises the constraints we want header hashes to have

Without this class we would need to write

deriving instance Eq (HeaderHash block) => Eq (ChainHash block)`

That requires UndecidableInstances ; not a problem by itself, but it also means that we can then not use deriving Eq anywhere else for datatypes that reference Hash , which is very frustrating; see

https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#inferred-context-for-deriving-clauses

Introducing the StandardHash class avoids this problem.

Having these constraints directly as part of the HasHeader class is possible but libraries that use the networking layer may wish to be able to talk about StandardHash independently of HasHeader since the latter may impose yet further constraints.

data ChainHash b Source #

Instances

Instances details
StandardHash block => Eq ( ChainHash block) Source #
Instance details

Defined in Ouroboros.Network.Block

StandardHash block => Ord ( ChainHash block) Source #
Instance details

Defined in Ouroboros.Network.Block

StandardHash block => Show ( ChainHash block) Source #
Instance details

Defined in Ouroboros.Network.Block

Generic ( ChainHash b) Source #
Instance details

Defined in Ouroboros.Network.Block

Associated Types

type Rep ( ChainHash b) :: Type -> Type Source #

Hashable ( HeaderHash b) => Hashable ( ChainHash b) Source #

Hashable instance for Hash

We don't insist that Hashable in StandardHash because Hashable is only used in the network layer tests .

This requires UndecidableInstances because Hashable (HeaderHash b) is no smaller than Hashable (ChainHash b) .

Instance details

Defined in Ouroboros.Network.Testing.ConcreteBlock

( StandardHash block, Typeable block) => NoThunks ( ChainHash block) Source #
Instance details

Defined in Ouroboros.Network.Block

Serialise ( HeaderHash b) => Serialise ( ChainHash b) Source #
Instance details

Defined in Ouroboros.Network.Block

type Rep ( ChainHash b) Source #
Instance details

Defined in Ouroboros.Network.Block

type Rep ( ChainHash b) = D1 (' MetaData "ChainHash" "Ouroboros.Network.Block" "ouroboros-network-0.1.0.1-2UgqzRSdBh49QYumtriFSI" ' False ) ( C1 (' MetaCons "GenesisHash" ' PrefixI ' False ) ( U1 :: Type -> Type ) :+: C1 (' MetaCons "BlockHash" ' PrefixI ' False ) ( S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 ( HeaderHash b))))

newtype Point block Source #

A point on the chain is identified by its Slot and HeaderHash .

The Slot tells us where to look and the HeaderHash either simply serves as a check, or in some contexts it disambiguates blocks from different forks that were in the same slot.

It's a newtype rather than a type synonym, because using a type synonym would lead to ambiguity, since HeaderHash is a non-injective type family.

Instances

Instances details
StandardHash block => Eq ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

StandardHash block => Ord ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

StandardHash block => Show ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

Generic ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

Associated Types

type Rep ( Point block) :: Type -> Type Source #

StandardHash block => NoThunks ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

Serialise ( HeaderHash block) => Serialise ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

ShowProxy block => ShowProxy ( Point block :: Type ) Source #
Instance details

Defined in Ouroboros.Network.Block

type Rep ( Point block) Source #
Instance details

Defined in Ouroboros.Network.Block

type Rep ( Point block) = D1 (' MetaData "Point" "Ouroboros.Network.Block" "ouroboros-network-0.1.0.1-2UgqzRSdBh49QYumtriFSI" ' True ) ( C1 (' MetaCons "Point" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getPoint") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( WithOrigin ( Block SlotNo ( HeaderHash block))))))

data Tip b Source #

Used in chain-sync protocol to advertise the tip of the server's chain.

Constructors

TipGenesis

The tip is genesis

Tip ! SlotNo !( HeaderHash b) ! BlockNo

The tip is not genesis

Instances

Instances details
StandardHash b => Eq ( Tip b) Source #
Instance details

Defined in Ouroboros.Network.Block

StandardHash b => Show ( Tip b) Source #
Instance details

Defined in Ouroboros.Network.Block

Generic ( Tip b) Source #
Instance details

Defined in Ouroboros.Network.Block

Associated Types

type Rep ( Tip b) :: Type -> Type Source #

StandardHash b => NoThunks ( Tip b) Source #
Instance details

Defined in Ouroboros.Network.Block

ShowProxy b => ShowProxy ( Tip b :: Type ) Source #
Instance details

Defined in Ouroboros.Network.Block

type Rep ( Tip b) Source #
Instance details

Defined in Ouroboros.Network.Block

getLegacyTipBlockNo :: Tip b -> BlockNo Source #

Deprecated: Use getTipBlockNo

Get the block number associated with a Tip , or genesisBlockNo otherwise

TODO: This is wrong . There is no block number if we are at genesis ( genesisBlockNo is the block number of the first block on the chain). Usage of this function should be phased out.

legacyTip :: Point b -> BlockNo -> Tip b Source #

Deprecated: Use tipFromHeader instead

Inverse of toLegacyTip

TODO: This should be phased out, since it makes no sense to have a BlockNo for the genesis point.

toLegacyTip :: Tip b -> ( Point b, BlockNo ) Source #

Deprecated: Use getTipPoint and getTipBlockNo

Translate to the format it was before (to maintain binary compatibility)

decodeTip :: forall blk. ( forall s. Decoder s ( HeaderHash blk)) -> forall s. Decoder s ( Tip blk) Source #

data ChainUpdate block a Source #

A representation of two actions to update a chain: add a block or roll back to a previous point.

The type parameter a is there to allow a Functor instance. Typically, it will be instantiated with block itself.

Constructors

AddBlock a
RollBack ( Point block)

Instances

Instances details
Functor ( ChainUpdate block) Source #
Instance details

Defined in Ouroboros.Network.Block

Methods

fmap :: (a -> b) -> ChainUpdate block a -> ChainUpdate block b Source #

(<$) :: a -> ChainUpdate block b -> ChainUpdate block a Source #

Foldable ( ChainUpdate block) Source #
Instance details

Defined in Ouroboros.Network.Block

Traversable ( ChainUpdate block) Source #
Instance details

Defined in Ouroboros.Network.Block

( StandardHash block, Eq a) => Eq ( ChainUpdate block a) Source #
Instance details

Defined in Ouroboros.Network.Block

( StandardHash block, Show a) => Show ( ChainUpdate block a) Source #
Instance details

Defined in Ouroboros.Network.Block

data MaxSlotNo Source #

The highest slot number seen.

Constructors

NoMaxSlotNo

No block/header has been seen yet, so we don't have a highest slot number.

MaxSlotNo ! SlotNo

The highest slot number seen.

Instances

Instances details
Eq MaxSlotNo Source #
Instance details

Defined in Ouroboros.Network.Block

Ord MaxSlotNo Source #
Instance details

Defined in Ouroboros.Network.Block

Show MaxSlotNo Source #
Instance details

Defined in Ouroboros.Network.Block

Generic MaxSlotNo Source #
Instance details

Defined in Ouroboros.Network.Block

Semigroup MaxSlotNo Source #
Instance details

Defined in Ouroboros.Network.Block

Monoid MaxSlotNo Source #
Instance details

Defined in Ouroboros.Network.Block

NoThunks MaxSlotNo Source #
Instance details

Defined in Ouroboros.Network.Block

type Rep MaxSlotNo Source #
Instance details

Defined in Ouroboros.Network.Block

type Rep MaxSlotNo = D1 (' MetaData "MaxSlotNo" "Ouroboros.Network.Block" "ouroboros-network-0.1.0.1-2UgqzRSdBh49QYumtriFSI" ' False ) ( C1 (' MetaCons "NoMaxSlotNo" ' PrefixI ' False ) ( U1 :: Type -> Type ) :+: C1 (' MetaCons "MaxSlotNo" ' PrefixI ' False ) ( S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 SlotNo )))

Serialisation

decodePoint :: ( forall s. Decoder s ( HeaderHash block)) -> forall s. Decoder s ( Point block) Source #

Serialised block/header

newtype Serialised a Source #

An already serialised value

When streaming blocks/header from disk to the network, there is often no need to deserialise them, as we'll just end up serialising them again when putting them on the wire.

Instances

Instances details
Eq ( Serialised a) Source #
Instance details

Defined in Ouroboros.Network.Block

Show ( Serialised a) Source #
Instance details

Defined in Ouroboros.Network.Block

Serialise ( Serialised a) Source #

CBOR-in-CBOR

TODO: replace with encodeEmbeddedCBOR from cborg-0.2.4 once it is available, since that will be faster.

TODO: Avoid converting to a strict ByteString, as that requires copying O(n) in case the lazy ByteString consists of more than one chunks.

Instance details

Defined in Ouroboros.Network.Block

StandardHash block => StandardHash ( Serialised block) Source #
Instance details

Defined in Ouroboros.Network.Block

ShowProxy a => ShowProxy ( Serialised a :: Type ) Source #
Instance details

Defined in Ouroboros.Network.Block

type HeaderHash ( Serialised block) Source #
Instance details

Defined in Ouroboros.Network.Block

wrapCBORinCBOR :: (a -> Encoding ) -> a -> Encoding Source #

Wrap CBOR-in-CBOR

This is primarily useful for the decoder ; see unwrapCBORinCBOR

unwrapCBORinCBOR :: ( forall s. Decoder s ( ByteString -> a)) -> forall s. Decoder s a Source #

Unwrap CBOR-in-CBOR

The CBOR-in-CBOR encoding gives us the ByteString we need in order to to construct annotations.

mkSerialised :: (a -> Encoding ) -> a -> Serialised a Source #

Construct Serialised value from an unserialised value

fromSerialised :: ( forall s. Decoder s ( ByteString -> a)) -> Serialised a -> forall s. Decoder s a Source #

Decode a Serialised value

Unlike a regular Decoder , which has an implicit input stream, fromSerialised takes the Serialised value as an argument.