Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Model implementation of the chain DB
Intended for qualified import
Synopsis
- data Model blk
- type FollowerId = Int
- type IteratorId = Int
- addBlock ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → blk → Model blk → Model blk
- addBlockPromise ∷ ∀ m blk. (LedgerSupportsProtocol blk, MonadSTM m) ⇒ TopLevelConfig blk → blk → Model blk → (AddBlockPromise m blk, Model blk)
- addBlocks ∷ LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → [blk] → Model blk → Model blk
- empty ∷ HasHeader blk ⇒ LoE () → ExtLedgerState blk → Model blk
- currentChain ∷ Model blk → Chain blk
- currentLedger ∷ Model blk → ExtLedgerState blk
- getBlock ∷ HasHeader blk ⇒ HeaderHash blk → Model blk → Maybe blk
- getBlockByPoint ∷ HasHeader blk ⇒ RealPoint blk → Model blk → Maybe blk
- getBlockComponentByPoint ∷ ModelSupportsBlock blk ⇒ BlockComponent blk b → RealPoint blk → Model blk → Either (ChainDbError blk) (Maybe b)
- getIsValid ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ Model blk → RealPoint blk → Maybe Bool
- getLedgerDB ∷ LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → Model blk → LedgerDB (ExtLedgerState blk)
- getLoEFragment ∷ Model blk → LoE (AnchoredFragment blk)
- getMaxSlotNo ∷ HasHeader blk ⇒ Model blk → MaxSlotNo
- hasBlock ∷ HasHeader blk ⇒ HeaderHash blk → Model blk → Bool
- hasBlockByPoint ∷ HasHeader blk ⇒ Point blk → Model blk → Bool
- immutableBlockNo ∷ HasHeader blk ⇒ SecurityParam → Model blk → WithOrigin BlockNo
- immutableChain ∷ SecurityParam → Model blk → Chain blk
- immutableSlotNo ∷ HasHeader blk ⇒ SecurityParam → Model blk → WithOrigin SlotNo
- invalid ∷ Model blk → InvalidBlocks blk
- isOpen ∷ Model blk → Bool
- isValid ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ RealPoint blk → Model blk → Maybe Bool
- lastK ∷ HasHeader a ⇒ SecurityParam → (blk → a) → Model blk → AnchoredFragment a
- tipBlock ∷ Model blk → Maybe blk
- tipPoint ∷ HasHeader blk ⇒ Model blk → Point blk
- volatileChain ∷ (HasHeader a, HasHeader blk) ⇒ SecurityParam → (blk → a) → Model blk → AnchoredFragment a
- iteratorClose ∷ IteratorId → Model blk → Model blk
- iteratorNext ∷ ModelSupportsBlock blk ⇒ IteratorId → BlockComponent blk b → Model blk → (IteratorResult blk b, Model blk)
- stream ∷ GetPrevHash blk ⇒ SecurityParam → StreamFrom blk → StreamTo blk → Model blk → Either (ChainDbError blk) (Either (UnknownRange blk) IteratorId, Model blk)
- followerClose ∷ FollowerId → Model blk → Model blk
- followerForward ∷ HasHeader blk ⇒ FollowerId → [Point blk] → Model blk → Either (ChainDbError blk) (Maybe (Point blk), Model blk)
- followerInstruction ∷ ∀ blk b. ModelSupportsBlock blk ⇒ FollowerId → BlockComponent blk b → Model blk → Either (ChainDbError blk) (Maybe (ChainUpdate blk b), Model blk)
- newFollower ∷ HasHeader blk ⇒ Model blk → (FollowerId, Model blk)
- class (HasHeader blk, GetHeader blk, HasHeader (Header blk), Serialise blk, Serialise (Header blk), HasNestedContent Header blk) ⇒ ModelSupportsBlock blk
- data ShouldGarbageCollect
- between ∷ ∀ blk. GetPrevHash blk ⇒ SecurityParam → StreamFrom blk → StreamTo blk → Model blk → Either (UnknownRange blk) [blk]
- blocks ∷ HasHeader blk ⇒ Model blk → Map (HeaderHash blk) blk
- chains ∷ ∀ blk. GetPrevHash blk ⇒ Map (HeaderHash blk) blk → [Chain blk]
- closeDB ∷ Model blk → Model blk
- copyToImmutableDB ∷ ∀ blk. HasHeader blk ⇒ SecurityParam → ShouldGarbageCollect → Model blk → Model blk
- garbageCollectable ∷ ∀ blk. HasHeader blk ⇒ SecurityParam → Model blk → blk → Bool
- garbageCollectableIteratorNext ∷ ∀ blk. ModelSupportsBlock blk ⇒ SecurityParam → Model blk → IteratorId → Bool
- garbageCollectablePoint ∷ ∀ blk. HasHeader blk ⇒ SecurityParam → Model blk → RealPoint blk → Bool
- getFragmentBetween ∷ ∀ blk. GetPrevHash blk ⇒ Map (HeaderHash blk) blk → Anchor blk → ChainHash blk → Maybe (AnchoredFragment blk)
- immutableDbChain ∷ Model blk → Chain blk
- initLedger ∷ Model blk → ExtLedgerState blk
- reopen ∷ Model blk → Model blk
- updateLoE ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → AnchoredFragment blk → Model blk → (Point blk, Model blk)
- validChains ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → Model blk → Map (HeaderHash blk) blk → (InvalidBlocks blk, [(Chain blk, ExtLedgerState blk)])
- volatileDbBlocks ∷ Model blk → Map (HeaderHash blk) blk
- wipeVolatileDB ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → Model blk → (Point blk, Model blk)
Documentation
Model of the chain DB
Instances
Generic (Model blk) Source # | |
(LedgerSupportsProtocol blk, Show blk) ⇒ Show (Model blk) Source # | |
(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 (Model blk) Source # | |
type Rep (Model blk) Source # | |
Defined in Test.Ouroboros.Storage.ChainDB.Model |
type FollowerId = Int Source #
type IteratorId = Int Source #
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
.
addBlocks ∷ LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → [blk] → Model blk → Model blk Source #
Queries
currentChain ∷ Model blk → Chain blk Source #
currentLedger ∷ Model blk → ExtLedgerState blk Source #
getBlockComponentByPoint ∷ ModelSupportsBlock blk ⇒ BlockComponent blk b → RealPoint blk → Model blk → Either (ChainDbError blk) (Maybe b) Source #
getIsValid ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ Model blk → RealPoint blk → Maybe Bool Source #
getLedgerDB ∷ LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → Model blk → LedgerDB (ExtLedgerState blk) Source #
getLoEFragment ∷ Model blk → LoE (AnchoredFragment blk) Source #
immutableBlockNo ∷ HasHeader 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 ∷ SecurityParam → Model blk → Chain blk Source #
Return the immutable prefix of the current chain.
This is the longest of the given two chains:
- The current chain with the last
k
blocks dropped. - 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.
immutableSlotNo ∷ HasHeader 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.
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.
∷ HasHeader a | |
⇒ SecurityParam | |
→ (blk → a) | Provided since |
→ Model blk | |
→ AnchoredFragment a |
∷ (HasHeader a, HasHeader blk) | |
⇒ SecurityParam | |
→ (blk → a) | Provided since |
→ 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:
- The last
k
blocks of the current chain. - The suffix of the current chain not part of the
immutableDbChain
, i.e., the "ImmutableDB".
Iterators
iteratorClose ∷ IteratorId → Model blk → Model blk Source #
iteratorNext ∷ ModelSupportsBlock blk ⇒ IteratorId → BlockComponent blk b → Model blk → (IteratorResult blk b, Model blk) Source #
stream ∷ GetPrevHash blk ⇒ SecurityParam → StreamFrom blk → StreamTo blk → Model blk → Either (ChainDbError blk) (Either (UnknownRange blk) IteratorId, Model blk) Source #
Followers
followerClose ∷ FollowerId → Model blk → Model blk Source #
followerForward ∷ HasHeader blk ⇒ FollowerId → [Point blk] → Model blk → Either (ChainDbError blk) (Maybe (Point blk), Model blk) Source #
followerInstruction ∷ ∀ blk b. ModelSupportsBlock blk ⇒ FollowerId → BlockComponent blk b → Model blk → Either (ChainDbError blk) (Maybe (ChainUpdate blk b), 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
Exported for testing purposes
data ShouldGarbageCollect Source #
Instances
between ∷ ∀ blk. GetPrevHash blk ⇒ SecurityParam → StreamFrom blk → StreamTo blk → Model blk → Either (UnknownRange blk) [blk] Source #
chains ∷ ∀ blk. GetPrevHash blk ⇒ Map (HeaderHash blk) blk → [Chain blk] Source #
copyToImmutableDB ∷ ∀ blk. HasHeader 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 ∷ ∀ blk. HasHeader 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 ∷ ∀ blk. ModelSupportsBlock 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 ∷ ∀ blk. HasHeader 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.
∷ ∀ blk. GetPrevHash blk | |
⇒ Map (HeaderHash blk) blk | A map of blocks; usually the |
→ 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
initLedger ∷ Model blk → ExtLedgerState blk Source #
updateLoE ∷ ∀ blk. LedgerSupportsProtocol 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.
validChains ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → Model blk → Map (HeaderHash blk) blk → (InvalidBlocks blk, [(Chain blk, ExtLedgerState blk)]) Source #
volatileDbBlocks ∷ Model blk → Map (HeaderHash blk) blk Source #
The VolatileDB
wipeVolatileDB ∷ ∀ blk. LedgerSupportsProtocol blk ⇒ TopLevelConfig blk → Model blk → (Point blk, Model blk) Source #