| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq
Description
The data structure that holds the cached ledger states.
Synopsis
- data LedgerTablesHandle (m ∷ Type → Type) (l ∷ Type → (Type → Type → Type) → Type) blk = LedgerTablesHandle {
- close ∷ !(m ())
- duplicateWithDiffs ∷ !(l blk EmptyMK → l blk DiffMK → m (LedgerTablesHandle m l blk))
- duplicate ∷ !(m (LedgerTablesHandle m l blk))
- read ∷ !(l blk EmptyMK → LedgerTables blk KeysMK → m (LedgerTables blk ValuesMK))
- readRange ∷ !(l blk EmptyMK → (Maybe (TxIn blk), Int) → m (LedgerTables blk ValuesMK, Maybe (TxIn blk)))
- readAll ∷ !(l blk EmptyMK → m (LedgerTables blk ValuesMK))
- takeHandleSnapshot ∷ !(l blk EmptyMK → String → m (Maybe CRC))
- tablesSize ∷ !Int
- newtype LedgerSeq (m ∷ Type → Type) (l ∷ Type → (Type → Type → Type) → Type) blk = LedgerSeq {
- getLedgerSeq ∷ AnchoredSeq (WithOrigin SlotNo) (StateRef m l blk) (StateRef m l blk)
- type LedgerSeq' (m ∷ Type → Type) blk = LedgerSeq m ExtLedgerState blk
- data StateRef (m ∷ Type → Type) (l ∷ Type → (Type → Type → Type) → Type) blk = StateRef {
- state ∷ !(l blk EmptyMK)
- tables ∷ !(LedgerTablesHandle m l blk)
- closeLedgerSeq ∷ ∀ m (l ∷ Type → (Type → Type → Type) → Type) blk. Monad m ⇒ LedgerSeq m l blk → m ()
- empty ∷ (GetTip (l blk), IOLike m) ⇒ l blk EmptyMK → init → (init → m (LedgerTablesHandle m l blk)) → m (LedgerSeq m l blk)
- empty' ∷ (GetTip (l blk), IOLike m, HasLedgerTables l blk) ⇒ l blk ValuesMK → (l blk ValuesMK → m (LedgerTablesHandle m l blk)) → m (LedgerSeq m l blk)
- extend ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ StateRef m l blk → LedgerSeq m l blk → LedgerSeq m l blk
- prune ∷ ∀ m (l ∷ Type → LedgerStateKind) blk. (Monad m, GetTip (l blk)) ⇒ LedgerDbPrune → LedgerSeq m l blk → (m (), LedgerSeq m l blk)
- pruneToImmTipOnly ∷ ∀ m (l ∷ Type → LedgerStateKind) blk. (Monad m, GetTip (l blk)) ⇒ LedgerSeq m l blk → (m (), LedgerSeq m l blk)
- reapplyBlock ∷ ∀ (l ∷ StateKind) blk m. (ApplyBlock l blk, IOLike m) ⇒ ComputeLedgerEvents → LedgerCfg l blk → blk → LedgerSeq m l blk → m (StateRef m l blk)
- reapplyThenPush ∷ ∀ m (l ∷ StateKind) blk. (IOLike m, ApplyBlock l blk) ⇒ LedgerDbCfg l blk → blk → LedgerSeq m l blk → m (LedgerSeq m l blk)
- anchor ∷ ∀ (m ∷ Type → Type) l blk. LedgerSeq m l blk → l blk EmptyMK
- anchorHandle ∷ ∀ (m ∷ Type → Type) (l ∷ Type → (Type → Type → Type) → Type) blk. LedgerSeq m l blk → StateRef m l blk
- current ∷ ∀ l blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → l blk EmptyMK
- currentHandle ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → StateRef m l blk
- getPastLedgerAt ∷ ∀ blk l (m ∷ Type → Type). (HasHeader blk, GetTip (l blk), HeaderHash (l blk) ~ HeaderHash blk, StandardHash (l blk)) ⇒ Point blk → LedgerSeq m l blk → Maybe (l blk EmptyMK)
- immutableTipSlot ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → WithOrigin SlotNo
- isSaturated ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ SecurityParam → LedgerSeq m l blk → Bool
- maxRollback ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → Word64
- rollback ∷ ∀ blk (l ∷ Type → LedgerStateKind) (m ∷ Type → Type). (HasHeader blk, GetTip (l blk), HeaderHash (l blk) ~ HeaderHash blk, StandardHash (l blk)) ⇒ Point blk → LedgerSeq m l blk → Maybe (LedgerSeq m l blk)
- rollbackN ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ Word64 → LedgerSeq m l blk → Maybe (LedgerSeq m l blk)
- rollbackToAnchor ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → LedgerSeq m l blk
- rollbackToPoint ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). (StandardHash (l blk), GetTip (l blk)) ⇒ Point (l blk) → LedgerSeq m l blk → Maybe (LedgerSeq m l blk)
- snapshots ∷ ∀ (m ∷ Type → Type) l blk. LedgerSeq m l blk → [(Word64, l blk EmptyMK)]
- tip ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → Point (l blk)
- volatileStatesBimap ∷ ∀ a b l blk (m ∷ Type → Type). Anchorable (WithOrigin SlotNo) a b ⇒ (l blk EmptyMK → a) → (l blk EmptyMK → b) → LedgerSeq m l blk → AnchoredSeq (WithOrigin SlotNo) a b
LedgerHandles
data LedgerTablesHandle (m ∷ Type → Type) (l ∷ Type → (Type → Type → Type) → Type) blk Source #
The interface fulfilled by handles on both the InMemory and LSM handles.
The most relevant concept is handle duplication:
A duplicated handle must provide access to all the data that was there in the original handle while being able to mutate in ways different than the original handle.
When applying diffs to a table, we will first duplicate the handle, then apply the diffs in the copy. It is expected that duplicating the handle takes constant time.
Constructors
| LedgerTablesHandle | |
Fields
| |
Instances
| NoThunks (LedgerTablesHandle m l blk) Source # | |
The ledger seq
newtype LedgerSeq (m ∷ Type → Type) (l ∷ Type → (Type → Type → Type) → Type) blk Source #
Constructors
| LedgerSeq | |
Fields
| |
Instances
| Generic (LedgerSeq m l blk) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq Associated Types
| |||||
| Show (l blk EmptyMK) ⇒ Show (LedgerSeq m l blk) Source # | |||||
| Eq (l blk EmptyMK) ⇒ Eq (LedgerSeq m l blk) Source # | |||||
| (IOLike m, NoThunks (l blk EmptyMK)) ⇒ NoThunks (LedgerSeq m l blk) Source # | |||||
| type Rep (LedgerSeq m l blk) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq type Rep (LedgerSeq m l blk) = D1 ('MetaData "LedgerSeq" "Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq" "ouroboros-consensus-3.0.1.0-inplace" 'True) (C1 ('MetaCons "LedgerSeq" 'PrefixI 'True) (S1 ('MetaSel ('Just "getLedgerSeq") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (AnchoredSeq (WithOrigin SlotNo) (StateRef m l blk) (StateRef m l blk))))) | |||||
type LedgerSeq' (m ∷ Type → Type) blk = LedgerSeq m ExtLedgerState blk Source #
data StateRef (m ∷ Type → Type) (l ∷ Type → (Type → Type → Type) → Type) blk Source #
For single era blocks, it would be the same to hold a stowed ledger state
(), an unstowed one
(LedgerTables (LedgerState blk) EmptyMK) or a tuple with the state
and the tables (LedgerTables (LedgerState blk) ValuesMKLedgerState blk EmptyMK, LedgerTables (LedgerState
blk) ValuesMK), however, for a hard fork block, these are not equivalent.
If we were to hold a sequence of type LedgerState blk EmptyMK with stowed
values, we would have to translate the entirety of the tables on epoch
boundaries.
If we were to hold a sequence of type LedgerState blk ValuesMK we would
have the same problem as the mk in the state actually refers to the mk in
the HardForkState'ed state.
Therefore it sounds reasonable to hold a LedgerState blk EmptyMK with no
values, and a LedgerTables blk ValuesMK next to it, that will live its
entire lifetime as LedgerTables of the HardForkBlock.
Constructors
| StateRef | |
Fields
| |
Instances
closeLedgerSeq ∷ ∀ m (l ∷ Type → (Type → Type → Type) → Type) blk. Monad m ⇒ LedgerSeq m l blk → m () Source #
Close all LedgerTablesHandle in this LedgerSeq, in particular that on
the anchor.
empty ∷ (GetTip (l blk), IOLike m) ⇒ l blk EmptyMK → init → (init → m (LedgerTablesHandle m l blk)) → m (LedgerSeq m l blk) Source #
Creates an empty LedgerSeq
empty' ∷ (GetTip (l blk), IOLike m, HasLedgerTables l blk) ⇒ l blk ValuesMK → (l blk ValuesMK → m (LedgerTablesHandle m l blk)) → m (LedgerSeq m l blk) Source #
Creates an empty LedgerSeq
Apply Blocks
extend ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ StateRef m l blk → LedgerSeq m l blk → LedgerSeq m l blk Source #
Extending the LedgerDB with a valid ledger state.
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>LedgerSeq ldb' = extend l4 ldb>>>AS.toOldestFirst ldb' == [l1, l2, l3, l4]True
prune ∷ ∀ m (l ∷ Type → LedgerStateKind) blk. (Monad m, GetTip (l blk)) ⇒ LedgerDbPrune → LedgerSeq m l blk → (m (), LedgerSeq m l blk) Source #
Prune older ledger states according to the given LedgerDbPrune strategy.
The fst component of the returned value is an action closing the pruned
ledger states.
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>ldb' = LedgerSeq $ AS.fromOldestFirst l1 [l2, l3]>>>snd (prune (LedgerDbPruneBeforeSlot 1) ldb) == ldb'True
where lX is a ledger state from slot X-1 (or Origin for l0).
pruneToImmTipOnly ∷ ∀ m (l ∷ Type → LedgerStateKind) blk. (Monad m, GetTip (l blk)) ⇒ LedgerSeq m l blk → (m (), LedgerSeq m l blk) Source #
Set the volatile tip as the immutable tip and prune all older states.
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>LedgerSeq ldb' = snd $ pruneToImmTipOnly ldb>>>AS.anchor ldb' == l3 && AS.toOldestFirst ldb' == []True
reapplyBlock ∷ ∀ (l ∷ StateKind) blk m. (ApplyBlock l blk, IOLike m) ⇒ ComputeLedgerEvents → LedgerCfg l blk → blk → LedgerSeq m l blk → m (StateRef m l blk) Source #
reapplyThenPush ∷ ∀ m (l ∷ StateKind) blk. (IOLike m, ApplyBlock l blk) ⇒ LedgerDbCfg l blk → blk → LedgerSeq m l blk → m (LedgerSeq m l blk) Source #
Apply a block on top of the ledger state and extend the LedgerSeq with the result ledger state.
The fst component of the result should be run to close the pruned states.
Queries
anchor ∷ ∀ (m ∷ Type → Type) l blk. LedgerSeq m l blk → l blk EmptyMK Source #
The ledger state at the anchor of the Volatile chain (i.e. the immutable tip).
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>l0s == anchor ldbTrue
anchorHandle ∷ ∀ (m ∷ Type → Type) (l ∷ Type → (Type → Type → Type) → Type) blk. LedgerSeq m l blk → StateRef m l blk Source #
current ∷ ∀ l blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → l blk EmptyMK Source #
The ledger state at the tip of the chain
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>l3s == current ldbTrue
currentHandle ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → StateRef m l blk Source #
getPastLedgerAt ∷ ∀ blk l (m ∷ Type → Type). (HasHeader blk, GetTip (l blk), HeaderHash (l blk) ~ HeaderHash blk, StandardHash (l blk)) ⇒ Point blk → LedgerSeq m l blk → Maybe (l blk EmptyMK) Source #
Get a past ledger state
\( O(\log(\min(i,n-i)) \)
When no ledger state (or anchor) has the given Point, Nothing is
returned.
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>getPastLedgerAt (Point (At (Block 4 4)) :: Point B) ldb == NothingTrue>>>getPastLedgerAt (Point (At (Block 1 1)) :: Point B) ldb == Just l2sTrue
immutableTipSlot ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → WithOrigin SlotNo Source #
isSaturated ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ SecurityParam → LedgerSeq m l blk → Bool Source #
Have we seen at least k blocks?
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>isSaturated (SecurityParam (unsafeNonZero 3)) ldbTrue>>>isSaturated (SecurityParam (unsafeNonZero 4)) ldbFalse
maxRollback ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → Word64 Source #
How many blocks can we currently roll back?
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>maxRollback ldb3
rollback ∷ ∀ blk (l ∷ Type → LedgerStateKind) (m ∷ Type → Type). (HasHeader blk, GetTip (l blk), HeaderHash (l blk) ~ HeaderHash blk, StandardHash (l blk)) ⇒ Point blk → LedgerSeq m l blk → Maybe (LedgerSeq m l blk) Source #
rollbackN ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ Word64 → LedgerSeq m l blk → Maybe (LedgerSeq m l blk) Source #
Rollback n ledger states.
Returns Nothing if maximum rollback (usually k, but can be less on
startup or under corruption) is exceeded.
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>fmap (([l1] ==) . AS.toOldestFirst . getLedgerSeq) (rollbackN 2 ldb)Just True
rollbackToAnchor ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → LedgerSeq m l blk Source #
Rollback the volatile states up to the volatile anchor.
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>LedgerSeq ldb' = rollbackToAnchor ldb>>>AS.anchor ldb' == l0 && AS.toOldestFirst ldb' == []True
rollbackToPoint ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). (StandardHash (l blk), GetTip (l blk)) ⇒ Point (l blk) → LedgerSeq m l blk → Maybe (LedgerSeq m l blk) Source #
Roll back the volatile states up to the specified point.
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>Just (LedgerSeq ldb') = rollbackToPoint (Point Origin) ldb>>>AS.anchor ldb' == l0 && AS.toOldestFirst ldb' == []True>>>rollbackToPoint (Point (At (Block 1 2))) ldb == NothingTrue>>>Just (LedgerSeq ldb') = rollbackToPoint (Point (At (Block 1 1))) ldb>>>AS.anchor ldb' == l0 && AS.toOldestFirst ldb' == [l1, l2]True
snapshots ∷ ∀ (m ∷ Type → Type) l blk. LedgerSeq m l blk → [(Word64, l blk EmptyMK)] Source #
All snapshots currently stored by the ledger DB (new to old)
This also includes the snapshot at the anchor. For each snapshot we also return the distance from the tip.
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>[(0, l3s), (1, l2s), (2, l1s)] == snapshots ldbTrue
tip ∷ ∀ (l ∷ Type → LedgerStateKind) blk (m ∷ Type → Type). GetTip (l blk) ⇒ LedgerSeq m l blk → Point (l blk) Source #
Reference to the block at the tip of the chain
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>tip ldb == getTip l3sTrue
volatileStatesBimap ∷ ∀ a b l blk (m ∷ Type → Type). Anchorable (WithOrigin SlotNo) a b ⇒ (l blk EmptyMK → a) → (l blk EmptyMK → b) → LedgerSeq m l blk → AnchoredSeq (WithOrigin SlotNo) a b Source #
Transform the underlying volatile AnchoredSeq using the given functions.