Safe Haskell | Safe-Inferred |
---|---|
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 ∷ k) ∷ Type
- data HeaderFields (b ∷ k) = 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 ∷ k)
- 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 ∷ ∀ {k} (block ∷ k). Point block → SlotNo
- withHash ∷ ∀ {k} (block ∷ k). 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
- decodeTip ∷ ∀ blk. (∀ s. Decoder s (HeaderHash blk)) → ∀ s. Decoder s (Tip blk)
- data ChainUpdate block a
- data MaxSlotNo
- maxSlotNoFromMaybe ∷ Maybe SlotNo → MaxSlotNo
- maxSlotNoToMaybe ∷ MaxSlotNo → Maybe SlotNo
- maxSlotNoFromWithOrigin ∷ WithOrigin SlotNo → MaxSlotNo
- genesisPoint ∷ Point block
- encodePoint ∷ (HeaderHash block → Encoding) → Point block → Encoding
- encodeChainHash ∷ (HeaderHash block → Encoding) → ChainHash block → Encoding
- decodePoint ∷ (∀ s. Decoder s (HeaderHash block)) → ∀ s. Decoder s (Point block)
- decodeChainHash ∷ (∀ s. Decoder s (HeaderHash block)) → ∀ s. Decoder s (ChainHash block)
- newtype Serialised a = Serialised {}
- wrapCBORinCBOR ∷ (a → Encoding) → a → Encoding
- unwrapCBORinCBOR ∷ (∀ s. Decoder s (ByteString → a)) → ∀ s. Decoder s a
- mkSerialised ∷ (a → Encoding) → a → Serialised a
- fromSerialised ∷ (∀ s. Decoder s (ByteString → a)) → Serialised a → ∀ s. Decoder s a
Documentation
The 0-based index for the Ourboros time slot.
Instances
FromJSON SlotNo | |
ToJSON SlotNo | |
Bounded SlotNo | |
Enum SlotNo | |
Generic SlotNo | |
Num SlotNo | |
Show SlotNo | |
FromCBOR SlotNo | |
ToCBOR SlotNo | |
NFData SlotNo | |
Defined in Cardano.Slotting.Slot | |
Eq SlotNo | |
Ord SlotNo | |
NoThunks SlotNo | |
Serialise SlotNo | |
ShowProxy SlotNo Source # | |
HasHeader block ⇒ Anchorable (WithOrigin SlotNo) (Anchor block) block Source # | |
Defined in Ouroboros.Network.AnchoredFragment | |
type Rep SlotNo | |
Defined in Cardano.Slotting.Slot type Rep SlotNo = D1 ('MetaData "SlotNo" "Cardano.Slotting.Slot" "cardano-slotting-0.2.0.0-b80c39407d1aae29adb9ad4f2d33d3fc06cf7bab5162a7ec4f22b16819d616e6" 'True) (C1 ('MetaCons "SlotNo" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSlotNo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64))) |
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
FromJSON BlockNo | |
ToJSON BlockNo | |
Bounded BlockNo | |
Enum BlockNo | |
Defined in Cardano.Slotting.Block | |
Generic BlockNo | |
Num BlockNo | |
Show BlockNo | |
FromCBOR BlockNo | |
ToCBOR BlockNo | |
NFData BlockNo | |
Defined in Cardano.Slotting.Block | |
Eq BlockNo | |
Ord BlockNo | |
NoThunks BlockNo | |
Serialise BlockNo | |
type Rep BlockNo | |
Defined in Cardano.Slotting.Block type Rep BlockNo = D1 ('MetaData "BlockNo" "Cardano.Slotting.Block" "cardano-slotting-0.2.0.0-b80c39407d1aae29adb9ad4f2d33d3fc06cf7bab5162a7ec4f22b16819d616e6" 'True) (C1 ('MetaCons "BlockNo" 'PrefixI 'True) (S1 ('MetaSel ('Just "unBlockNo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64))) |
type family HeaderHash (b ∷ k) ∷ Type Source #
Header hash
Instances
type HeaderHash (HeaderFields b ∷ Type) Source # | |
Defined in Ouroboros.Network.Block | |
type HeaderHash (Serialised block ∷ Type) Source # | |
Defined in Ouroboros.Network.Block |
data HeaderFields (b ∷ k) 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
(StandardHash b, Typeable b, Typeable k) ⇒ 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 #
class (Eq (HeaderHash b), Ord (HeaderHash b), Show (HeaderHash b), Typeable (HeaderHash b), NoThunks (HeaderHash b)) ⇒ StandardHash (b ∷ k) 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/exts/deriving_inferred.html
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 b ⇒ StandardHash (HeaderFields b ∷ Type) Source # | |
Defined in Ouroboros.Network.Block | |
StandardHash block ⇒ StandardHash (Serialised block ∷ Type) Source # | |
Defined in Ouroboros.Network.Block |
Instances
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
ShowProxy block ⇒ ShowProxy (Point block ∷ Type) Source # | |
Generic (Point block) Source # | |
StandardHash block ⇒ Show (Point block) Source # | |
StandardHash block ⇒ Eq (Point block) Source # | |
StandardHash block ⇒ Ord (Point block) Source # | |
StandardHash block ⇒ NoThunks (Point block) Source # | |
Serialise (HeaderHash block) ⇒ Serialise (Point block) Source # | |
type Rep (Point block) Source # | |
Defined in Ouroboros.Network.Block type Rep (Point block) = D1 ('MetaData "Point" "Ouroboros.Network.Block" "ouroboros-network-api-0.7.2.0-inplace" 'True) (C1 ('MetaCons "Point" 'PrefixI 'True) (S1 ('MetaSel ('Just "getPoint") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (WithOrigin (Block SlotNo (HeaderHash block)))))) |
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 ∷ ∀ {k} (block ∷ k). 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
ShowProxy b ⇒ ShowProxy (Tip b ∷ Type) Source # | |
Generic (Tip b) Source # | |
StandardHash b ⇒ Show (Tip b) Source # | |
StandardHash b ⇒ Eq (Tip b) Source # | |
StandardHash b ⇒ NoThunks (Tip b) Source # | |
type Rep (Tip b) Source # | |
Defined in Ouroboros.Network.Block type Rep (Tip b) = D1 ('MetaData "Tip" "Ouroboros.Network.Block" "ouroboros-network-api-0.7.2.0-inplace" '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)
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
Monoid MaxSlotNo Source # | |
Semigroup MaxSlotNo Source # | |
Generic MaxSlotNo Source # | |
Show MaxSlotNo Source # | |
Eq MaxSlotNo Source # | |
Ord MaxSlotNo Source # | |
Defined in Ouroboros.Network.Block | |
NoThunks MaxSlotNo Source # | |
type Rep MaxSlotNo Source # | |
Defined in Ouroboros.Network.Block type Rep MaxSlotNo = D1 ('MetaData "MaxSlotNo" "Ouroboros.Network.Block" "ouroboros-network-api-0.7.2.0-inplace" '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 #
encodeChainHash ∷ (HeaderHash block → Encoding) → ChainHash block → Encoding Source #
decodePoint ∷ (∀ s. Decoder s (HeaderHash block)) → ∀ s. Decoder s (Point block) Source #
decodeChainHash ∷ (∀ s. Decoder s (HeaderHash block)) → ∀ 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
wrapCBORinCBOR ∷ (a → Encoding) → a → Encoding Source #
Wrap CBOR-in-CBOR
This is primarily useful for the decoder; see unwrapCBORinCBOR
unwrapCBORinCBOR ∷ (∀ s. Decoder s (ByteString → a)) → ∀ 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 ∷ (∀ s. Decoder s (ByteString → a)) → Serialised a → ∀ 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.