ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Peras.Context

Synopsis

Bounded Peras epoch context

data BoundedPerasEpochContext blk Source #

A PerasEpochContext that is valid only in a given range of round numbers

Constructors

BoundedPerasEpochContext 

Fields

Instances

Instances details
FromCBOR (BoundedPerasEpochContext blk) ⇒ DecodeDisk blk (BoundedPerasEpochContext blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

ToCBOR (BoundedPerasEpochContext blk) ⇒ EncodeDisk blk (BoundedPerasEpochContext blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

(Typeable blk, FromCBOR (PerasVotingCommittee blk))FromCBOR (BoundedPerasEpochContext blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

(Typeable blk, ToCBOR (PerasVotingCommittee blk))ToCBOR (BoundedPerasEpochContext blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Eq (PerasEpochContext blk) ⇒ Eq (BoundedPerasEpochContext blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Generic (BoundedPerasEpochContext blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Associated Types

type Rep (BoundedPerasEpochContext blk) 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

type Rep (BoundedPerasEpochContext blk) = D1 ('MetaData "BoundedPerasEpochContext" "Ouroboros.Consensus.Peras.Context" "ouroboros-consensus-4.0.0.0-inplace" 'False) (C1 ('MetaCons "BoundedPerasEpochContext" 'PrefixI 'True) (S1 ('MetaSel ('Just "startPerasRoundNo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PerasRoundNo) :*: (S1 ('MetaSel ('Just "endPerasRoundNo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PerasRoundNo) :*: S1 ('MetaSel ('Just "epochContext") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PerasEpochContext blk)))))
Show (PerasEpochContext blk) ⇒ Show (BoundedPerasEpochContext blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

NoThunks (PerasEpochContext blk) ⇒ NoThunks (BoundedPerasEpochContext blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

type Rep (BoundedPerasEpochContext blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

type Rep (BoundedPerasEpochContext blk) = D1 ('MetaData "BoundedPerasEpochContext" "Ouroboros.Consensus.Peras.Context" "ouroboros-consensus-4.0.0.0-inplace" 'False) (C1 ('MetaCons "BoundedPerasEpochContext" 'PrefixI 'True) (S1 ('MetaSel ('Just "startPerasRoundNo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PerasRoundNo) :*: (S1 ('MetaSel ('Just "endPerasRoundNo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PerasRoundNo) :*: S1 ('MetaSel ('Just "epochContext") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PerasEpochContext blk)))))

withinEpochContextPerasRoundNoBoundedPerasEpochContext blk → Maybe (PerasEpochContext blk) Source #

Check whether a given PerasRoundNo is within the bounds of a BoundedPerasEpochContext.

Returns the corresponding PerasEpochContext if the round number is within the bounds, or Nothing otherwise.

Peras epoch context resolver and handle

data PerasEpochContextResolver blk Source #

A two-epoch window of Peras epoch contexts, which can be used to resolve round numbers into their corresponding Peras contexts.

Constructors

PerasEpochContextResolverError !String

The resolver is in an error state, and cannot resolve any round number.

NOTE: this exists to allow for recoverable errors during resolver initialisation or ticking caused, e.g., by incorrect parameterization.

PerasEpochContextResolver

The resolver has a two-epoch window of Peras epoch contexts, which may be empty if Peras is not enabled in either of these epochs.

Fields

Instances

Instances details
FromCBOR (PerasEpochContextResolver blk) ⇒ DecodeDisk blk (PerasEpochContextResolver blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

ToCBOR (PerasEpochContextResolver blk) ⇒ EncodeDisk blk (PerasEpochContextResolver blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

(Typeable blk, FromCBOR (PerasVotingCommittee blk))FromCBOR (PerasEpochContextResolver blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

(Typeable blk, ToCBOR (PerasVotingCommittee blk))ToCBOR (PerasEpochContextResolver blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Eq (PerasEpochContext blk) ⇒ Eq (PerasEpochContextResolver blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Generic (PerasEpochContextResolver blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Associated Types

type Rep (PerasEpochContextResolver blk) 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

type Rep (PerasEpochContextResolver blk) = D1 ('MetaData "PerasEpochContextResolver" "Ouroboros.Consensus.Peras.Context" "ouroboros-consensus-4.0.0.0-inplace" 'False) (C1 ('MetaCons "PerasEpochContextResolverError" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 String)) :+: C1 ('MetaCons "PerasEpochContextResolver" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (PerasEnabled (BoundedPerasEpochContext blk))) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (PerasEnabled (BoundedPerasEpochContext blk)))))
Show (PerasEpochContext blk) ⇒ Show (PerasEpochContextResolver blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

NoThunks (PerasEpochContext blk) ⇒ NoThunks (PerasEpochContextResolver blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

type Rep (PerasEpochContextResolver blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

type Rep (PerasEpochContextResolver blk) = D1 ('MetaData "PerasEpochContextResolver" "Ouroboros.Consensus.Peras.Context" "ouroboros-consensus-4.0.0.0-inplace" 'False) (C1 ('MetaCons "PerasEpochContextResolverError" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 String)) :+: C1 ('MetaCons "PerasEpochContextResolver" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (PerasEnabled (BoundedPerasEpochContext blk))) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (PerasEnabled (BoundedPerasEpochContext blk)))))

data PerasEpochContextNotFoundForRound Source #

An error indicating that a PerasEpochContext could not be found for a given PerasRoundNo in a PerasEpochContextResolver.

Constructors

PerasEpochContextNotFoundForRound 

Fields

  • !PerasRoundNo

    The round number for which the context could not be found.

  • !String

    Detailed reason for the failure.

Instances

Instances details
Eq PerasEpochContextNotFoundForRound Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Exception PerasEpochContextNotFoundForRound Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Generic PerasEpochContextNotFoundForRound Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Associated Types

type Rep PerasEpochContextNotFoundForRound 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

type Rep PerasEpochContextNotFoundForRound = D1 ('MetaData "PerasEpochContextNotFoundForRound" "Ouroboros.Consensus.Peras.Context" "ouroboros-consensus-4.0.0.0-inplace" 'False) (C1 ('MetaCons "PerasEpochContextNotFoundForRound" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PerasRoundNo) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 String)))
Show PerasEpochContextNotFoundForRound Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

NoThunks PerasEpochContextNotFoundForRound Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

type Rep PerasEpochContextNotFoundForRound Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

type Rep PerasEpochContextNotFoundForRound = D1 ('MetaData "PerasEpochContextNotFoundForRound" "Ouroboros.Consensus.Peras.Context" "ouroboros-consensus-4.0.0.0-inplace" 'False) (C1 ('MetaCons "PerasEpochContextNotFoundForRound" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PerasRoundNo) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 String)))

resolveRoundNoPerasEpochContextResolver blk → PerasRoundNoEither PerasEpochContextNotFoundForRound (PerasEpochContext blk) Source #

Resolve a PerasRoundNo into its corresponding PerasEpochContext using a PerasEpochContextResolver.

Fails with PerasEpochContextNotFoundForRound if the round number is not within the bounds of either the current or previous epoch context, or if the resolver is in an error state.

perasEpochContextResolverBoundsPerasEpochContextResolver blk → (PerasRoundNo, PerasRoundNo) Source #

Compute the bounds of the Peras round numbers that are covered by the given PerasEpochContextResolver.

NOTE: the upper bound is exclusive, thus we return an empty range [0,0) when the resolver doesn't cover any Peras round.

newtype PerasEpochContextResolverHandle (m ∷ TypeType) blk Source #

A handle to a PerasEpochContextResolver that can be used in STM to resolve round numbers into their corresponding PerasEpochContexts.

mockPerasEpochContextResolverHandle(IOLike m, NoThunks (PerasEpochContext blk))PerasEpochContext blk → m (PerasEpochContextResolverHandle m blk) Source #

A mocked PerasEpochContextResolverHandle that always succeeds by resolving every round number to a fixed given (fixed) PerasEpochContext.

withResolvedRoundNo ∷ ∀ (m ∷ TypeType) err blk a. (MonadSTM m, MonadThrow (STM m), Exception err)PerasEpochContextResolverHandle m blk → PerasRoundNo → (PerasEpochContext blk → Either err a) → STM m a Source #

Helper to resolve the epoch context for a given round a pass it to a continuation for further processing.

NOTE: this function will throw an STM exception if round number cannot be resolved, or if the continuation fails.

Extracting and resolving Peras epoch contexts from the node state

class (HasHardForkHistory blk, LedgerStateSupportsPeras (LedgerState blk), LedgerStateSupportsPeras (Ticked LedgerState blk), ChainDepStateSupportsPeras (ChainDepState (BlockProtocol blk)), ChainDepStateSupportsPeras (Ticked (ChainDepState (BlockProtocol blk))), IsPerasError (PerasError blk) blk, Show (PerasError blk), Show (PerasVotingCommittee blk), Eq (PerasVotingCommittee blk), NoThunks (PerasVotingCommittee blk), Typeable (PerasVotingCommittee blk), FromCBOR (PerasVotingCommittee blk), ToCBOR (PerasVotingCommittee blk), Show (PerasEpochContextResolver blk), Eq (PerasEpochContextResolver blk), NoThunks (PerasEpochContextResolver blk), Typeable (PerasEpochContextResolver blk), FromCBOR (PerasEpochContextResolver blk), ToCBOR (PerasEpochContextResolver blk), EncodeDisk blk (PerasEpochContextResolver blk), DecodeDisk blk (PerasEpochContextResolver blk))StateSupportsPerasEpochContext blk where Source #

Type-class for blocks that support constructing a Peras epoch contexts from their corresponding ledger and chain-dep states.

Associated Types

type MaybeEraIndexedEpochToPerasRoundInfo blk Source #

Epoch-dependent information needed to resolve a PerasRoundNo into its corresponding PerasEpochContext. In practice, this is always an EpochToPerasRoundInfo, with the exception of the HardForkBlock, which additionally takes advantage of the era index returned by runQueryEraIndexed to be able to dispatch to the correct era-specific implementation.

Instances

Instances details
CanHardFork xs ⇒ StateSupportsPerasEpochContext (HardForkBlock xs) Source # 
Instance details

Defined in Ouroboros.Consensus.HardFork.Combinator.Ledger

(Bridge m a, Typeable m, Typeable a, ChainDepStateSupportsPeras (ChainDepState (BlockProtocol m)), ChainDepStateSupportsPeras (Ticked (ChainDepState (BlockProtocol m))))StateSupportsPerasEpochContext (DualBlock m a) Source # 
Instance details

Defined in Ouroboros.Consensus.Ledger.Dual

mkBoundedPerasEpochContextWith(LedgerStateSupportsPeras ledgerState, ChainDepStateSupportsPeras chainDepState, CryptoSupportsVotingCommittee (PerasCrypto blk) (PerasVotingCommitteeScheme blk), MaybeEraIndexedEpochToPerasRoundInfo blk ~ EpochToPerasRoundInfo, IsPerasError (PerasError blk) blk) ⇒ ((LedgerStateSupportsPeras ledgerState, ChainDepStateSupportsPeras chainDepState) ⇒ ledgerState EmptyMK → chainDepState → Either (PerasError blk) (PerasVotingCommitteeInput blk)) → MaybeEraIndexedEpochToPerasRoundInfo blk → ledgerState EmptyMK → chainDepState → Either (PerasError blk) (BoundedPerasEpochContext blk) Source #

Helper to build a BoundedPerasEpochContext using a function that produces a PerasVotingCommitteeInput from a ledger and chain-dep state.

NOTE: this is useful to define instances for StateSupportsPerasEpochContext where mkBoundedPerasEpochContext is instantiated to either: * mkBoundedPerasEpochContextWith mkMockPerasVotingCommitteeInput for test types with limited Peras support, and * mkBoundedPerasEpochContextWith V1.mkPerasVotingCommitteeInput for production types.

initPerasEpochContextResolver(All (TopTypeConstraint) (HardForkIndices blk), StateSupportsPerasEpochContext blk)LedgerConfig blk → LedgerState blk EmptyMKHeaderState blk → PerasEpochContextResolver blk Source #

Initialize a PerasEpochContextResolver from a ledger and header state.

NOTES: 1. We may later decide that a PerasEpochContextResolver is always initiated with empty/error value, and rely on the first ticking to properly initialize it. In the current architecture, however, that would work only if the first ticking happens when the previous slot is either Origin, or a slot from a previous epoch compared to the target slot. 2. Given that we have no assumption that (1) would work, we made a polymorphic system where a BoundedEpochContext can be created from either a ticked or unticked ledger+header state (see LedgerStateSupportsPeras and ChainDepStateSupportsPeras helper classes). This way, a PerasEpochContextResolver can be initialized from unticked LedgerState and HeaderState, but then ticked by using the 'Ticked LedgerState' and 'Ticked HeaderState'. 3. If in the future we move on to a system where the resolver is always initialized with empty/error value, we can remove the polymorphic system and only create a BoundedPerasEpochContext from 'Ticked LedgerState' and 'Ticked HeaderState'.

tickPerasEpochContextResolver Source #

Arguments

(All (TopTypeConstraint) (HardForkIndices blk), StateSupportsPerasEpochContext blk) 
LedgerConfig blk 
→ (PerasEpochContextResolver blk, LedgerState blk EmptyMK, HeaderState blk)

The fields needed from the previous ExtLedgerState (before ticking)

→ (SlotNo, Ticked LedgerState blk EmptyMK, Ticked (HeaderState blk))

Target SlotNo and fields of the 'Ticked ExtLedgerState' ticked to it

PerasEpochContextResolver blk 

Tick a PerasEpochContextResolver to a target SlotNo.

NOTES: 1. To avoid circular dependencies, this function uses a deconstructed ExtLedgerState instead of the ExtLedgerState itself. 2. It doesn't seem to bring much to differentiate a PerasEpochContextResolver from a ticked one at type level, since they need to carry exactly the same information. We tried, and it didn't improve readability.

Time resolution

data TimeResolutionContext blk where Source #

Data needed to run time-dependent queries.

NOTE: this is existential on the MapKind of the ledger state, as we really don't care about it for the purpose of time resolution.

Constructors

TimeResolutionContext ∷ ∀ blk (mk ∷ MapKind). LedgerConfig blk → LedgerState blk mk → TimeResolutionContext blk 

newtype TimeResolutionContextHandle (m ∷ TypeType) blk Source #

A handle to an STM action that returns a TimeResolutionContext.

runQueryWithContextHandle ∷ ∀ blk (m ∷ TypeType) a. (HasHardForkHistory blk, MonadSTM m)TimeResolutionContextHandle m blk → Qry a → STM m (Either PastHorizonException a) Source #

Helper to run a time-dependent query using a TimeResolutionContextHandle.

Next-epoch detection

data EpochCrossing a Source #

The outcome of comparing the epoch of a previous slot with the epoch of a target slot when ticking the ledger, discriminated by how many epoch boundaries were crossed. This drives how the Peras epoch-context resolver is updated.

Constructors

SameEpoch

The target slot is in the same epoch as the previous slot: no epoch boundary was crossed.

NextEpoch !a

Exactly one epoch boundary was crossed. The resolver can be advanced incrementally (the current context becomes the previous one).

ManyEpochsCrossed !a

More than one epoch boundary was crossed at once, i.e. the chain skipped one or more entire epochs. This is only possible for a sparse/empty chain, or when ticking the ledger far ahead of its tip. The two-epoch window cannot be advanced incrementally across the gap, so the resolver must be re-initialised at the target epoch instead.

Instances

Instances details
Functor EpochCrossing Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Methods

fmap ∷ (a → b) → EpochCrossing a → EpochCrossing b #

(<$) ∷ a → EpochCrossing b → EpochCrossing a #

Foldable EpochCrossing Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Methods

foldMonoid m ⇒ EpochCrossing m → m #

foldMapMonoid m ⇒ (a → m) → EpochCrossing a → m #

foldMap'Monoid m ⇒ (a → m) → EpochCrossing a → m #

foldr ∷ (a → b → b) → b → EpochCrossing a → b #

foldr' ∷ (a → b → b) → b → EpochCrossing a → b #

foldl ∷ (b → a → b) → b → EpochCrossing a → b #

foldl' ∷ (b → a → b) → b → EpochCrossing a → b #

foldr1 ∷ (a → a → a) → EpochCrossing a → a #

foldl1 ∷ (a → a → a) → EpochCrossing a → a #

toListEpochCrossing a → [a] #

nullEpochCrossing a → Bool #

lengthEpochCrossing a → Int #

elemEq a ⇒ a → EpochCrossing a → Bool #

maximumOrd a ⇒ EpochCrossing a → a #

minimumOrd a ⇒ EpochCrossing a → a #

sumNum a ⇒ EpochCrossing a → a #

productNum a ⇒ EpochCrossing a → a #

Traversable EpochCrossing Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

Methods

traverseApplicative f ⇒ (a → f b) → EpochCrossing a → f (EpochCrossing b) #

sequenceAApplicative f ⇒ EpochCrossing (f a) → f (EpochCrossing a) #

mapMMonad m ⇒ (a → m b) → EpochCrossing a → m (EpochCrossing b) #

sequenceMonad m ⇒ EpochCrossing (m a) → m (EpochCrossing a) #

Show a ⇒ Show (EpochCrossing a) Source # 
Instance details

Defined in Ouroboros.Consensus.Peras.Context

data DetectNextEpochError Source #

Errors that can occur when detecting whether a target slot is in the next epoch compared to a previous slot.

isNextEpochHasHardForkHistory blk ⇒ TimeResolutionContext blk → WithOrigin SlotNoSlotNoEither DetectNextEpochError (EpochCrossing (EraIndexed (HardForkIndices blk) (PerasEnabled EpochToPerasRoundInfo))) Source #

Determine whether a target slot is in the next epoch compared to a previous slot, and if so, how many epoch boundaries were crossed.