Safe Haskell | None |
---|---|
Language | Haskell2010 |
Abstract view over blocks
The network layer does not make any concrete assumptions about what blocks look like.
Synopsis
- newtype SlotNo = SlotNo { }
- newtype BlockNo = BlockNo { }
- type family HeaderHash b :: Type
- data HeaderFields b = HeaderFields { }
- castHeaderFields :: HeaderHash b ~ HeaderHash b' => HeaderFields b -> HeaderFields b'
-
class
(
StandardHash
b,
Typeable
b) =>
HasHeader
b
where
- getHeaderFields :: b -> HeaderFields b
- blockNo :: HasHeader b => b -> BlockNo
- blockSlot :: HasHeader b => b -> SlotNo
- blockHash :: HasHeader b => b -> HeaderHash b
-
class
HasHeader
b =>
HasFullHeader
b
where
- blockPrevHash :: b -> ChainHash b
- blockInvariant :: b -> Bool
- class ( Eq ( HeaderHash b), Ord ( HeaderHash b), Show ( HeaderHash b), Typeable ( HeaderHash b), NoThunks ( HeaderHash b)) => StandardHash b
-
data
ChainHash
b
- = GenesisHash
- | BlockHash !( HeaderHash b)
- castHash :: Coercible ( HeaderHash b) ( HeaderHash b') => ChainHash b -> ChainHash b'
-
newtype
Point
block =
Point
{
- getPoint :: WithOrigin ( Block SlotNo ( HeaderHash block))
- pointSlot :: Point block -> WithOrigin SlotNo
- pointHash :: Point block -> ChainHash block
- castPoint :: Coercible ( HeaderHash b) ( HeaderHash b') => Point b -> Point b'
- blockPoint :: HasHeader block => block -> Point block
- pattern GenesisPoint :: Point block
- pattern BlockPoint :: SlotNo -> HeaderHash block -> Point block
- atSlot :: Point block -> SlotNo
- withHash :: Point block -> HeaderHash block
-
data
Tip
b
- = TipGenesis
- | Tip ! SlotNo !( HeaderHash b) ! BlockNo
- castTip :: HeaderHash a ~ HeaderHash b => Tip a -> Tip b
- getTipPoint :: Tip b -> Point b
- getTipBlockNo :: Tip b -> WithOrigin BlockNo
- getTipSlotNo :: Tip b -> WithOrigin SlotNo
- getLegacyTipBlockNo :: Tip b -> BlockNo
- tipFromHeader :: HasHeader a => a -> Tip a
- legacyTip :: Point b -> BlockNo -> Tip b
- toLegacyTip :: Tip b -> ( Point b, BlockNo )
- encodeTip :: ( HeaderHash blk -> Encoding ) -> Tip blk -> Encoding
- encodedTipSize :: ( Proxy ( HeaderHash blk) -> Size ) -> Proxy ( Tip blk) -> Size
- decodeTip :: forall blk. ( forall s. Decoder s ( HeaderHash blk)) -> forall s. Decoder s ( Tip blk)
- data ChainUpdate block a
-
data
MaxSlotNo
- = NoMaxSlotNo
- | MaxSlotNo ! SlotNo
- maxSlotNoFromMaybe :: Maybe SlotNo -> MaxSlotNo
- maxSlotNoToMaybe :: MaxSlotNo -> Maybe SlotNo
- maxSlotNoFromWithOrigin :: WithOrigin SlotNo -> MaxSlotNo
- genesisPoint :: Point block
- encodePoint :: ( HeaderHash block -> Encoding ) -> Point block -> Encoding
- encodedPointSize :: ( Proxy ( HeaderHash block) -> Size ) -> Proxy ( Point block) -> Size
- encodeChainHash :: ( HeaderHash block -> Encoding ) -> ChainHash block -> Encoding
- decodePoint :: ( forall s. Decoder s ( HeaderHash block)) -> forall s. Decoder s ( Point block)
- decodeChainHash :: ( forall s. Decoder s ( HeaderHash block)) -> forall s. Decoder s ( ChainHash block)
- newtype Serialised a = Serialised { }
- wrapCBORinCBOR :: (a -> Encoding ) -> a -> Encoding
- unwrapCBORinCBOR :: ( forall s. Decoder s ( ByteString -> a)) -> forall s. Decoder s a
- mkSerialised :: (a -> Encoding ) -> a -> Serialised a
- fromSerialised :: ( forall s. Decoder s ( ByteString -> a)) -> Serialised a -> forall s. Decoder s a
Documentation
The 0-based index for the Ourboros time slot.
Instances
Bounded SlotNo | |
Enum SlotNo | |
Defined in Cardano.Slotting.Slot succ :: SlotNo -> SlotNo Source # pred :: SlotNo -> SlotNo Source # toEnum :: Int -> SlotNo Source # fromEnum :: SlotNo -> Int Source # enumFrom :: SlotNo -> [ SlotNo ] Source # enumFromThen :: SlotNo -> SlotNo -> [ SlotNo ] Source # enumFromTo :: SlotNo -> SlotNo -> [ SlotNo ] Source # enumFromThenTo :: SlotNo -> SlotNo -> SlotNo -> [ SlotNo ] Source # |
|
Eq SlotNo | |
Num SlotNo | |
Defined in Cardano.Slotting.Slot |
|
Ord SlotNo | |
Show SlotNo | |
Generic SlotNo | |
Hashable SlotNo Source # | |
ToJSON SlotNo | |
FromJSON SlotNo | |
ToCBOR SlotNo | |
FromCBOR SlotNo | |
NFData SlotNo | |
Defined in Cardano.Slotting.Slot |
|
NoThunks SlotNo | |
Serialise SlotNo | |
HasHeader block => Anchorable ( WithOrigin SlotNo ) ( Anchor block) block Source # | |
Defined in Ouroboros.Network.AnchoredFragment |
|
type Rep SlotNo | |
Defined in Cardano.Slotting.Slot |
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.
Instances
Bounded BlockNo | |
Enum BlockNo | |
Defined in Cardano.Slotting.Block succ :: BlockNo -> BlockNo Source # pred :: BlockNo -> BlockNo Source # toEnum :: Int -> BlockNo Source # fromEnum :: BlockNo -> Int Source # enumFrom :: BlockNo -> [ BlockNo ] Source # enumFromThen :: BlockNo -> BlockNo -> [ BlockNo ] Source # enumFromTo :: BlockNo -> BlockNo -> [ BlockNo ] Source # enumFromThenTo :: BlockNo -> BlockNo -> BlockNo -> [ BlockNo ] Source # |
|
Eq BlockNo | |
Num BlockNo | |
Defined in Cardano.Slotting.Block |
|
Ord BlockNo | |
Defined in Cardano.Slotting.Block |
|
Show BlockNo | |
Generic BlockNo | |
Hashable BlockNo Source # | |
ToCBOR BlockNo | |
FromCBOR BlockNo | |
NFData BlockNo | |
Defined in Cardano.Slotting.Block |
|
NoThunks BlockNo | |
Serialise BlockNo | |
type Rep BlockNo | |
Defined in Cardano.Slotting.Block |
type family HeaderHash b :: Type Source #
Header hash
Instances
type HeaderHash BlockHeader Source # | |
Defined in Ouroboros.Network.Testing.ConcreteBlock |
|
type HeaderHash Block Source # | |
Defined in Ouroboros.Network.Testing.ConcreteBlock |
|
type HeaderHash ( Serialised block) Source # | |
Defined in Ouroboros.Network.Block |
|
type HeaderHash ( HeaderFields b) Source # | |
Defined in Ouroboros.Network.Block |
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.
Instances
castHeaderFields :: HeaderHash b ~ HeaderHash b' => HeaderFields b -> HeaderFields b' Source #
class ( StandardHash b, Typeable b) => HasHeader b where Source #
Abstract over the shape of blocks (or indeed just block headers)
getHeaderFields :: b -> HeaderFields b Source #
Instances
HasHeader BlockHeader Source # | |
HasHeader Block Source # | |
Defined in Ouroboros.Network.Testing.ConcreteBlock getHeaderFields :: Block -> HeaderFields Block Source # |
|
( StandardHash b, Typeable b) => HasHeader ( HeaderFields b) Source # | |
Defined in Ouroboros.Network.Block getHeaderFields :: HeaderFields b -> HeaderFields ( HeaderFields b) Source # |
blockHash :: HasHeader b => b -> HeaderHash b Source #
class HasHeader b => HasFullHeader b where Source #
Extension of
HasHeader
with some additional information
Used in tests and assertions only.
blockPrevHash :: b -> ChainHash b Source #
blockInvariant :: b -> Bool Source #
Instances
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
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.
Instances
StandardHash BlockHeader Source # | |
Defined in Ouroboros.Network.Testing.ConcreteBlock |
|
StandardHash Block Source # | |
Defined in Ouroboros.Network.Testing.ConcreteBlock |
|
StandardHash block => StandardHash ( Serialised block) Source # | |
Defined in Ouroboros.Network.Block |
|
StandardHash b => StandardHash ( HeaderFields b) Source # | |
Defined in Ouroboros.Network.Block |
GenesisHash | |
BlockHash !( HeaderHash b) |
Instances
StandardHash block => Eq ( ChainHash block) Source # | |
StandardHash block => Ord ( ChainHash block) Source # | |
Defined in Ouroboros.Network.Block compare :: ChainHash block -> ChainHash block -> Ordering Source # (<) :: ChainHash block -> ChainHash block -> Bool Source # (<=) :: ChainHash block -> ChainHash block -> Bool Source # (>) :: ChainHash block -> ChainHash block -> Bool Source # (>=) :: ChainHash block -> ChainHash block -> Bool Source # max :: ChainHash block -> ChainHash block -> ChainHash block Source # min :: ChainHash block -> ChainHash block -> ChainHash block Source # |
|
StandardHash block => Show ( ChainHash block) Source # | |
Generic ( ChainHash b) Source # | |
Hashable ( HeaderHash b) => Hashable ( ChainHash b) Source # |
We don't insist that
This requires
|
( StandardHash block, Typeable block) => NoThunks ( ChainHash block) Source # | |
Serialise ( HeaderHash b) => Serialise ( ChainHash b) Source # | |
type Rep ( ChainHash b) Source # | |
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))))
|
castHash :: Coercible ( HeaderHash b) ( HeaderHash b') => ChainHash b -> ChainHash b' 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.
Point | |
|
Instances
castPoint :: Coercible ( HeaderHash b) ( HeaderHash b') => Point b -> Point b' Source #
blockPoint :: HasHeader block => block -> Point block Source #
pattern GenesisPoint :: Point block Source #
pattern BlockPoint :: SlotNo -> HeaderHash block -> Point block Source #
withHash :: Point block -> HeaderHash block Source #
Used in chain-sync protocol to advertise the tip of the server's chain.
TipGenesis |
The tip is genesis |
Tip ! SlotNo !( HeaderHash b) ! BlockNo |
The tip is not genesis |
Instances
StandardHash b => Eq ( Tip b) Source # | |
StandardHash b => Show ( Tip b) Source # | |
Generic ( Tip b) Source # | |
StandardHash b => NoThunks ( Tip b) Source # | |
ShowProxy b => ShowProxy ( Tip b :: Type ) Source # | |
type Rep ( Tip b) Source # | |
Defined in Ouroboros.Network.Block
type
Rep
(
Tip
b) =
D1
('
MetaData
"Tip" "Ouroboros.Network.Block" "ouroboros-network-0.1.0.1-2UgqzRSdBh49QYumtriFSI" '
False
) (
C1
('
MetaCons
"TipGenesis" '
PrefixI
'
False
) (
U1
::
Type
->
Type
)
:+:
C1
('
MetaCons
"Tip" '
PrefixI
'
False
) (
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
SourceStrict
'
DecidedStrict
) (
Rec0
SlotNo
)
:*:
(
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
SourceStrict
'
DecidedStrict
) (
Rec0
(
HeaderHash
b))
:*:
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
SourceStrict
'
DecidedStrict
) (
Rec0
BlockNo
))))
|
castTip :: HeaderHash a ~ HeaderHash b => Tip a -> Tip b Source #
getTipPoint :: Tip b -> Point b Source #
getTipBlockNo :: Tip b -> WithOrigin BlockNo Source #
getTipSlotNo :: Tip b -> WithOrigin SlotNo Source #
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.
tipFromHeader :: HasHeader a => a -> Tip a Source #
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)
encodedTipSize :: ( Proxy ( HeaderHash blk) -> Size ) -> Proxy ( Tip blk) -> Size Source #
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.
Instances
The highest slot number seen.
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
Eq MaxSlotNo Source # | |
Ord MaxSlotNo Source # | |
Defined in Ouroboros.Network.Block |
|
Show MaxSlotNo Source # | |
Generic MaxSlotNo Source # | |
Semigroup MaxSlotNo Source # | |
Monoid MaxSlotNo Source # | |
NoThunks MaxSlotNo Source # | |
type Rep MaxSlotNo Source # | |
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
)))
|
genesisPoint :: Point block Source #
Serialisation
encodePoint :: ( HeaderHash block -> Encoding ) -> Point block -> Encoding Source #
encodedPointSize :: ( Proxy ( HeaderHash block) -> Size ) -> Proxy ( Point block) -> Size Source #
encodeChainHash :: ( HeaderHash block -> Encoding ) -> ChainHash block -> Encoding Source #
decodePoint :: ( forall s. Decoder s ( HeaderHash block)) -> forall s. Decoder s ( Point block) Source #
decodeChainHash :: ( forall s. Decoder s ( HeaderHash block)) -> forall s. Decoder s ( ChainHash 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
Eq ( Serialised a) Source # | |
Defined in Ouroboros.Network.Block (==) :: Serialised a -> Serialised a -> Bool Source # (/=) :: Serialised a -> Serialised a -> Bool Source # |
|
Show ( Serialised a) Source # | |
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. |
Defined in Ouroboros.Network.Block encode :: Serialised a -> Encoding Source # decode :: Decoder s ( Serialised a) Source # encodeList :: [ Serialised a] -> Encoding Source # decodeList :: Decoder s [ Serialised a] Source # |
|
StandardHash block => StandardHash ( Serialised block) Source # | |
Defined in Ouroboros.Network.Block |
|
ShowProxy a => ShowProxy ( Serialised a :: Type ) Source # | |
Defined in Ouroboros.Network.Block |
|
type HeaderHash ( Serialised block) Source # | |
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.