Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Accessors for the LedgerDB and management
This module defines the operations that can be done on a LedgerDB, as well as the procedures to apply a block to a LedgerDB and pushing the resulting LedgerState into the DB.
Synopsis
- ledgerDbWithAnchor ∷ GetTip l ⇒ l → LedgerDB l
- data AnnLedgerError l blk = AnnLedgerError {
- annLedgerState ∷ LedgerDB l
- annLedgerErrRef ∷ RealPoint blk
- annLedgerErr ∷ LedgerErr l
- type AnnLedgerError' blk = AnnLedgerError (ExtLedgerState blk) blk
- data Ap m l blk c where
- ReapplyVal ∷ blk → Ap m l blk ()
- ApplyVal ∷ blk → Ap m l blk (ThrowsLedgerError m l blk)
- ReapplyRef ∷ RealPoint blk → Ap m l blk (ResolvesBlocks m blk)
- ApplyRef ∷ RealPoint blk → Ap m l blk (ResolvesBlocks m blk, ThrowsLedgerError m l blk)
- Weaken ∷ (c' ⇒ c) ⇒ Ap m l blk c → Ap m l blk c'
- data ExceededRollback = ExceededRollback {}
- class Monad m ⇒ ThrowsLedgerError m l blk where
- throwLedgerError ∷ LedgerDB l → RealPoint blk → LedgerErr l → m a
- defaultThrowLedgerErrors ∷ ExceptT (AnnLedgerError l blk) m a → m (Either (AnnLedgerError l blk) a)
- type ResolveBlock m blk = RealPoint blk → m blk
- class Monad m ⇒ ResolvesBlocks m blk | m → blk where
- doResolveBlock ∷ ResolveBlock m blk
- defaultResolveBlocks ∷ ResolveBlock m blk → ReaderT (ResolveBlock m blk) m a → m a
- defaultResolveWithErrors ∷ ResolveBlock m blk → ExceptT (AnnLedgerError l blk) (ReaderT (ResolveBlock m blk) m) a → m (Either (AnnLedgerError l blk) a)
- ledgerDbBimap ∷ Anchorable (WithOrigin SlotNo) a b ⇒ (l → a) → (l → b) → LedgerDB l → AnchoredSeq (WithOrigin SlotNo) a b
- ledgerDbPrune ∷ GetTip l ⇒ SecurityParam → LedgerDB l → LedgerDB l
- ledgerDbPush ∷ ∀ m c l blk. (ApplyBlock l blk, Monad m, c) ⇒ LedgerDbCfg l → Ap m l blk c → LedgerDB l → m (LedgerDB l)
- ledgerDbSwitch ∷ (ApplyBlock l blk, Monad m, c) ⇒ LedgerDbCfg l → Word64 → (UpdateLedgerDbTraceEvent blk → m ()) → [Ap m l blk c] → LedgerDB l → m (Either ExceededRollback (LedgerDB l))
- ledgerDbPush' ∷ ApplyBlock l blk ⇒ LedgerDbCfg l → blk → LedgerDB l → LedgerDB l
- ledgerDbPushMany' ∷ ApplyBlock l blk ⇒ LedgerDbCfg l → [blk] → LedgerDB l → LedgerDB l
- ledgerDbSwitch' ∷ ∀ l blk. ApplyBlock l blk ⇒ LedgerDbCfg l → Word64 → [blk] → LedgerDB l → Maybe (LedgerDB l)
- newtype PushGoal blk = PushGoal {
- unPushGoal ∷ RealPoint blk
- newtype PushStart blk = PushStart {
- unPushStart ∷ RealPoint blk
- newtype Pushing blk = Pushing {}
- data UpdateLedgerDbTraceEvent blk = StartedPushingBlockToTheLedgerDb !(PushStart blk) (PushGoal blk) !(Pushing blk)
LedgerDB management
ledgerDbWithAnchor ∷ GetTip l ⇒ l → LedgerDB l Source #
Ledger DB starting at the specified ledger state
Applying blocks
data AnnLedgerError l blk Source #
Annotated ledger errors
AnnLedgerError | |
|
Instances
Monad m ⇒ ThrowsLedgerError (ExceptT (AnnLedgerError l blk) m) l blk Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Update throwLedgerError ∷ LedgerDB l → RealPoint blk → LedgerErr l → ExceptT (AnnLedgerError l blk) m a Source # |
type AnnLedgerError' blk = AnnLedgerError (ExtLedgerState blk) blk Source #
data Ap m l blk c where Source #
Ap
is used to pass information about blocks to ledger DB updates
The constructors serve two purposes:
- Specify the various parameters a. Are we passing the block by value or by reference? b. Are we applying or reapplying the block?
- Compute the constraint
c
on the monadm
in order to run the query: a. If we are passing a block by reference, we must be able to resolve it. b. If we are applying rather than reapplying, we might have ledger errors.
ReapplyVal ∷ blk → Ap m l blk () | |
ApplyVal ∷ blk → Ap m l blk (ThrowsLedgerError m l blk) | |
ReapplyRef ∷ RealPoint blk → Ap m l blk (ResolvesBlocks m blk) | |
ApplyRef ∷ RealPoint blk → Ap m l blk (ResolvesBlocks m blk, ThrowsLedgerError m l blk) | |
Weaken ∷ (c' ⇒ c) ⇒ Ap m l blk c → Ap m l blk c' |
This is primarily useful when combining multiple |
data ExceededRollback Source #
Exceeded maximum rollback supported by the current ledger DB state
Under normal circumstances this will not arise. It can really only happen in the presence of data corruption (or when switching to a shorter fork, but that is disallowed by all currently known Ouroboros protocols).
Records both the supported and the requested rollback.
class Monad m ⇒ ThrowsLedgerError m l blk where Source #
Instances
Monad m ⇒ ThrowsLedgerError (ExceptT (AnnLedgerError l blk) m) l blk Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Update throwLedgerError ∷ LedgerDB l → RealPoint blk → LedgerErr l → ExceptT (AnnLedgerError l blk) m a Source # |
defaultThrowLedgerErrors ∷ ExceptT (AnnLedgerError l blk) m a → m (Either (AnnLedgerError l blk) a) Source #
Block resolution
type ResolveBlock m blk = RealPoint blk → m blk Source #
Resolve a block
Resolving a block reference to the actual block lives in m
because
it might need to read the block from disk (and can therefore not be
done inside an STM transaction).
NOTE: The ledger DB will only ask the ChainDB
for blocks it knows
must exist. If the ChainDB
is unable to fulfill the request, data
corruption must have happened and the ChainDB
should trigger
validation mode.
class Monad m ⇒ ResolvesBlocks m blk | m → blk where Source #
Monads in which we can resolve blocks
To guide type inference, we insist that we must be able to infer the type of the block we are resolving from the type of the monad.
doResolveBlock ∷ ResolveBlock m blk Source #
Instances
Monad m ⇒ ResolvesBlocks (ExceptT e (ReaderT (ResolveBlock m blk) m)) blk Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Update doResolveBlock ∷ ResolveBlock (ExceptT e (ReaderT (ResolveBlock m blk) m)) blk Source # | |
Monad m ⇒ ResolvesBlocks (ReaderT (ResolveBlock m blk) m) blk Source # | |
Defined in Ouroboros.Consensus.Storage.LedgerDB.Update doResolveBlock ∷ ResolveBlock (ReaderT (ResolveBlock m blk) m) blk Source # |
defaultResolveBlocks ∷ ResolveBlock m blk → ReaderT (ResolveBlock m blk) m a → m a Source #
Updates
defaultResolveWithErrors ∷ ResolveBlock m blk → ExceptT (AnnLedgerError l blk) (ReaderT (ResolveBlock m blk) m) a → m (Either (AnnLedgerError l blk) a) Source #
ledgerDbBimap ∷ Anchorable (WithOrigin SlotNo) a b ⇒ (l → a) → (l → b) → LedgerDB l → AnchoredSeq (WithOrigin SlotNo) a b Source #
Transform the underlying AnchoredSeq
using the given functions.
ledgerDbPrune ∷ GetTip l ⇒ SecurityParam → LedgerDB l → LedgerDB l Source #
Prune snapshots until at we have at most k
snapshots in the LedgerDB,
excluding the snapshots stored at the anchor.
ledgerDbPush ∷ ∀ m c l blk. (ApplyBlock l blk, Monad m, c) ⇒ LedgerDbCfg l → Ap m l blk c → LedgerDB l → m (LedgerDB l) Source #
∷ (ApplyBlock l blk, Monad m, c) | |
⇒ LedgerDbCfg l | |
→ Word64 | How many blocks to roll back |
→ (UpdateLedgerDbTraceEvent blk → m ()) | |
→ [Ap m l blk c] | New blocks to apply |
→ LedgerDB l | |
→ m (Either ExceededRollback (LedgerDB l)) |
Switch to a fork
Pure API
ledgerDbPush' ∷ ApplyBlock l blk ⇒ LedgerDbCfg l → blk → LedgerDB l → LedgerDB l Source #
ledgerDbPushMany' ∷ ApplyBlock l blk ⇒ LedgerDbCfg l → [blk] → LedgerDB l → LedgerDB l Source #
ledgerDbSwitch' ∷ ∀ l blk. ApplyBlock l blk ⇒ LedgerDbCfg l → Word64 → [blk] → LedgerDB l → Maybe (LedgerDB l) Source #
Trace
PushGoal | |
|
Instances
StandardHash blk ⇒ Show (PushGoal blk) Source # | |
StandardHash blk ⇒ Eq (PushGoal blk) Source # | |
newtype PushStart blk Source #
PushStart | |
|
Instances
StandardHash blk ⇒ Show (PushStart blk) Source # | |
StandardHash blk ⇒ Eq (PushStart blk) Source # | |
Instances
StandardHash blk ⇒ Show (Pushing blk) Source # | |
StandardHash blk ⇒ Eq (Pushing blk) Source # | |
data UpdateLedgerDbTraceEvent blk Source #
StartedPushingBlockToTheLedgerDb | Event fired when we are about to push a block to the LedgerDB |