Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Main tests for the chain DB.
These are the main tests for the chain DB. Commands include
- Add a block
- Add a block with a
SlotNo
that is ahead of the wall-clock. - Get the current chain and/or ledger state
- Create a new iterator and use it to stream blocks
- Create a new follower and use it to follow the chain
- (Limited) disk corruption (the chain DB relies on the immutable DB and volatile DB for the storage proper and they have extensive disk corruption tests, so we don't need to repeat that here).
Synopsis
- newtype At t blk m r = At {
- unAt ∷ t blk (IterRef blk m r) (FollowerRef blk m r)
- data Cmd blk it flr
- = AddBlock blk
- | GetCurrentChain
- | GetLedgerDB
- | GetTipBlock
- | GetTipHeader
- | GetTipPoint
- | GetBlockComponent (RealPoint blk)
- | GetGCedBlockComponent (RealPoint blk)
- | GetMaxSlotNo
- | GetIsValid (RealPoint blk)
- | Stream (StreamFrom blk) (StreamTo blk)
- | UpdateLoE (AnchoredFragment blk)
- | IteratorNext it
- | IteratorNextGCed it
- | IteratorClose it
- | NewFollower ChainType
- | FollowerInstruction flr
- | FollowerForward flr [Point blk]
- | FollowerClose flr
- | Close
- | Reopen
- | PersistBlks
- | PersistBlksThenGC
- | UpdateLedgerSnapshots
- | WipeVolatileDB
- type FollowerRef blk m r = Reference (Opaque (TestFollower m blk)) r
- type IterRef blk m r = Reference (Opaque (TestIterator m blk)) r
- data IteratorResult blk b
- = IteratorExhausted
- | IteratorResult b
- | IteratorBlockGCed (RealPoint blk)
- data IteratorResultGCed blk = IteratorResultGCed {
- real ∷ Bool
- iterResult ∷ IteratorResult blk (AllComponents blk)
- newtype Resp blk it flr = Resp {
- getResp ∷ Either (ChainDbError blk) (Success blk it flr)
- data Success blk it flr
- = Unit ()
- | Chain (AnchoredFragment (Header blk))
- | LedgerDB (LedgerDB (ExtLedgerState blk))
- | MbBlock (Maybe blk)
- | MbAllComponents (Maybe (AllComponents blk))
- | MbGCedAllComponents (MaybeGCedBlock (AllComponents blk))
- | MbHeader (Maybe (Header blk))
- | Point (Point blk)
- | IsValid IsValidResult
- | UnknownRange (UnknownRange blk)
- | Iter it
- | IterResult (IteratorResult blk (AllComponents blk))
- | IterResultGCed (IteratorResultGCed blk)
- | Flr flr
- | MbChainUpdate (Maybe (ChainUpdate blk (AllComponents blk)))
- | MbPoint (Maybe (Point blk))
- | MaxSlot MaxSlotNo
- data Model blk m r
- data ShouldGarbageCollect
- runCmdsLockstep ∷ LoE () → SmallChunkInfo → Commands (At Cmd Blk IO) (At Resp Blk IO) → Property
- data ChainDBEnv m blk = ChainDBEnv {
- varDB ∷ StrictTVar m (ChainDBState m blk)
- registry ∷ ResourceRegistry m
- varCurSlot ∷ StrictTVar m SlotNo
- varNextId ∷ StrictTVar m Id
- varVolatileDbFs ∷ StrictTMVar m MockFS
- args ∷ ChainDbArgs Identity m blk
- varLoEFragment ∷ StrictTVar m (AnchoredFragment (Header blk))
- data ChainDBState m blk = ChainDBState {}
- close ∷ IOLike m ⇒ ChainDBState m blk → m ()
- mkTestCfg ∷ ChunkInfo → TopLevelConfig TestBlock
- open ∷ (IOLike m, TestConstraints blk) ⇒ ChainDbArgs Identity m blk → m (ChainDBState m blk)
- persistBlks ∷ IOLike m ⇒ ShouldGarbageCollect → Internal m blk → m ()
- type AllComponents blk = (blk, blk, Header blk, ByteString, ByteString, HeaderHash blk, SlotNo, IsEBB, SizeInBytes, Word16, SomeSecond (NestedCtxt Header) blk)
- allComponents ∷ BlockComponent blk (AllComponents blk)
- type TestConstraints blk = (ConsensusProtocol (BlockProtocol blk), LedgerSupportsProtocol blk, BlockSupportsDiffusionPipelining blk, InspectLedger blk, Eq (ChainDepState (BlockProtocol blk)), Eq (LedgerState blk), Eq blk, Show blk, HasHeader blk, StandardHash blk, Serialise blk, ModelSupportsBlock blk, Eq (Header blk), Show (Header blk), ConvertRawHash blk, HasHardForkHistory blk, SerialiseDiskConstraints blk)
- traceEventName ∷ TraceEvent blk → String
- tests ∷ TestTree
Commands
Instantiate functor t blk
to
t blk (
.IterRef
blk m r) (FollowerRef
blk m r)
Needed because we need to (partially) apply
to At
t blk flr mr
.
At | |
|
Instances
Bifoldable (t blk) ⇒ Foldable (At t blk m ∷ (Type → Type) → Type) Source # | |
Bifunctor (t blk) ⇒ Functor (At t blk m ∷ (Type → Type) → Type) Source # | |
Bitraversable (t blk) ⇒ Traversable (At t blk m ∷ (Type → Type) → Type) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine | |
CommandNames (At Cmd blk m ∷ (Type → Type) → Type) Source # | |
Generic (At t blk m r) Source # | |
Show (t blk (IterRef blk m r) (FollowerRef blk m r)) ⇒ Show (At t blk m r) Source # | |
(TestConstraints blk, Eq1 r) ⇒ Eq (At Resp blk m r) Source # | |
type Rep (At t blk m r) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine type Rep (At t blk m r) = D1 ('MetaData "At" "Test.Ouroboros.Storage.ChainDB.StateMachine" "ouroboros-consensus-0.21.0.0-inplace-storage-test" 'True) (C1 ('MetaCons "At" 'PrefixI 'True) (S1 ('MetaSel ('Just "unAt") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (t blk (IterRef blk m r) (FollowerRef blk m r))))) |
Commands
AddBlock blk | Advance the current slot to the block's slot (unless smaller than the current slot), add the block and run chain selection. |
GetCurrentChain | |
GetLedgerDB | |
GetTipBlock | |
GetTipHeader | |
GetTipPoint | |
GetBlockComponent (RealPoint blk) | |
GetGCedBlockComponent (RealPoint blk) | Only for blocks that may have been garbage collected. |
GetMaxSlotNo | |
GetIsValid (RealPoint blk) | |
Stream (StreamFrom blk) (StreamTo blk) | |
UpdateLoE (AnchoredFragment blk) | Update the LoE fragment and run chain selection. |
IteratorNext it | |
IteratorNextGCed it | Only for blocks that may have been garbage collected. |
IteratorClose it | |
NewFollower ChainType | |
FollowerInstruction flr |
|
FollowerForward flr [Point blk] | |
FollowerClose flr | |
Close | |
Reopen | |
PersistBlks | Copy the blocks older than |
PersistBlksThenGC | Copy the blocks older than The garbage collection procedure of the Chain DB (our system under test)
removes the blocks from the volatile DB without caring about whether
the removed blocks were persisted. Therefore, this part of the Chain DB
logic assumes that copy to the immutable DB took place before
garbage collection. The model uses this assumption as well. As a result,
we cannot perform garbage collection in isolation, since this will break
the model's |
UpdateLedgerSnapshots | Write a new |
WipeVolatileDB |
Instances
type FollowerRef blk m r = Reference (Opaque (TestFollower m blk)) r Source #
Concrete or symbolic references to a real follower
type IterRef blk m r = Reference (Opaque (TestIterator m blk)) r Source #
Concrete or symbolic references to a real iterator
data IteratorResult blk b Source #
IteratorExhausted | |
IteratorResult b | |
IteratorBlockGCed (RealPoint blk) | The block that was supposed to be streamed was garbage-collected from the VolatileDB, but not added to the ImmutableDB. This will only happen when streaming very old forks very slowly. The following example illustrates a situation in which an iterator result
could be a iterator i ↓ ... ⟶ [[ a ]] → [[ b ]] → [ c ] -> [ d ] ──────────────────────╯ ╰────────────╯ Immutable DB Current chain Suppose we switch to a longer fork that branches off from the immutable tip ('[[b]]'). iterator i ↓ ... ⟶ [[ a ]] → [[ b ]] → [ c ] -> [ d ] ──────────────────────╯│ Immutable DB │ ╰-→ [ e ] -> [ f ] -> [ g ] ╰─────────────────────╯ Current chain Assume |
Instances
data IteratorResultGCed blk Source #
Similar to MaybeGCedBlock
, but for the block returned by
iteratorNext
. A garbage-collected block could result in
IteratorBlockGCed
instead of IteratorResult
.
IteratorResultGCed | |
|
Instances
(Show blk, Show (Header blk), StandardHash blk, HasNestedContent Header blk) ⇒ Show (IteratorResultGCed blk) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine showsPrec ∷ Int → IteratorResultGCed blk → ShowS # show ∷ IteratorResultGCed blk → String # showList ∷ [IteratorResultGCed blk] → ShowS # | |
(Eq blk, Eq (Header blk), StandardHash blk, HasNestedContent Header blk) ⇒ Eq (IteratorResultGCed blk) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine (==) ∷ IteratorResultGCed blk → IteratorResultGCed blk → Bool # (/=) ∷ IteratorResultGCed blk → IteratorResultGCed blk → Bool # |
Responses
newtype Resp blk it flr Source #
Responses are either successful termination or an error.
Resp | |
|
Instances
Bifoldable (Resp blk) Source # | |
Bifunctor (Resp blk) Source # | |
Bitraversable (Resp blk) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine bitraverse ∷ Applicative f ⇒ (a → f c) → (b → f d) → Resp blk a b → f (Resp blk c d) # | |
Foldable (Resp blk it) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine fold ∷ Monoid m ⇒ Resp blk it m → m # foldMap ∷ Monoid m ⇒ (a → m) → Resp blk it a → m # foldMap' ∷ Monoid m ⇒ (a → m) → Resp blk it a → m # foldr ∷ (a → b → b) → b → Resp blk it a → b # foldr' ∷ (a → b → b) → b → Resp blk it a → b # foldl ∷ (b → a → b) → b → Resp blk it a → b # foldl' ∷ (b → a → b) → b → Resp blk it a → b # foldr1 ∷ (a → a → a) → Resp blk it a → a # foldl1 ∷ (a → a → a) → Resp blk it a → a # toList ∷ Resp blk it a → [a] # length ∷ Resp blk it a → Int # elem ∷ Eq a ⇒ a → Resp blk it a → Bool # maximum ∷ Ord a ⇒ Resp blk it a → a # minimum ∷ Ord a ⇒ Resp blk it a → a # | |
Traversable (Resp blk it) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine | |
Functor (Resp blk it) Source # | |
(TestConstraints blk, Show it, Show flr) ⇒ Show (Resp blk it flr) Source # | |
(TestConstraints blk, Eq it, Eq flr) ⇒ Eq (Resp blk it flr) Source # | |
(TestConstraints blk, Eq1 r) ⇒ Eq (At Resp blk m r) Source # | |
data Success blk it flr Source #
Return type for successful database operations.
Unit () | |
Chain (AnchoredFragment (Header blk)) | |
LedgerDB (LedgerDB (ExtLedgerState blk)) | |
MbBlock (Maybe blk) | |
MbAllComponents (Maybe (AllComponents blk)) | |
MbGCedAllComponents (MaybeGCedBlock (AllComponents blk)) | |
MbHeader (Maybe (Header blk)) | |
Point (Point blk) | |
IsValid IsValidResult | |
UnknownRange (UnknownRange blk) | |
Iter it | |
IterResult (IteratorResult blk (AllComponents blk)) | |
IterResultGCed (IteratorResultGCed blk) | |
Flr flr | |
MbChainUpdate (Maybe (ChainUpdate blk (AllComponents blk))) | |
MbPoint (Maybe (Point blk)) | |
MaxSlot MaxSlotNo |
Instances
Bifoldable (Success blk) Source # | |
Bifunctor (Success blk) Source # | |
Bitraversable (Success blk) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine bitraverse ∷ Applicative f ⇒ (a → f c) → (b → f d) → Success blk a b → f (Success blk c d) # | |
Foldable (Success blk it) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine fold ∷ Monoid m ⇒ Success blk it m → m # foldMap ∷ Monoid m ⇒ (a → m) → Success blk it a → m # foldMap' ∷ Monoid m ⇒ (a → m) → Success blk it a → m # foldr ∷ (a → b → b) → b → Success blk it a → b # foldr' ∷ (a → b → b) → b → Success blk it a → b # foldl ∷ (b → a → b) → b → Success blk it a → b # foldl' ∷ (b → a → b) → b → Success blk it a → b # foldr1 ∷ (a → a → a) → Success blk it a → a # foldl1 ∷ (a → a → a) → Success blk it a → a # toList ∷ Success blk it a → [a] # null ∷ Success blk it a → Bool # length ∷ Success blk it a → Int # elem ∷ Eq a ⇒ a → Success blk it a → Bool # maximum ∷ Ord a ⇒ Success blk it a → a # minimum ∷ Ord a ⇒ Success blk it a → a # | |
Traversable (Success blk it) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine | |
Functor (Success blk it) Source # | |
(TestConstraints blk, Show it, Show flr) ⇒ Show (Success blk it flr) Source # | |
(TestConstraints blk, Eq it, Eq flr) ⇒ Eq (Success blk it flr) Source # | |
Model
Execution model
Instances
Generic (Model blk m r) Source # | |
(TestConstraints blk, Show1 r) ⇒ Show (Model blk m r) Source # | |
(ToExpr blk, ToExpr (HeaderHash blk), ToExpr (ChainDepState (BlockProtocol blk)), ToExpr (TipInfo blk), ToExpr (LedgerState blk), ToExpr (ExtValidationError blk)) ⇒ ToExpr (Model blk IO Concrete) Source # | |
type Rep (Model blk m r) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine |
data ShouldGarbageCollect Source #
Instances
Running the model
runCmdsLockstep ∷ LoE () → SmallChunkInfo → Commands (At Cmd Blk IO) (At Resp Blk IO) → Property Source #
System under test
data ChainDBEnv m blk Source #
Environment to run commands against the real ChainDB implementation.
ChainDBEnv | |
|
data ChainDBState m blk Source #
The current ChainDB instance and things related to it.
When closing and reopening the ChainDB, this record will be replaced in the
$sel:varDB:ChainDBEnv
field of ChainDBEnv
with a new one.
Instances
NoThunks (ChainDBState m blk) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.StateMachine |
close ∷ IOLike m ⇒ ChainDBState m blk → m () Source #
open ∷ (IOLike m, TestConstraints blk) ⇒ ChainDbArgs Identity m blk → m (ChainDBState m blk) Source #
persistBlks ∷ IOLike m ⇒ ShouldGarbageCollect → Internal m blk → m () Source #
Specifying block components
type AllComponents blk = (blk, blk, Header blk, ByteString, ByteString, HeaderHash blk, SlotNo, IsEBB, SizeInBytes, Word16, SomeSecond (NestedCtxt Header) blk) Source #
A list of all the BlockComponent
indices (b
) we are interested in.
allComponents ∷ BlockComponent blk (AllComponents blk) Source #
Product of all BlockComponent
s. As this is a GADT, generating random
values of it (and combinations!) is not so simple. Therefore, we just
always request all block components.
Constraints
type TestConstraints blk = (ConsensusProtocol (BlockProtocol blk), LedgerSupportsProtocol blk, BlockSupportsDiffusionPipelining blk, InspectLedger blk, Eq (ChainDepState (BlockProtocol blk)), Eq (LedgerState blk), Eq blk, Show blk, HasHeader blk, StandardHash blk, Serialise blk, ModelSupportsBlock blk, Eq (Header blk), Show (Header blk), ConvertRawHash blk, HasHardForkHistory blk, SerialiseDiskConstraints blk) Source #
Tracing
traceEventName ∷ TraceEvent blk → String Source #