ouroboros-consensus-0.21.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ouroboros.Consensus.HeaderStateHistory

Description

HeaderState history

Intended for qualified import

import           Ouroboros.Consensus.HeaderStateHistory (HeaderStateHistory)
import qualified Ouroboros.Consensus.HeaderStateHistory as HeaderStateHistory
Synopsis

Documentation

newtype HeaderStateHistory blk Source #

Maintain a history of HeaderStateWithTimes.

Instances

Instances details
Generic (HeaderStateHistory blk) Source # 
Instance details

Defined in Ouroboros.Consensus.HeaderStateHistory

Associated Types

type Rep (HeaderStateHistory blk) ∷ TypeType #

(BlockSupportsProtocol blk, HasAnnTip blk) ⇒ Show (HeaderStateHistory blk) Source # 
Instance details

Defined in Ouroboros.Consensus.HeaderStateHistory

(BlockSupportsProtocol blk, HasAnnTip blk) ⇒ Eq (HeaderStateHistory blk) Source # 
Instance details

Defined in Ouroboros.Consensus.HeaderStateHistory

(BlockSupportsProtocol blk, HasAnnTip blk) ⇒ NoThunks (HeaderStateHistory blk) Source # 
Instance details

Defined in Ouroboros.Consensus.HeaderStateHistory

type Rep (HeaderStateHistory blk) Source # 
Instance details

Defined in Ouroboros.Consensus.HeaderStateHistory

type Rep (HeaderStateHistory blk) = D1 ('MetaData "HeaderStateHistory" "Ouroboros.Consensus.HeaderStateHistory" "ouroboros-consensus-0.21.0.0-inplace" 'True) (C1 ('MetaCons "HeaderStateHistory" 'PrefixI 'True) (S1 ('MetaSel ('Just "unHeaderStateHistory") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (AnchoredSeq (WithOrigin SlotNo) (HeaderStateWithTime blk) (HeaderStateWithTime blk)))))

rewind ∷ ∀ blk. HasAnnTip blk ⇒ Point blk → HeaderStateHistory blk → Maybe (HeaderStateHistory blk, Maybe (HeaderStateWithTime blk)) Source #

\( O\(n\) ). Rewind the header state history

We also return the oldest HeaderStateWithTime that was rewound, if any.

NOTE: we don't distinguish headers of regular blocks from headers of EBBs. Whenever we use "header" it can be either. In practice, EBB headers do not affect the ChainDepState, but they do affect the AnnTip.

PRECONDITION: the point to rewind to must correspond to a header (or GenesisPoint) that was previously applied to the header state history.

Rewinding the header state history is intended to be used when switching to a fork, longer or equally long to the chain to which the current header state corresponds. So each rewinding should be followed by rolling forward (using headerStateHistoryPush) at least as many blocks that we have rewound.

Note that repeatedly rewinding a header state history does not make it possible to rewind it all the way to genesis (this would mean that the whole historical header state is accumulated or derivable from the current header state history). For example, rewinding a header state by i blocks and then rewinding that header state again by j where i + j > k is not possible and will yield Nothing.

trimIntHeaderStateHistory blk → HeaderStateHistory blk Source #

Trim the HeaderStateHistory to the given size, dropping the oldest snapshots. The anchor will be shifted accordingly.

Note that we do not include the anchor in the size. For example, trimming to 0 results in no snapshots but still an anchor. Trimming to 1 results in 1 snapshot and an anchor.

HeaderStateWithTime

data HeaderStateWithTime blk Source #

A HeaderState together with the RelativeTime corresponding to the tip slot of the state. For a state at Origin, we use the same time as for slot 0.

Instances

Instances details
Generic (HeaderStateWithTime blk) Source # 
Instance details

Defined in Ouroboros.Consensus.HeaderStateHistory

Associated Types

type Rep (HeaderStateWithTime blk) ∷ TypeType #

(BlockSupportsProtocol blk, HasAnnTip blk) ⇒ Show (HeaderStateWithTime blk) Source # 
Instance details

Defined in Ouroboros.Consensus.HeaderStateHistory

(BlockSupportsProtocol blk, HasAnnTip blk) ⇒ Eq (HeaderStateWithTime blk) Source # 
Instance details

Defined in Ouroboros.Consensus.HeaderStateHistory

(BlockSupportsProtocol blk, HasAnnTip blk) ⇒ NoThunks (HeaderStateWithTime blk) Source # 
Instance details

Defined in Ouroboros.Consensus.HeaderStateHistory

Anchorable (WithOrigin SlotNo) (HeaderStateWithTime blk) (HeaderStateWithTime blk) Source # 
Instance details

Defined in Ouroboros.Consensus.HeaderStateHistory

type Rep (HeaderStateWithTime blk) Source # 
Instance details

Defined in Ouroboros.Consensus.HeaderStateHistory

type Rep (HeaderStateWithTime blk) = D1 ('MetaData "HeaderStateWithTime" "Ouroboros.Consensus.HeaderStateHistory" "ouroboros-consensus-0.21.0.0-inplace" 'False) (C1 ('MetaCons "HeaderStateWithTime" 'PrefixI 'True) (S1 ('MetaSel ('Just "hswtHeaderState") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (HeaderState blk)) :*: S1 ('MetaSel ('Just "hswtSlotTime") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RelativeTime)))

mkHeaderStateWithTimeFromSummary Source #

Arguments

∷ (HasCallStack, HasAnnTip blk) 
Summary (HardForkIndices blk)

Must be able to convert the tip slot of the HeaderState to a time.

HeaderState blk 
HeaderStateWithTime blk 

Validation

validateHeader Source #

Arguments

∷ ∀ blk. (BlockSupportsProtocol blk, ValidateEnvelope blk) 
TopLevelConfig blk 
LedgerView (BlockProtocol blk) 
Header blk 
RelativeTime

The time of the slot of the header.

HeaderStateHistory blk 
Except (HeaderError blk) (HeaderStateHistory blk) 

Variation on validateHeader that maintains a HeaderStateHistory.

This is used only in the chain sync client for header-only validation.

Note: this function does not trim the HeaderStateHistory.

Support for tests

fromChain Source #

Arguments

∷ ∀ blk. (ApplyBlock (ExtLedgerState blk) blk, HasHardForkHistory blk, HasAnnTip blk) 
TopLevelConfig blk 
ExtLedgerState blk

Initial ledger state

Chain blk 
HeaderStateHistory blk 

Create a HeaderStateHistory corresponding to the blocks in the given Chain.

PRECONDITION: the blocks in the chain are valid.