ouroboros-consensus
Safe HaskellNone
LanguageHaskell2010

Test.Ouroboros.Storage.ChainDB.Model

Description

Model implementation of the chain DB

Intended for qualified import

Synopsis

Documentation

data Model blk Source #

Model of the chain DB

Instances

Instances details
Generic (Model blk) Source # 
Instance details

Defined in Test.Ouroboros.Storage.ChainDB.Model

Associated Types

type Rep (Model blk) 
Instance details

Defined in Test.Ouroboros.Storage.ChainDB.Model

type Rep (Model blk)

Methods

from ∷ Model blk → Rep (Model blk) x #

to ∷ Rep (Model blk) x → Model blk #

(LedgerSupportsProtocol blk, BlockSupportsPeras blk, Show (PerasEpochContextResolver blk), Show blk) ⇒ Show (Model blk) Source # 
Instance details

Defined in Test.Ouroboros.Storage.ChainDB.Model

Methods

showsPrec ∷ Int → Model blk → ShowS #

show ∷ Model blk → String #

showList ∷ [Model blk] → ShowS #

(ToExpr blk, ToExpr (HeaderHash blk), ToExpr (ChainDepState (BlockProtocol blk)), ToExpr (TipInfo blk), ToExpr (LedgerState blk EmptyMK), ToExpr (ExtValidationError blk), ToExpr (Chain blk), ToExpr (ChainProducerState blk), ToExpr (ExtLedgerState blk EmptyMK), Show (PerasCert blk), Show (PerasVote blk), StandardHash blk, Show blk) ⇒ ToExpr (Model blk) Source # 
Instance details

Defined in Test.Ouroboros.Storage.ChainDB.Model

Methods

toExpr ∷ Model blk → Expr Source #

listToExpr ∷ [Model blk] → Expr Source #

type Rep (Model blk) Source # 
Instance details

Defined in Test.Ouroboros.Storage.ChainDB.Model

type Rep (Model blk)

Construction

empty ∷ HasHeader blk ⇒ LoE () → ExtLedgerState blk EmptyMK → Model blk Source #

Queries

currentChain ∷ Model blk → Chain blk Source #

getBlock ∷ HasHeader blk ⇒ HeaderHash blk → Model blk → Maybe blk Source #

getBlockByPoint ∷ HasHeader blk ⇒ RealPoint blk → Model blk → Maybe blk Source #

getLoEFragment ∷ Model blk → LoE (AnchoredFragment blk) Source #

getMaxSlotNo ∷ HasHeader blk ⇒ Model blk → MaxSlotNo Source #

hasBlock ∷ HasHeader blk ⇒ HeaderHash blk → Model blk → Bool Source #

hasBlockByPoint ∷ HasHeader blk ⇒ Point blk → Model blk → Bool Source #

immutableBlockNo ∷ (HasHeader blk, IsPerasCert (PerasCert blk) blk) ⇒ SecurityParam → Model blk → WithOrigin BlockNo Source #

The block number of the most recent "immutable" block, i.e. the oldest block we can roll back to. We cannot roll back the block itself.

Note that this is not necessarily the block at the tip of the ImmutableDB, because the background thread copying blocks to the ImmutableDB might not have caught up.

immutableChain ∷ (HasHeader blk, IsPerasCert (PerasCert blk) blk) ⇒ SecurityParam → Model blk → Chain blk Source #

Return the immutable prefix of the current chain.

This is the longest of the given two chains:

  1. The current chain with the longest suffix of weight at most k dropped.
  2. The chain formed by the blocks in immutableDbChain, i.e., the "ImmutableDB". We need to take this case in consideration because the VolatileDB might have been wiped.

We need this because we do not allow rolling back more than weight k, but the background thread copying blocks from the VolatileDB to the ImmutableDB might not have caught up yet. This means we cannot use the tip of the ImmutableDB to know the most recent "immutable" block.

immutableSlotNo ∷ (HasHeader blk, IsPerasCert (PerasCert blk) blk) ⇒ SecurityParam → Model blk → WithOrigin SlotNo Source #

The slot number of the most recent "immutable" block (see immutableBlockNo).

This is used for garbage collection of the VolatileDB, which is done in terms of slot numbers, not in terms of block numbers.

invalid ∷ Model blk → InvalidBlocks blk Source #

isOpen ∷ Model blk → Bool Source #

While the model tracks whether it is closed or not, the queries and other functions in this module ignore this for simplicity. The mock ChainDB that wraps this model will throw a ClosedDBError whenever it is used while closed.

tipBlock ∷ Model blk → Maybe blk Source #

tipPoint ∷ HasHeader blk ⇒ Model blk → Point blk Source #

volatileChain Source #

Arguments

∷ (HasHeader a, HasHeader blk, IsPerasCert (PerasCert blk) blk) 
⇒ SecurityParam 
→ (blk → a)

Provided since AnchoredFragment is not a functor

→ Model blk 
→ AnchoredFragment a 

Return the volatile suffix of the current chain.

The opposite of immutableChain.

This is the shortest of the given two chain fragments:

  1. The longest suffix of the current chain with weight at most k.
  2. The suffix of the current chain not part of the immutableDbChain, i.e., the "ImmutableDB".

Iterators

Followers

followerForward ∷ HasHeader blk ⇒ FollowerId → [Point blk] → Model blk → Either (ChainDbError blk) (Maybe (Point blk), Model blk) Source #

newFollower ∷ HasHeader blk ⇒ Model blk → (FollowerId, Model blk) Source #

ModelSupportsBlock

class (HasHeader blk, GetHeader blk, HasHeader (Header blk), Serialise blk, Serialise (Header blk), HasNestedContent Header blk) ⇒ ModelSupportsBlock blk Source #

Functionality the block needs to support so that it can be used in the Model.

Instances

Instances details
ModelSupportsBlock TestBlock Source # 
Instance details

Defined in Test.Ouroboros.Storage.ChainDB.StateMachine

ModelSupportsBlock TestBlock Source # 
Instance details

Defined in Test.Ouroboros.Storage.ChainDB.Model.Test

Exported for testing purposes

between ∷ (GetPrevHash blk, IsPerasCert (PerasCert blk) blk) ⇒ SecurityParam → StreamFrom blk → StreamTo blk → Model blk → Either (UnknownRange blk) [blk] Source #

blocks ∷ HasHeader blk ⇒ Model blk → Map (HeaderHash blk) blk Source #

chains ∷ GetPrevHash blk ⇒ Map (HeaderHash blk) blk → [Chain blk] Source #

closeDB ∷ Model blk → Model blk Source #

copyToImmutableDB ∷ (HasHeader blk, IsPerasCert (PerasCert blk) blk) ⇒ SecurityParam → ShouldGarbageCollect → Model blk → Model blk Source #

Copy all blocks on the current chain older than k to the "mock ImmutableDB" (immutableDbChain).

The ShouldGarbageCollect parameter determines if garbage collection should be performed after copying.

Idempotent.

garbageCollectable ∷ (HasHeader blk, IsPerasCert (PerasCert blk) blk) ⇒ SecurityParam → Model blk → blk → Bool Source #

Should the given block be garbage collected from the VolatileDB?

Blocks can be garbage collected when their slot number is older than the slot number of the immutable block (the block k blocks after the current tip).

garbageCollectableIteratorNext ∷ (ModelSupportsBlock blk, IsPerasCert (PerasCert blk) blk) ⇒ SecurityParam → Model blk → IteratorId → Bool Source #

Return True when the next block the given iterator would produced is eligible for garbage collection, i.e. the real implementation might have garbage collected it.

garbageCollectablePoint ∷ (HasHeader blk, IsPerasCert (PerasCert blk) blk) ⇒ SecurityParam → Model blk → RealPoint blk → Bool Source #

Return True when the model contains the block corresponding to the point and the block itself is eligible for garbage collection, i.e. the real implementation might have garbage collected it.

If the block is not in the model, return True, as it has likely been garbage-collected from the model too. Note that we cannot distinguish this case from a block that was never added to the model in the first place.

getFragmentBetween Source #

Arguments

∷ GetPrevHash blk 
⇒ Map (HeaderHash blk) blk

A map of blocks; usually the volatileDbBlocks of a Model.

→ Anchor blk

The anchor of the fragment to get.

→ ChainHash blk

The hash of the block to get the fragment up to.

→ Maybe (AnchoredFragment blk) 

Look in the given blocks database for a fragment spanning from the given anchor to the given hash, and return the fragment in question, or Nothing.

immutableDbChain ∷ Model blk → Chain blk Source #

The ImmutableDB

reopen ∷ Model blk → Model blk Source #

updateLoE ∷ (All (Top ∷ Type → Constraint) (HardForkIndices blk), LedgerTablesAreTrivial ExtLedgerState blk, LedgerSupportsProtocol blk, BlockSupportsPeras blk, StateSupportsPerasEpochContext blk) ⇒ TopLevelConfig blk → AnchoredFragment blk → Model blk → (Point blk, Model blk) Source #

Update the LoE fragment, trigger chain selection and return the new tip point.

volatileDbBlocks ∷ Model blk → Map (HeaderHash blk) blk Source #

The VolatileDB