ouroboros-consensus-0.1.0.1: Consensus layer for the Ouroboros blockchain protocol
Safe Haskell None
Language Haskell2010

Ouroboros.Consensus.HeaderValidation

Description

Header validation

Synopsis

Documentation

revalidateHeader :: forall blk. ( BlockSupportsProtocol blk, ValidateEnvelope blk, HasCallStack ) => TopLevelConfig blk -> Ticked ( LedgerView ( BlockProtocol blk)) -> Header blk -> Ticked ( HeaderState blk) -> HeaderState blk Source #

Header revalidation

Same as validateHeader but used when the header has been validated before w.r.t. the same exact HeaderState .

Expensive validation checks are skipped ( reupdateChainDepState vs. updateChainDepState ).

validateHeader :: ( BlockSupportsProtocol blk, ValidateEnvelope blk) => TopLevelConfig blk -> Ticked ( LedgerView ( BlockProtocol blk)) -> Header blk -> Ticked ( HeaderState blk) -> Except ( HeaderError blk) ( HeaderState blk) Source #

Header validation

Header validation (as opposed to block validation) is done by the chain sync client: as we download headers from other network nodes, we validate those headers before deciding whether or not to download the corresponding blocks.

Before we adopt any blocks we have downloaded, however, we will do a full block validation. As such, the header validation check can omit some checks (provided that we do those checks when we do the full validation); at worst, this would mean we might download some blocks that we will reject as being invalid where we could have detected that sooner.

For this reason, the header validation currently only checks two things:

o It verifies the consensus part of the header.

For example, for Praos this means checking the VRF proofs.

o It verifies the HasHeader part of the header.

By default, we verify that

x Block numbers are consecutive x The block number of the first block is firstBlockNo x Slot numbers are strictly increasing x The slot number of the first block is at least minimumPossibleSlotNo x Hashes line up

If a particular ledger wants to verify additional fields in the header, it will get the chance to do so in applyBlockLedgerResult , which is passed the entire block (not just the block body).

Annotated tips

data AnnTip blk Source #

Annotated information about the tip of the chain

The annotation is the additional information we need to validate the header envelope. Under normal circumstances no additional information is required, but for instance for Byron we need to know if the previous header was an EBB.

Instances

Instances details
Isomorphic AnnTip Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Embed.Unary

Inject AnnTip Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Embed.Nary

HasAnnTip blk => Eq ( AnnTip blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

HasAnnTip blk => Show ( AnnTip blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Generic ( AnnTip blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Associated Types

type Rep ( AnnTip blk) :: Type -> Type Source #

HasAnnTip blk => NoThunks ( AnnTip blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

SerialiseHFC xs => DecodeDisk ( HardForkBlock xs) ( AnnTip ( HardForkBlock xs)) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk

SerialiseHFC xs => EncodeDisk ( HardForkBlock xs) ( AnnTip ( HardForkBlock xs)) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk

type Rep ( AnnTip blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

type Rep ( AnnTip blk) = D1 (' MetaData "AnnTip" "Ouroboros.Consensus.HeaderValidation" "ouroboros-consensus-0.1.0.1-DT4Cvwf63DZKctsEvaJqCU" ' False ) ( C1 (' MetaCons "AnnTip" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "annTipSlotNo") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 SlotNo ) :*: ( S1 (' MetaSel (' Just "annTipBlockNo") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 BlockNo ) :*: S1 (' MetaSel (' Just "annTipInfo") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 ( TipInfo blk)))))

Header state

data HeaderState blk Source #

State required to validate the header

See validateHeader for details

Instances

Instances details
Isomorphic HeaderState Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Embed.Unary

Inject HeaderState Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Embed.Nary

( BlockSupportsProtocol blk, HasAnnTip blk) => Eq ( HeaderState blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

( BlockSupportsProtocol blk, HasAnnTip blk) => Show ( HeaderState blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Generic ( HeaderState blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Associated Types

type Rep ( HeaderState blk) :: Type -> Type Source #

( BlockSupportsProtocol blk, HasAnnTip blk) => NoThunks ( HeaderState blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Anchorable ( WithOrigin SlotNo ) ( HeaderState blk) ( HeaderState blk) Source #

Used by HeaderStateHistory but defined here, where it is not an orphan.

Instance details

Defined in Ouroboros.Consensus.HeaderValidation

type Rep ( HeaderState blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

type Rep ( HeaderState blk) = D1 (' MetaData "HeaderState" "Ouroboros.Consensus.HeaderValidation" "ouroboros-consensus-0.1.0.1-DT4Cvwf63DZKctsEvaJqCU" ' False ) ( C1 (' MetaCons "HeaderState" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "headerStateTip") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 ( WithOrigin ( AnnTip blk))) :*: S1 (' MetaSel (' Just "headerStateChainDep") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 ( ChainDepState ( BlockProtocol blk)))))
data Ticked ( HeaderState blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Validate header envelope

class ( HasHeader ( Header blk), HasAnnTip blk) => BasicEnvelopeValidation blk where Source #

Ledger-independent envelope validation (block, slot, hash)

Minimal complete definition

Nothing

Methods

expectedFirstBlockNo :: proxy blk -> BlockNo Source #

The block number of the first block on the chain

expectedNextBlockNo Source #

Arguments

:: proxy blk
-> TipInfo blk

Old tip

-> TipInfo blk

New block

-> BlockNo
-> BlockNo

Next block number

minimumPossibleSlotNo :: Proxy blk -> SlotNo Source #

The smallest possible SlotNo

NOTE: This does not affect the translation between SlotNo and EpochNo . Ouroboros.Consensus.HardFork.History for details.

minimumNextSlotNo Source #

Arguments

:: proxy blk
-> TipInfo blk

Old tip

-> TipInfo blk

New block

-> SlotNo
-> SlotNo

Minimum next slot number

data HeaderEnvelopeError blk Source #

Constructors

UnexpectedBlockNo ! BlockNo ! BlockNo

Invalid block number

We record both the expected and actual block number

UnexpectedSlotNo ! SlotNo ! SlotNo

Invalid slot number

We record both the expected (minimum) and actual slot number

UnexpectedPrevHash !( WithOrigin ( HeaderHash blk)) !( ChainHash blk)

Invalid hash (in the reference to the previous block)

We record the current tip as well as the prev hash of the new block.

OtherHeaderEnvelopeError !( OtherHeaderEnvelopeError blk)

Block specific envelope error

Instances

Instances details
ValidateEnvelope blk => Eq ( HeaderEnvelopeError blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

ValidateEnvelope blk => Show ( HeaderEnvelopeError blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Generic ( HeaderEnvelopeError blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

( ValidateEnvelope blk, Typeable blk) => NoThunks ( HeaderEnvelopeError blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

type Rep ( HeaderEnvelopeError blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

class ( BasicEnvelopeValidation blk, GetPrevHash blk, Eq ( OtherHeaderEnvelopeError blk), Show ( OtherHeaderEnvelopeError blk), NoThunks ( OtherHeaderEnvelopeError blk)) => ValidateEnvelope blk where Source #

Validate header envelope

Minimal complete definition

Nothing

Associated Types

type OtherHeaderEnvelopeError blk :: Type Source #

A block-specific error that validateEnvelope can return.

Errors

data HeaderError blk Source #

Invalid header

Constructors

HeaderProtocolError !( ValidationErr ( BlockProtocol blk))

Invalid consensus protocol fields

HeaderEnvelopeError !( HeaderEnvelopeError blk)

Failed to validate the envelope

Instances

Instances details
( BlockSupportsProtocol blk, ValidateEnvelope blk) => Eq ( HeaderError blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

( BlockSupportsProtocol blk, ValidateEnvelope blk) => Show ( HeaderError blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Generic ( HeaderError blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Associated Types

type Rep ( HeaderError blk) :: Type -> Type Source #

( BlockSupportsProtocol blk, ValidateEnvelope blk, Typeable blk) => NoThunks ( HeaderError blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

type Rep ( HeaderError blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

TipInfoIsEBB

data TipInfoIsEBB blk Source #

Reusable strict data type for TipInfo in case the TipInfo should contain IsEBB in addition to the HeaderHash .

Instances

Instances details
StandardHash blk => Eq ( TipInfoIsEBB blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

StandardHash blk => Show ( TipInfoIsEBB blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Generic ( TipInfoIsEBB blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Associated Types

type Rep ( TipInfoIsEBB blk) :: Type -> Type Source #

StandardHash blk => NoThunks ( TipInfoIsEBB blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

type Rep ( TipInfoIsEBB blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

Serialization

Type family instances

data family Ticked st :: Type Source #

" Ticked " piece of state ( LedgerState , LedgerView , ChainIndepState )

Ticking refers to the passage of time (the ticking of the clock). When a piece of state is marked as ticked, it means that time-related changes have been applied to the state (or forecast).

Some examples of time related changes:

  • Scheduled delegations might have been applied in Byron
  • New leader schedule computed for Shelley
  • Transition from Byron to Shelley activated in the hard fork combinator.
  • Nonces switched out at the start of a new epoch.

Instances

Instances details
Show ( Ticked ()) Source #
Instance details

Defined in Ouroboros.Consensus.Ticked

Show ( Ticked a) => Show ( Ticked ( K a x)) Source #
Instance details

Defined in Ouroboros.Consensus.Ticked

( SListI xs, Show ( Ticked a)) => Show ( Ticked ( HardForkLedgerView_ ( K a :: Type -> Type ) xs)) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Protocol.LedgerView

Generic ( Ticked ( LedgerState ( HardForkBlock xs))) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Ledger

NoThunks ( Ticked ( LedgerState ( DualBlock m a))) Source #
Instance details

Defined in Ouroboros.Consensus.Ledger.Dual

CanHardFork xs => NoThunks ( Ticked ( LedgerState ( HardForkBlock xs))) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Ledger

Bridge m a => GetTip ( Ticked ( LedgerState ( DualBlock m a))) Source #
Instance details

Defined in Ouroboros.Consensus.Ledger.Dual

CanHardFork xs => GetTip ( Ticked ( LedgerState ( HardForkBlock xs))) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Ledger

IsLedger ( LedgerState blk) => GetTip ( Ticked ( ExtLedgerState blk)) Source #
Instance details

Defined in Ouroboros.Consensus.Ledger.Extended

IsLedger l => GetTip ( Ticked ( LedgerDB l)) Source #
Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.InMemory

Isomorphic ( Ticked :.: LedgerState ) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Embed.Unary

Show ( Ticked (f a)) => Show (( Ticked :.: f) a) Source #
Instance details

Defined in Ouroboros.Consensus.Ticked

NoThunks ( Ticked (f a)) => NoThunks (( Ticked :.: f) a) Source #
Instance details

Defined in Ouroboros.Consensus.Ticked

data Ticked () Source #
Instance details

Defined in Ouroboros.Consensus.Ticked

type Rep ( Ticked ( LedgerState ( HardForkBlock xs))) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Ledger

type Rep ( Ticked ( LedgerState ( HardForkBlock xs))) = D1 (' MetaData "Ticked" "Ouroboros.Consensus.HardFork.Combinator.Ledger" "ouroboros-consensus-0.1.0.1-DT4Cvwf63DZKctsEvaJqCU" ' False ) ( C1 (' MetaCons "TickedHardForkLedgerState" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "tickedHardForkLedgerStateTransition") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 TransitionInfo ) :*: S1 (' MetaSel (' Just "tickedHardForkLedgerStatePerEra") ' NoSourceUnpackedness ' SourceStrict ' DecidedStrict ) ( Rec0 ( HardForkState ( Ticked :.: LedgerState ) xs))))
type HeaderHash ( Ticked l) Source #
Instance details

Defined in Ouroboros.Consensus.Ledger.Basics

data Ticked ( LedgerState ( DualBlock m a)) Source #
Instance details

Defined in Ouroboros.Consensus.Ledger.Dual

data Ticked ( LedgerState ( HardForkBlock xs)) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Ledger

data Ticked ( HeaderState blk) Source #
Instance details

Defined in Ouroboros.Consensus.HeaderValidation

newtype Ticked ( WrapLedgerView blk) Source #
Instance details

Defined in Ouroboros.Consensus.TypeFamilyWrappers

newtype Ticked ( WrapChainDepState blk) Source #
Instance details

Defined in Ouroboros.Consensus.TypeFamilyWrappers

data Ticked ( ExtLedgerState blk) Source #
Instance details

Defined in Ouroboros.Consensus.Ledger.Extended

data Ticked ( LedgerDB l) Source #

Ticking the ledger DB just ticks the current state

We don't push the new state into the DB until we apply a block.

Instance details

Defined in Ouroboros.Consensus.Storage.LedgerDB.InMemory

data Ticked ( HardForkChainDepState xs) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Protocol

data Ticked ( PBftState c) Source #
Instance details

Defined in Ouroboros.Consensus.Protocol.PBFT

newtype Ticked ( PBftLedgerView c) Source #
Instance details

Defined in Ouroboros.Consensus.Protocol.PBFT

data Ticked ( HardForkLedgerView_ f xs) Source #
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Protocol.LedgerView

newtype Ticked ( K a x) Source #
Instance details

Defined in Ouroboros.Consensus.Ticked