Safe Haskell | None |
---|---|
Language | Haskell2010 |
Ouroboros.Consensus.Mempool.Impl.Common
Description
Definition of common types used in Ouroboros.Consensus.Mempool.Init, Ouroboros.Consensus.Mempool.Update and Ouroboros.Consensus.Mempool.Query.
Synopsis
- data InternalState blk = IS {
- isTxs ∷ !(TxSeq (TxMeasure blk) (Validated (GenTx blk)))
- isTxIds ∷ !(Set (GenTxId blk))
- isTxKeys ∷ !(LedgerTables (LedgerState blk) KeysMK)
- isTxValues ∷ !(LedgerTables (LedgerState blk) ValuesMK)
- isLedgerState ∷ !(TickedLedgerState blk DiffMK)
- isTip ∷ !(Point blk)
- isSlotNo ∷ !SlotNo
- isLastTicketNo ∷ !TicketNo
- isCapacity ∷ !(TxMeasure blk)
- isMempoolSize ∷ TxLimits blk ⇒ InternalState blk → MempoolSize
- data MempoolEnv (m ∷ Type → Type) blk = MempoolEnv {
- mpEnvLedger ∷ LedgerInterface m blk
- mpEnvLedgerCfg ∷ LedgerConfig blk
- mpEnvStateVar ∷ StrictTMVar m (InternalState blk)
- mpEnvAddTxsRemoteFifo ∷ MVar m ()
- mpEnvAddTxsAllFifo ∷ MVar m ()
- mpEnvTracer ∷ Tracer m (TraceEventMempool blk)
- mpEnvCapacityOverride ∷ MempoolCapacityBytesOverride
- initMempoolEnv ∷ (IOLike m, LedgerSupportsMempool blk, ValidateEnvelope blk) ⇒ LedgerInterface m blk → LedgerConfig blk → MempoolCapacityBytesOverride → Tracer m (TraceEventMempool blk) → m (MempoolEnv m blk)
- data LedgerInterface (m ∷ Type → Type) blk = LedgerInterface {
- getCurrentLedgerState ∷ STM m (LedgerState blk EmptyMK)
- getLedgerTablesAtFor ∷ Point blk → LedgerTables (LedgerState blk) KeysMK → m (Maybe (LedgerTables (LedgerState blk) ValuesMK))
- chainDBLedgerInterface ∷ ∀ (m ∷ Type → Type) blk. IOLike m ⇒ ChainDB m blk → LedgerInterface m blk
- data RevalidateTxsResult blk = RevalidateTxsResult {
- newInternalState ∷ !(InternalState blk)
- removedTxs ∷ ![Invalidated blk]
- computeSnapshot ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ MempoolCapacityBytesOverride → LedgerConfig blk → SlotNo → TickedLedgerState blk DiffMK → LedgerTables (LedgerState blk) ValuesMK → TicketNo → [TxTicket (TxMeasure blk) (Validated (GenTx blk))] → MempoolSnapshot blk
- revalidateTxsFor ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ MempoolCapacityBytesOverride → LedgerConfig blk → SlotNo → TickedLedgerState blk DiffMK → LedgerTables (LedgerState blk) ValuesMK → TicketNo → [TxTicket (TxMeasure blk) (Validated (GenTx blk))] → RevalidateTxsResult blk
- validateNewTransaction ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ LedgerConfig blk → WhetherToIntervene → GenTx blk → TxMeasure blk → LedgerTables (LedgerState blk) ValuesMK → TickedLedgerState blk ValuesMK → InternalState blk → (Either (ApplyTxErr blk) (Validated (GenTx blk)), InternalState blk)
- data TraceEventMempool blk
- = TraceMempoolAddedTx (Validated (GenTx blk)) MempoolSize MempoolSize
- | TraceMempoolRejectedTx (GenTx blk) (ApplyTxErr blk) MempoolSize
- | TraceMempoolRemoveTxs [(Validated (GenTx blk), ApplyTxErr blk)] MempoolSize
- | TraceMempoolManuallyRemovedTxs (NonEmpty (GenTxId blk)) [Validated (GenTx blk)] MempoolSize
- | TraceMempoolSynced EnclosingTimed
- | TraceMempoolSyncNotNeeded (Point blk)
- | TraceMempoolAttemptingAdd (GenTx blk)
- | TraceMempoolLedgerFound (Point blk)
- | TraceMempoolLedgerNotFound (Point blk)
- snapshotFromIS ∷ (HasTxId (GenTx blk), TxLimits blk, GetTip (TickedLedgerState blk)) ⇒ InternalState blk → MempoolSnapshot blk
- tickLedgerState ∷ (UpdateLedger blk, ValidateEnvelope blk) ⇒ LedgerConfig blk → ForgeLedgerState blk → (SlotNo, TickedLedgerState blk DiffMK)
Internal state
data InternalState blk Source #
Internal state in the mempool
Constructors
IS | |
Fields
|
Instances
isMempoolSize ∷ TxLimits blk ⇒ InternalState blk → MempoolSize Source #
\( O(1) \). Return the number of transactions in the internal state of the Mempool paired with their total size in bytes.
Mempool environment
data MempoolEnv (m ∷ Type → Type) blk Source #
The mempool environment captures all the associated variables wrt the Mempool and is accessed by the Mempool interface on demand to perform the different operations.
Constructors
MempoolEnv | |
Fields
|
initMempoolEnv ∷ (IOLike m, LedgerSupportsMempool blk, ValidateEnvelope blk) ⇒ LedgerInterface m blk → LedgerConfig blk → MempoolCapacityBytesOverride → Tracer m (TraceEventMempool blk) → m (MempoolEnv m blk) Source #
Ledger interface
data LedgerInterface (m ∷ Type → Type) blk Source #
Abstract interface needed to run a Mempool.
Constructors
LedgerInterface | |
Fields
|
chainDBLedgerInterface ∷ ∀ (m ∷ Type → Type) blk. IOLike m ⇒ ChainDB m blk → LedgerInterface m blk Source #
Create a LedgerInterface
from a ChainDB
.
Validation
data RevalidateTxsResult blk Source #
Constructors
RevalidateTxsResult | |
Fields
|
Arguments
∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) | |
⇒ MempoolCapacityBytesOverride | |
→ LedgerConfig blk | |
→ SlotNo | |
→ TickedLedgerState blk DiffMK | The ticked ledger state againt which txs will be revalidated |
→ LedgerTables (LedgerState blk) ValuesMK | The tables with all the inputs for the transactions |
→ TicketNo |
|
→ [TxTicket (TxMeasure blk) (Validated (GenTx blk))] | |
→ MempoolSnapshot blk |
Compute snapshot is largely the same as revalidate the transactions but we ignore the diffs.
Arguments
∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) | |
⇒ MempoolCapacityBytesOverride | |
→ LedgerConfig blk | |
→ SlotNo | |
→ TickedLedgerState blk DiffMK | The ticked ledger state againt which txs will be revalidated |
→ LedgerTables (LedgerState blk) ValuesMK | The tables with all the inputs for the transactions |
→ TicketNo |
|
→ [TxTicket (TxMeasure blk) (Validated (GenTx blk))] | |
→ RevalidateTxsResult blk |
Revalidate the given transactions against the given ticked ledger state,
producing a new InternalState
.
Note that this function will perform revalidation so it is expected that the transactions given to it were previously applied, for example if we are revalidating the whole set of transactions onto a new state, or if we remove some transactions and revalidate the remaining ones.
validateNewTransaction Source #
Arguments
∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) | |
⇒ LedgerConfig blk | |
→ WhetherToIntervene | |
→ GenTx blk | |
→ TxMeasure blk | |
→ LedgerTables (LedgerState blk) ValuesMK | Values to cache if success |
→ TickedLedgerState blk ValuesMK | This state is the internal state with the tables for this transaction
advanced through the diffs in the internal state. One could think we can
create this value here, but it is needed for some other uses like calling
|
→ InternalState blk | |
→ (Either (ApplyTxErr blk) (Validated (GenTx blk)), InternalState blk) |
Extend InternalState
with a new transaction (one which we have not
previously validated) that may or may not be valid in this ledger state.
Tracing
data TraceEventMempool blk Source #
Events traced by the Mempool.
Constructors
TraceMempoolAddedTx | |
Fields
| |
TraceMempoolRejectedTx | |
Fields
| |
TraceMempoolRemoveTxs | |
Fields
| |
TraceMempoolManuallyRemovedTxs | |
Fields
| |
TraceMempoolSynced | Emitted when the mempool is adjusted after the tip has changed. |
Fields
| |
TraceMempoolSyncNotNeeded (Point blk) | A sync is not needed, as the point at the tip of the LedgerDB and the point at the mempool are the same. |
TraceMempoolAttemptingAdd (GenTx blk) | We will try to add a transaction. Adding a transaction might need to trigger a re-sync. |
TraceMempoolLedgerFound (Point blk) | When adding a transaction, the ledger state in the mempool was found in the LedgerDB, and therefore we can read values, even if it is not the tip of the LedgerDB. An async re-sync will be performed eventually in that case. |
TraceMempoolLedgerNotFound (Point blk) | When adding a transaction, the ledger state in the mempool is gone from the LedgerDB, so we cannot read values for the new transaction. This forces an in-place re-sync. |
Instances
Generic (TraceEventMempool blk) Source # | |||||
Defined in Ouroboros.Consensus.Mempool.Impl.Common Associated Types
Methods from ∷ TraceEventMempool blk → Rep (TraceEventMempool blk) x # to ∷ Rep (TraceEventMempool blk) x → TraceEventMempool blk # | |||||
(Show (GenTx blk), Show (Validated (GenTx blk)), Show (GenTxId blk), Show (ApplyTxErr blk), StandardHash blk) ⇒ Show (TraceEventMempool blk) Source # | |||||
Defined in Ouroboros.Consensus.Mempool.Impl.Common Methods showsPrec ∷ Int → TraceEventMempool blk → ShowS # show ∷ TraceEventMempool blk → String # showList ∷ [TraceEventMempool blk] → ShowS # | |||||
(Eq (GenTx blk), Eq (Validated (GenTx blk)), Eq (GenTxId blk), Eq (ApplyTxErr blk), StandardHash blk) ⇒ Eq (TraceEventMempool blk) Source # | |||||
Defined in Ouroboros.Consensus.Mempool.Impl.Common Methods (==) ∷ TraceEventMempool blk → TraceEventMempool blk → Bool # (/=) ∷ TraceEventMempool blk → TraceEventMempool blk → Bool # | |||||
type Rep (TraceEventMempool blk) Source # | |||||
Defined in Ouroboros.Consensus.Mempool.Impl.Common type Rep (TraceEventMempool blk) = D1 ('MetaData "TraceEventMempool" "Ouroboros.Consensus.Mempool.Impl.Common" "ouroboros-consensus-0.26.0.0-inplace" 'False) (((C1 ('MetaCons "TraceMempoolAddedTx" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Validated (GenTx blk))) :*: (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize) :*: S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize))) :+: C1 ('MetaCons "TraceMempoolRejectedTx" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (GenTx blk)) :*: (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (ApplyTxErr blk)) :*: S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize)))) :+: (C1 ('MetaCons "TraceMempoolRemoveTxs" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Validated (GenTx blk), ApplyTxErr blk)]) :*: S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize)) :+: C1 ('MetaCons "TraceMempoolManuallyRemovedTxs" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (NonEmpty (GenTxId blk))) :*: (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Validated (GenTx blk)]) :*: S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize))))) :+: ((C1 ('MetaCons "TraceMempoolSynced" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EnclosingTimed)) :+: C1 ('MetaCons "TraceMempoolSyncNotNeeded" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Point blk)))) :+: (C1 ('MetaCons "TraceMempoolAttemptingAdd" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (GenTx blk))) :+: (C1 ('MetaCons "TraceMempoolLedgerFound" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Point blk))) :+: C1 ('MetaCons "TraceMempoolLedgerNotFound" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Point blk))))))) |
Conversions
snapshotFromIS ∷ (HasTxId (GenTx blk), TxLimits blk, GetTip (TickedLedgerState blk)) ⇒ InternalState blk → MempoolSnapshot blk Source #
Create a Mempool Snapshot from a given Internal State of the mempool.
Ticking a ledger state
tickLedgerState ∷ (UpdateLedger blk, ValidateEnvelope blk) ⇒ LedgerConfig blk → ForgeLedgerState blk → (SlotNo, TickedLedgerState blk DiffMK) Source #
Tick the LedgerState
using the given BlockSlot
.