ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Leios.Types

Description

The Leios types that the storage layer needs: hashes, points, endorser block bodies and their sizes.

This is the slice of the Leios prototype's types that Ouroboros.Consensus.Storage.LeiosDB depends on. The rest of the Leios machinery (announcements, fetch, voting, certificates) extends this module as it lands.

Synopsis

Hashes

type EndorserBlockHash = Hash HASH EraIndependentEbReferences Source #

The hash of an endorser block, as ranking blocks announce it.

newtype RankingBlockHash Source #

The hash of a ranking block's header, which votes sign.

Ranking blocks are Praos blocks, whose HeaderHash depends on blk. Use toRankingBlockHash to convert it to this monomorphic type.

Instances

Instances details
FromCBOR RankingBlockHash Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

ToCBOR RankingBlockHash Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

SignableRepresentation RankingBlockHash Source #

Used by Leios voting, which signs the hash's bytes.

Instance details

Defined in Ouroboros.Consensus.Leios.Types

Eq RankingBlockHash Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Ord RankingBlockHash Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Generic RankingBlockHash Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Associated Types

type Rep RankingBlockHash 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep RankingBlockHash = D1 ('MetaData "RankingBlockHash" "Ouroboros.Consensus.Leios.Types" "ouroboros-consensus-5.0.0.0-inplace" 'True) (C1 ('MetaCons "MkRankingBlockHash" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRankingBlockHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Hash HASH EraIndependentBlockHeader))))
Show RankingBlockHash Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

NoThunks RankingBlockHash Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep RankingBlockHash Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep RankingBlockHash = D1 ('MetaData "RankingBlockHash" "Ouroboros.Consensus.Leios.Types" "ouroboros-consensus-5.0.0.0-inplace" 'True) (C1 ('MetaCons "MkRankingBlockHash" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRankingBlockHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Hash HASH EraIndependentBlockHeader))))

toRankingBlockHash ∷ ConvertRawHash blk ⇒ Proxy blk → HeaderHash blk → RankingBlockHash Source #

Convert a ranking block's HeaderHash. It must be the same length as a RankingBlockHash, ie 32 bytes.

TODO Rule out a HeaderHash of another size at compile time, as Peras does with HashSize blk ~ 32, without requiring it of every RunNode block.

type TxHash = Hash HASH EraIndependentTx Source #

The hash of a transaction an endorser block references. It hashes all of the transaction's bytes, witnesses included, unlike the ledger's TxId and so the mempool's GenTxId, which hash only the transaction's body.

Transactions

newtype LeiosTx Source #

A Leios transaction, as the CBOR bytes of the ledger's transaction.

Its codec wraps those bytes as CBOR-in-CBOR, so receiving a transaction does not decode it.

TODO ChainSel and Leios voting will need a way to actually decode the transaction: a per-block-type decoder that takes the ledger state resulting from the announcing ranking block, whose era is the one the endorser block was announced in.

Constructors

MkLeiosTx 

Instances

Instances details
Eq LeiosTx Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Methods

(==) ∷ LeiosTx → LeiosTx → Bool #

(/=) ∷ LeiosTx → LeiosTx → Bool #

Show LeiosTx Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Methods

showsPrec ∷ Int → LeiosTx → ShowS #

show ∷ LeiosTx → String #

showList ∷ [LeiosTx] → ShowS #

ShowProxy LeiosTx Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Methods

showProxy ∷ Proxy LeiosTx → String #

Points

data LeiosPoint Source #

Uniquely identifies an endorser block in Leios. Could use 'Block SlotNo EndorserBlockHash' eventually, but a dedicated type is better to explore.

Instances

Instances details
Eq LeiosPoint Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Methods

(==) ∷ LeiosPoint → LeiosPoint → Bool #

(/=) ∷ LeiosPoint → LeiosPoint → Bool #

Ord LeiosPoint Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Generic LeiosPoint Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Associated Types

type Rep LeiosPoint 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep LeiosPoint = D1 ('MetaData "LeiosPoint" "Ouroboros.Consensus.Leios.Types" "ouroboros-consensus-5.0.0.0-inplace" 'False) (C1 ('MetaCons "MkLeiosPoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "pointSlotNo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SlotNo) :*: S1 ('MetaSel ('Just "pointEbHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EndorserBlockHash)))
Show LeiosPoint Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

NoThunks LeiosPoint Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

ShowProxy LeiosPoint Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep LeiosPoint Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep LeiosPoint = D1 ('MetaData "LeiosPoint" "Ouroboros.Consensus.Leios.Types" "ouroboros-consensus-5.0.0.0-inplace" 'False) (C1 ('MetaCons "MkLeiosPoint" 'PrefixI 'True) (S1 ('MetaSel ('Just "pointSlotNo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SlotNo) :*: S1 ('MetaSel ('Just "pointEbHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EndorserBlockHash)))

Elections

data ElectionId Source #

A ranking block leadership election: a slot and the pool it elected.

This is unrelated to the ElectionId type family, which identifies an election of a voting committee. We do not anticipate a module using both.

The derived Ord orders by slot first, which pruning relies on.

Instances

Instances details
Eq ElectionId Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Methods

(==) ∷ ElectionId → ElectionId → Bool #

(/=) ∷ ElectionId → ElectionId → Bool #

Ord ElectionId Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Generic ElectionId Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Associated Types

type Rep ElectionId 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep ElectionId = D1 ('MetaData "ElectionId" "Ouroboros.Consensus.Leios.Types" "ouroboros-consensus-5.0.0.0-inplace" 'False) (C1 ('MetaCons "ElectionId" 'PrefixI 'True) (S1 ('MetaSel ('Just "electionSlot") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SlotNo) :*: S1 ('MetaSel ('Just "electionElectee") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (KeyHash 'BlockIssuer))))
Show ElectionId Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

NoThunks ElectionId Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep ElectionId Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep ElectionId = D1 ('MetaData "ElectionId" "Ouroboros.Consensus.Leios.Types" "ouroboros-consensus-5.0.0.0-inplace" 'False) (C1 ('MetaCons "ElectionId" 'PrefixI 'True) (S1 ('MetaSel ('Just "electionSlot") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SlotNo) :*: S1 ('MetaSel ('Just "electionElectee") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (KeyHash 'BlockIssuer))))

Votes

data LeiosVote Source #

A vote for a Leios announcement.

Constructors

MkLeiosVote 

Fields

Instances

Instances details
Eq LeiosVote Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Methods

(==) ∷ LeiosVote → LeiosVote → Bool #

(/=) ∷ LeiosVote → LeiosVote → Bool #

Generic LeiosVote Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Associated Types

type Rep LeiosVote 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep LeiosVote = D1 ('MetaData "LeiosVote" "Ouroboros.Consensus.Leios.Types" "ouroboros-consensus-5.0.0.0-inplace" 'False) (C1 ('MetaCons "MkLeiosVote" 'PrefixI 'True) (S1 ('MetaSel ('Just "voteAnnouncingRbHash") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RankingBlockHash) :*: (S1 ('MetaSel ('Just "voteSeatId") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LeiosSeatId) :*: S1 ('MetaSel ('Just "voteSignature") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LeiosSignature))))

Methods

from ∷ LeiosVote → Rep LeiosVote x #

to ∷ Rep LeiosVote x → LeiosVote #

Show LeiosVote Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Methods

showsPrec ∷ Int → LeiosVote → ShowS #

show ∷ LeiosVote → String #

showList ∷ [LeiosVote] → ShowS #

NoThunks LeiosVote Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

ShowProxy LeiosVote Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep LeiosVote Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep LeiosVote = D1 ('MetaData "LeiosVote" "Ouroboros.Consensus.Leios.Types" "ouroboros-consensus-5.0.0.0-inplace" 'False) (C1 ('MetaCons "MkLeiosVote" 'PrefixI 'True) (S1 ('MetaSel ('Just "voteAnnouncingRbHash") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RankingBlockHash) :*: (S1 ('MetaSel ('Just "voteSeatId") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LeiosSeatId) :*: S1 ('MetaSel ('Just "voteSignature") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LeiosSignature))))

Endorser blocks

data EndorserBlock Source #

An endorser block in the Leios overlay protocol. It endorses transactions by naming a list of TxHash and BytesSize pairs. Construct using mkEndorserBlock.

A compatibility layer over the ledger's EbReferences: consensus sees only this module's functions, never the ledger's representation.

Instances

Instances details
NFData EndorserBlock Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Methods

rnf ∷ EndorserBlock → () #

Eq EndorserBlock Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Generic EndorserBlock Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

Associated Types

type Rep EndorserBlock 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep EndorserBlock = D1 ('MetaData "EndorserBlock" "Ouroboros.Consensus.Leios.Types" "ouroboros-consensus-5.0.0.0-inplace" 'True) (C1 ('MetaCons "MkEndorserBlock" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EbReferences)))
Show EndorserBlock Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

NoThunks EndorserBlock Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

ShowProxy EndorserBlock Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep EndorserBlock Source # 
Instance details

Defined in Ouroboros.Consensus.Leios.Types

type Rep EndorserBlock = D1 ('MetaData "EndorserBlock" "Ouroboros.Consensus.Leios.Types" "ouroboros-consensus-5.0.0.0-inplace" 'True) (C1 ('MetaCons "MkEndorserBlock" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EbReferences)))

type TxOffset = Int Source #

The position of a transaction in its endorser block.

mkEndorserBlock ∷ [(TxHash, BytesSize)] → EndorserBlock Source #

An endorser block naming these transactions, in this order.

endorserBlockFromTxBytes ∷ NonEmpty ByteString → EndorserBlock Source #

The endorser block naming the transactions with these bytes, in this order. It names each by the TxHash and the length of its bytes.

endorserBlockHash ∷ EndorserBlock → EndorserBlockHash Source #

The hash ranking blocks announce for the endorser block: that of its encoding.

endorserBlockReferences ∷ EndorserBlock → [(TxHash, BytesSize)] Source #

The transactions an endorser block names, in order.

encodeEndorserBlock ∷ EndorserBlock → Encoding Source #

Encode an endorser block as the ledger does: a CBOR map from each transaction hash to the size of that transaction.

The mempool charges each transaction sizeEndorserBlockReference, and referencesCapacity subtracts the framing around the references. If the encoding changes, both must change with it.

decodeEndorserBlock ∷ Decoder s (ByteString → EndorserBlock) Source #

The inverse of encodeEndorserBlock, given the whole input it decoded from, not just the endorser block's bytes: the ledger's annotator slices them by the byte offsets of this decoder's run. Like the ledger, it rejects an empty map of transaction references and one naming a transaction twice. It also rejects one whose bytes exceed maxEndorserBlockBytesSize. It can tell only after decoding them (if endorser blocks were wrapped as CBOR-in-CBOR, it would know their length before decoding them, even from an indefinite-length byte string), since a CBOR map gives its number of entries rather than of bytes. So the byte limit of the message carrying it must keep small the work it does before then, eg byteLimitsLeiosFetch.

The endorser block keeps its slice of those bytes, so its hash and encoding are of the bytes received.

sizeEndorserBlockReference ∷ ByteSize32 → ByteSize32 Source #

The bytes one reference occupies for a transaction of the given size: the hash and the size, exactly as encodeEndorserBlock writes them.

Also used on the Dijkstra transaction measure, so the mempool charges a transaction what it will actually cost in the reference list rather than an approximation of it.

encodeEndorserBlockSize ∷ EndorserBlock → BytesSize Source #

The size of encodeEndorserBlock: of the bytes the endorser block was received in, or of the ledger's encoding of one this node built.

referencesCapacity ∷ BytesSize → BytesSize Source #

The references capacity a maxEndorserBlockReferencesSize parameter yields: the parameter minus the framing encodeEndorserBlock writes ahead of the references. A parameter smaller than the framing exhausts the capacity, so no reference fits, rather than wrapping around to "no limit".

maxEndorserBlockBytesSize ∷ BytesSize Source #

The design ceiling on an endorser block's encoding: what the node will forge, serve and size its buffers for.

TODO Nothing yet keeps the maxEndorserBlockReferencesSize protocol parameter within it, so a larger value would let an honest peer send an endorser block that decodeEndorserBlock rejects. Make it the constitution's guardrail on that parameter, and refuse to run with a parameter above it.

maxTxsPerEndorserBlock ∷ Int Source #

The most transactions an endorser block may name, given maxEndorserBlockBytesSize. Each reference takes at least as many bytes as sizeEndorserBlockReference charges a transaction of size 0, however it is encoded.

It derives from the design ceiling and not from the protocol parameter, since the buffers it sizes are allocated before any ledger state is in reach.

Header checks

milliseconds32ToNominalDiffTime ∷ Milliseconds32 → NominalDiffTime Source #

A duration the ledger gives in milliseconds.

minCertificationSlot Source #

Arguments

∷ SlotLength 
→ Milliseconds32

Announcement period length

→ Milliseconds32

Vote period length

→ Milliseconds32

Diffusion period length

→ SlotNo

Slot of the announcing block

→ SlotNo 

The earliest slot at which a block may certify an endorser block announced in the given slot.

The announcement, voting and diffusion periods must all have elapsed. They are wall-clock durations, so the gap rounds up to whole slots: a block is forged at its slot's onset, so the answer is the first slot whose onset is far enough after the announcement.