storage-test
Safe HaskellSafe-Inferred
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) ∷ TypeType #

Methods

fromModel blk → Rep (Model blk) x #

toRep (Model blk) x → Model blk #

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

Defined in Test.Ouroboros.Storage.ChainDB.Model

Methods

showsPrecIntModel blk → ShowS #

showModel blk → String #

showList ∷ [Model blk] → ShowS #

(ToExpr blk, ToExpr (HeaderHash blk), ToExpr (ChainDepState (BlockProtocol blk)), ToExpr (TipInfo blk), ToExpr (LedgerState blk), ToExpr (ExtValidationError blk), ToExpr (Chain blk), ToExpr (ChainProducerState blk), ToExpr (ExtLedgerState blk), ToExpr (InvalidBlockReason blk)) ⇒ ToExpr (Model blk) Source # 
Instance details

Defined in Test.Ouroboros.Storage.ChainDB.Model

Methods

toExprModel 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

addBlock ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → blk → Model blk → Model blk Source #

addBlockPromise ∷ ∀ m blk. (LedgerSupportsProtocol blk, MonadSTM m) ⇒ TopLevelConfig blk → blk → Model blk → (AddBlockPromise m blk, Model blk) Source #

Wrapper around addBlock that returns an AddBlockPromise.

addBlocksLedgerSupportsProtocol blk ⇒ TopLevelConfig blk → [blk] → Model blk → Model blk Source #

empty Source #

Arguments

ExtLedgerState blk 
Word64

Max clock skew in number of blocks

Model blk 

Queries

currentChainModel blk → Chain blk Source #

futureBlocksHasHeader blk ⇒ Model blk → Map (HeaderHash blk) blk Source #

getBlockHasHeader blk ⇒ HeaderHash blk → Model blk → Maybe blk Source #

getBlockByPointHasHeader blk ⇒ RealPoint blk → Model blk → Maybe blk Source #

getIsValid ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ Model blk → RealPoint blk → Maybe Bool Source #

hasBlockHasHeader blk ⇒ HeaderHash blk → Model blk → Bool Source #

hasBlockByPointHasHeader blk ⇒ Point blk → Model blk → Bool Source #

immutableBlockNoHasHeader blk ⇒ SecurityParamModel 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.

immutableChainSecurityParamModel 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 last k blocks 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 k blocks, 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.

immutableSlotNoHasHeader blk ⇒ SecurityParamModel 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.

invalidModel blk → InvalidBlocks blk Source #

isOpenModel 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.

isValid ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ RealPoint blk → Model blk → Maybe Bool Source #

lastK Source #

Arguments

HasHeader a 
SecurityParam 
→ (blk → a)

Provided since AnchoredFragment is not a functor

Model blk 
AnchoredFragment a 

maxClockSkewModel blk → Word64 Source #

Max clock skew in terms of slots. A static configuration parameter.

tipBlockModel blk → Maybe blk Source #

tipPointHasHeader blk ⇒ Model blk → Point blk Source #

volatileChain Source #

Arguments

∷ (HasHeader a, HasHeader 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 last k blocks of the current chain.
  2. The suffix of the current chain not part of the immutableDbChain, i.e., the "ImmutableDB".

Iterators

Followers

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

followerInstruction ∷ ∀ blk b. ModelSupportsBlock blk ⇒ FollowerIdBlockComponent blk b → Model blk → Either (ChainDbError blk) (Maybe (ChainUpdate blk b), Model blk) Source #

newFollowerHasHeader 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.

Exported for testing purposes

advanceCurSlot Source #

Arguments

SlotNo

The new current slot

Model blk 
Model blk 

Advance the currentSlot of the model to the given SlotNo if the current slot of the model < the given SlotNo.

between ∷ ∀ blk. GetPrevHash blk ⇒ SecurityParamStreamFrom blk → StreamTo blk → Model blk → Either (UnknownRange blk) [blk] Source #

blocksHasHeader blk ⇒ Model blk → Map (HeaderHash blk) blk Source #

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

closeDBModel blk → Model blk Source #

copyToImmutableDB ∷ ∀ blk. HasHeader blk ⇒ SecurityParamShouldGarbageCollectModel 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 ∷ ∀ blk. HasHeader blk ⇒ SecurityParamModel 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 ∷ ∀ blk. ModelSupportsBlock blk ⇒ SecurityParamModel blk → IteratorIdBool 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 ∷ ∀ blk. HasHeader blk ⇒ SecurityParamModel 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.

immutableDbChainModel blk → Chain blk Source #

The ImmutableDB

reopenModel blk → Model blk Source #

validChains ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → Model blk → Map (HeaderHash blk) blk → (InvalidBlocks blk, [(Chain blk, ExtLedgerState blk)]) Source #

volatileDbBlocksModel blk → Map (HeaderHash blk) blk Source #

The VolatileDB

wipeVolatileDB ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → Model blk → (Point blk, Model blk) Source #