| 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) = LedgerTablesHandle {
- close ∷ !(m ())
- transfer ∷ !(ResourceKey m → m ())
- duplicate ∷ !(ResourceRegistry m → m (ResourceKey m, LedgerTablesHandle m l))
- read ∷ !(l EmptyMK → LedgerTables l KeysMK → m (LedgerTables l ValuesMK))
- readRange ∷ !(l EmptyMK → (Maybe (TxIn l), Int) → m (LedgerTables l ValuesMK, Maybe (TxIn l)))
- readAll ∷ !(l EmptyMK → m (LedgerTables l ValuesMK))
- pushDiffs ∷ !(∀ (mk ∷ Type → Type → Type). l mk → l DiffMK → m ())
- takeHandleSnapshot ∷ !(l EmptyMK → String → m (Maybe CRC))
- tablesSize ∷ !(m (Maybe Int))
- newtype LedgerSeq (m ∷ Type → Type) (l ∷ (Type → Type → Type) → Type) = LedgerSeq {
- getLedgerSeq ∷ AnchoredSeq (WithOrigin SlotNo) (StateRef m l) (StateRef m l)
- type LedgerSeq' (m ∷ Type → Type) blk = LedgerSeq m (ExtLedgerState blk)
- data StateRef (m ∷ Type → Type) (l ∷ (Type → Type → Type) → Type) = StateRef {
- state ∷ !(l EmptyMK)
- tables ∷ !(LedgerTablesHandle m l)
- closeLedgerSeq ∷ ∀ m (l ∷ (Type → Type → Type) → Type). Monad m ⇒ LedgerSeq m l → m ()
- empty ∷ (GetTip l, IOLike m) ⇒ l EmptyMK → init → (init → m (LedgerTablesHandle m l)) → m (LedgerSeq m l)
- empty' ∷ (GetTip l, IOLike m, HasLedgerTables l) ⇒ l ValuesMK → (l ValuesMK → m (LedgerTablesHandle m l)) → m (LedgerSeq m l)
- extend ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ StateRef m l → LedgerSeq m l → LedgerSeq m l
- prune ∷ ∀ m (l ∷ LedgerStateKind). (Monad m, GetTip l) ⇒ LedgerDbPrune → LedgerSeq m l → (m (), LedgerSeq m l)
- pruneToImmTipOnly ∷ ∀ m (l ∷ LedgerStateKind). (Monad m, GetTip l) ⇒ LedgerSeq m l → (m (), LedgerSeq m l)
- reapplyBlock ∷ ∀ m (l ∷ LedgerStateKind) blk. (ApplyBlock l blk, IOLike m) ⇒ ComputeLedgerEvents → LedgerCfg l → blk → ResourceRegistry m → LedgerSeq m l → m (StateRef m l)
- reapplyThenPush ∷ ∀ m (l ∷ LedgerStateKind) blk. (IOLike m, ApplyBlock l blk) ⇒ ResourceRegistry m → LedgerDbCfg l → blk → LedgerSeq m l → m (m (), LedgerSeq m l)
- anchor ∷ ∀ (m ∷ Type → Type) l. LedgerSeq m l → l EmptyMK
- anchorHandle ∷ ∀ (m ∷ Type → Type) (l ∷ (Type → Type → Type) → Type). LedgerSeq m l → StateRef m l
- current ∷ ∀ l (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → l EmptyMK
- currentHandle ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → StateRef m l
- getPastLedgerAt ∷ ∀ blk l (m ∷ Type → Type). (HasHeader blk, GetTip l, HeaderHash l ~ HeaderHash blk, StandardHash l) ⇒ Point blk → LedgerSeq m l → Maybe (l EmptyMK)
- immutableTipSlot ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → WithOrigin SlotNo
- isSaturated ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ SecurityParam → LedgerSeq m l → Bool
- maxRollback ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → Word64
- rollback ∷ ∀ blk (l ∷ LedgerStateKind) (m ∷ Type → Type). (HasHeader blk, GetTip l, HeaderHash l ~ HeaderHash blk, StandardHash l) ⇒ Point blk → LedgerSeq m l → Maybe (LedgerSeq m l)
- rollbackN ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ Word64 → LedgerSeq m l → Maybe (LedgerSeq m l)
- rollbackToAnchor ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → LedgerSeq m l
- rollbackToPoint ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). (StandardHash l, GetTip l) ⇒ Point l → LedgerSeq m l → Maybe (LedgerSeq m l)
- snapshots ∷ ∀ (m ∷ Type → Type) l. LedgerSeq m l → [(Word64, l EmptyMK)]
- tip ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → Point l
- volatileStatesBimap ∷ ∀ a b l (m ∷ Type → Type). Anchorable (WithOrigin SlotNo) a b ⇒ (l EmptyMK → a) → (l EmptyMK → b) → LedgerSeq m l → AnchoredSeq (WithOrigin SlotNo) a b
LedgerHandles
data LedgerTablesHandle (m ∷ Type → Type) (l ∷ (Type → Type → Type) → Type) Source #
The interface fulfilled by handles on both the InMemory and LSM handles.
Constructors
| LedgerTablesHandle | |
Fields
| |
Instances
| NoThunks (LedgerTablesHandle m l) Source # | |
The ledger seq
newtype LedgerSeq (m ∷ Type → Type) (l ∷ (Type → Type → Type) → Type) Source #
Constructors
| LedgerSeq | |
Fields
| |
Instances
type LedgerSeq' (m ∷ Type → Type) blk = LedgerSeq m (ExtLedgerState blk) Source #
data StateRef (m ∷ Type → Type) (l ∷ (Type → Type → Type) → Type) 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
| GetTip l ⇒ Anchorable (WithOrigin SlotNo) (StateRef m l) (StateRef m l) Source # | |||||
| Generic (StateRef m l) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq Associated Types
| |||||
| Show (l EmptyMK) ⇒ Show (StateRef m l) Source # | |||||
| Eq (l EmptyMK) ⇒ Eq (StateRef m l) Source # | |||||
| (IOLike m, NoThunks (l EmptyMK)) ⇒ NoThunks (StateRef m l) Source # | |||||
| type Rep (StateRef m l) Source # | |||||
Defined in Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq type Rep (StateRef m l) = D1 ('MetaData "StateRef" "Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq" "ouroboros-consensus-0.28.0.0-inplace" 'False) (C1 ('MetaCons "StateRef" 'PrefixI 'True) (S1 ('MetaSel ('Just "state") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (l EmptyMK)) :*: S1 ('MetaSel ('Just "tables") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (LedgerTablesHandle m l)))) | |||||
closeLedgerSeq ∷ ∀ m (l ∷ (Type → Type → Type) → Type). Monad m ⇒ LedgerSeq m l → m () Source #
Close all LedgerTablesHandle in this LedgerSeq, in particular that on
the anchor.
empty ∷ (GetTip l, IOLike m) ⇒ l EmptyMK → init → (init → m (LedgerTablesHandle m l)) → m (LedgerSeq m l) Source #
Creates an empty LedgerSeq
empty' ∷ (GetTip l, IOLike m, HasLedgerTables l) ⇒ l ValuesMK → (l ValuesMK → m (LedgerTablesHandle m l)) → m (LedgerSeq m l) Source #
Creates an empty LedgerSeq
Apply Blocks
extend ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ StateRef m l → LedgerSeq m l → LedgerSeq m l 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 ∷ LedgerStateKind). (Monad m, GetTip l) ⇒ LedgerDbPrune → LedgerSeq m l → (m (), LedgerSeq m l) 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 ∷ LedgerStateKind). (Monad m, GetTip l) ⇒ LedgerSeq m l → (m (), LedgerSeq m l) 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 ∷ ∀ m (l ∷ LedgerStateKind) blk. (ApplyBlock l blk, IOLike m) ⇒ ComputeLedgerEvents → LedgerCfg l → blk → ResourceRegistry m → LedgerSeq m l → m (StateRef m l) Source #
reapplyThenPush ∷ ∀ m (l ∷ LedgerStateKind) blk. (IOLike m, ApplyBlock l blk) ⇒ ResourceRegistry m → LedgerDbCfg l → blk → LedgerSeq m l → m (m (), LedgerSeq m l) 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. LedgerSeq m l → l 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). LedgerSeq m l → StateRef m l Source #
current ∷ ∀ l (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → l EmptyMK Source #
The ledger state at the tip of the chain
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>l3s == current ldbTrue
currentHandle ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → StateRef m l Source #
getPastLedgerAt ∷ ∀ blk l (m ∷ Type → Type). (HasHeader blk, GetTip l, HeaderHash l ~ HeaderHash blk, StandardHash l) ⇒ Point blk → LedgerSeq m l → Maybe (l 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 ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → WithOrigin SlotNo Source #
isSaturated ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ SecurityParam → LedgerSeq m l → 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 ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → Word64 Source #
How many blocks can we currently roll back?
>>>ldb = LedgerSeq $ AS.fromOldestFirst l0 [l1, l2, l3]>>>maxRollback ldb3
rollback ∷ ∀ blk (l ∷ LedgerStateKind) (m ∷ Type → Type). (HasHeader blk, GetTip l, HeaderHash l ~ HeaderHash blk, StandardHash l) ⇒ Point blk → LedgerSeq m l → Maybe (LedgerSeq m l) Source #
rollbackN ∷ ∀ (l ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ Word64 → LedgerSeq m l → Maybe (LedgerSeq m l) 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 ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → LedgerSeq m l 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 ∷ LedgerStateKind) (m ∷ Type → Type). (StandardHash l, GetTip l) ⇒ Point l → LedgerSeq m l → Maybe (LedgerSeq m l) 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. LedgerSeq m l → [(Word64, l 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 ∷ LedgerStateKind) (m ∷ Type → Type). GetTip l ⇒ LedgerSeq m l → Point l 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 (m ∷ Type → Type). Anchorable (WithOrigin SlotNo) a b ⇒ (l EmptyMK → a) → (l EmptyMK → b) → LedgerSeq m l → AnchoredSeq (WithOrigin SlotNo) a b Source #
Transform the underlying volatile AnchoredSeq using the given functions.