| 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 (TxMeasureWithDiffTime blk) (ValidatedTxWithDiffs blk))
- isTxIds ∷ !(Set (GenTxId blk))
- isTxKeys ∷ !(LedgerTables blk KeysMK)
- isTxValues ∷ !(LedgerTables blk ValuesMK)
- isLedgerState ∷ !(TickedLedgerState blk DiffMK)
- isTip ∷ !(Point blk)
- isSlotNo ∷ !SlotNo
- isLastTicketNo ∷ !TicketNo
- isCapacity ∷ !(TxMeasure blk)
- isRemovalCounter ∷ !Word64
- data ValidatedTxWithDiffs blk = ValidatedTxWithDiffs {
- validatedTx ∷ !(Validated (GenTx blk))
- validatedTxDiffs ∷ !(LedgerTables blk DiffMK)
- isMempoolSize ∷ TxLimits blk ⇒ InternalState blk → MempoolSize
- data MempoolEnv (m ∷ Type → Type) blk = MempoolEnv {
- mpEnvLedger ∷ LedgerInterface m blk
- mpEnvForker ∷ StrictMVar m (ReadOnlyForker m LedgerState blk)
- mpEnvLedgerCfg ∷ LedgerConfig blk
- mpEnvStateVar ∷ StrictTMVar m (InternalState blk)
- mpEnvAddTxsRemoteFifo ∷ StrictMVar m ()
- mpEnvAddTxsAllFifo ∷ StrictMVar m ()
- mpEnvTracer ∷ Tracer m (TraceEventMempool blk)
- mpEnvCapacityOverride ∷ MempoolCapacityBytesOverride
- mpEnvTimeoutConfig ∷ Maybe MempoolTimeoutConfig
- initMempoolEnv ∷ (IOLike m, LedgerSupportsMempool blk, ValidateEnvelope blk) ⇒ LedgerInterface m blk → LedgerConfig blk → MempoolCapacityBytesOverride → Maybe MempoolTimeoutConfig → Tracer m (TraceEventMempool blk) → m (MempoolEnv m blk)
- newtype LedgerInterface (m ∷ Type → Type) blk = LedgerInterface {
- getCurrentLedgerState ∷ STM m (MempoolLedgerDBView m blk)
- data MempoolLedgerDBView (m ∷ Type → Type) blk = MempoolLedgerDBView {
- mldViewState ∷ LedgerState blk EmptyMK
- mldViewGetForker ∷ m (Either GetForkerError (ReadOnlyForker m LedgerState blk))
- chainDBLedgerInterface ∷ ∀ (m ∷ Type → Type) blk. (IOLike m, IsLedger LedgerState blk) ⇒ ChainDB m blk → LedgerInterface m blk
- data RevalidateTxsResult blk = RevalidateTxsResult {
- newInternalState ∷ !(InternalState blk)
- removedTxs ∷ ![Invalidated blk]
- computeSnapshot ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ LedgerConfig blk → SlotNo → TickedLedgerState blk DiffMK → LedgerTables blk ValuesMK → [TxTicket (TxMeasureWithDiffTime blk) (Validated (GenTx blk))] → MempoolSnapshot blk
- revalidateTxsFor ∷ (Monad m, LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ ReadOnlyForker m LedgerState blk → MempoolCapacityBytesOverride → LedgerConfig blk → SlotNo → TickedLedgerState blk DiffMK → TicketNo → Word64 → [TxTicket (TxMeasureWithDiffTime blk) (ValidatedTxWithDiffs blk)] → m (RevalidateTxsResult blk)
- revalidateTxsFor' ∷ (Monad m, LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ ReadOnlyForker m LedgerState blk → MempoolCapacityBytesOverride → LedgerConfig blk → SlotNo → RevalidateTxsResult blk → TicketNo → [TxTicket (TxMeasureWithDiffTime blk) (ValidatedTxWithDiffs blk)] → m (RevalidateTxsResult blk)
- validateNewTransaction ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ LedgerConfig blk → WhetherToIntervene → GenTx blk → TxMeasure blk → LedgerTables blk ValuesMK → TickedLedgerState blk ValuesMK → InternalState blk → (Either (ApplyTxErr blk) (Validated (GenTx blk), LedgerTables blk DiffMK), DiffTimeMeasure → InternalState blk)
- data MempoolRejectionDetails
- data TraceEventMempool blk
- = TraceMempoolAddedTx (Validated (GenTx blk)) MempoolSize MempoolSize
- | TraceMempoolRejectedTx (GenTx blk) (ApplyTxErr blk) MempoolRejectionDetails MempoolSize
- | TraceMempoolRemoveTxs [(GenTx blk, ApplyTxErr blk)] MempoolSize
- | TraceMempoolManuallyRemovedTxs (NonEmpty (GenTxId blk)) [GenTx blk] MempoolSize
- | TraceMempoolSynced EnclosingTimed
- | TraceMempoolSyncNotNeeded (Point blk)
- | TraceMempoolAttemptingAdd (GenTx blk)
- | TraceMempoolTipMovedBetweenSTMBlocks
- jsonMempoolRejectionDetails ∷ MempoolRejectionDetails → Value
- snapshotFromIS ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ InternalState blk → MempoolSnapshot blk
- snapshotFromValidTxs ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ [TxTicket (TxMeasureWithDiffTime blk) (Validated (GenTx blk))] → Point blk → SlotNo → 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
data ValidatedTxWithDiffs blk Source #
We cache the differences produced by validating each transaction, as the current differences in UTxO-HD do not depend on which block the transaction was validated. This means that these differences cannot be "stale", as long as the transaction is considered, the differences will be the same. If we extend UTxO-HD to consider more differences, this might be violated and we will have to reconsider what we can cache and what we can't.
Constructors
| ValidatedTxWithDiffs | |
Fields
| |
Instances
| Generic (ValidatedTxWithDiffs blk) Source # | |||||
Defined in Ouroboros.Consensus.Mempool.Impl.Common Associated Types
Methods from ∷ ValidatedTxWithDiffs blk → Rep (ValidatedTxWithDiffs blk) x # to ∷ Rep (ValidatedTxWithDiffs blk) x → ValidatedTxWithDiffs blk # | |||||
| (NoThunks (Validated (GenTx blk)), NoThunks (TxIn blk), NoThunks (TxOut blk)) ⇒ NoThunks (ValidatedTxWithDiffs blk) Source # | |||||
Defined in Ouroboros.Consensus.Mempool.Impl.Common | |||||
| type Rep (ValidatedTxWithDiffs blk) Source # | |||||
Defined in Ouroboros.Consensus.Mempool.Impl.Common type Rep (ValidatedTxWithDiffs blk) = D1 ('MetaData "ValidatedTxWithDiffs" "Ouroboros.Consensus.Mempool.Impl.Common" "ouroboros-consensus-4.0.0.0-inplace" 'False) (C1 ('MetaCons "ValidatedTxWithDiffs" 'PrefixI 'True) (S1 ('MetaSel ('Just "validatedTx") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Validated (GenTx blk))) :*: S1 ('MetaSel ('Just "validatedTxDiffs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (LedgerTables blk DiffMK)))) | |||||
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 → Maybe MempoolTimeoutConfig → Tracer m (TraceEventMempool blk) → m (MempoolEnv m blk) Source #
Ledger interface
newtype LedgerInterface (m ∷ Type → Type) blk Source #
Abstract interface needed to run a Mempool.
Constructors
| LedgerInterface | |
Fields
| |
data MempoolLedgerDBView (m ∷ Type → Type) blk Source #
Constructors
| MempoolLedgerDBView | |
Fields
| |
chainDBLedgerInterface ∷ ∀ (m ∷ Type → Type) blk. (IOLike m, IsLedger LedgerState blk) ⇒ 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)) | |
| ⇒ LedgerConfig blk | |
| → SlotNo | |
| → TickedLedgerState blk DiffMK | The ticked ledger state againt which txs will be revalidated |
| → LedgerTables blk ValuesMK | The tables with all the inputs for the transactions |
| → [TxTicket (TxMeasureWithDiffTime blk) (Validated (GenTx blk))] | |
| → MempoolSnapshot blk |
Compute snapshot is largely the same as revalidate the transactions but we ignore the diffs.
Arguments
| ∷ (Monad m, LedgerSupportsMempool blk, HasTxId (GenTx blk)) | |
| ⇒ ReadOnlyForker m LedgerState blk | The forker to read the transactions' inputs from. |
| → MempoolCapacityBytesOverride | |
| → LedgerConfig blk | |
| → SlotNo | |
| → TickedLedgerState blk DiffMK | The ticked ledger state againt which txs will be revalidated |
| → TicketNo |
|
| → Word64 | The removal generation to stamp on the result (see |
| → [TxTicket (TxMeasureWithDiffTime blk) (ValidatedTxWithDiffs blk)] | |
| → m (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.
Arguments
| ∷ (Monad m, LedgerSupportsMempool blk, HasTxId (GenTx blk)) | |
| ⇒ ReadOnlyForker m LedgerState blk | The forker to read the delta txs' inputs from. |
| → MempoolCapacityBytesOverride | |
| → LedgerConfig blk | |
| → SlotNo | |
| → RevalidateTxsResult blk | The result so far: its state is extended in place with the delta (no full
rebuild), and its removed txs are carried forward so the loop accumulates
them without any bookkeeping of its own. The candidate already carries the
base it was revalidated against (via |
| → TicketNo | The new |
| → [TxTicket (TxMeasureWithDiffTime blk) (ValidatedTxWithDiffs blk)] | The delta txs, in ascending |
| → m (RevalidateTxsResult blk) |
The general revalidation step: reapply a delta of already-validated txs on
top of the candidate carried in the given RevalidateTxsResult, without
reprocessing what it already holds, appending any newly-removed txs to those
carried in. revalidateTxsFor is the special case that starts from an empty
candidate.
deltaTxTickets are the txs added since the candidate was revalidated, in
ascending ticket order. Their inputs are read from frk here rather than by
the caller — the keys to read are derived from the txs anyway. Seeding the
delta from the candidate's post-reapply ledger (isLedgerState) lets a sync
shrink its work off the lock and hold the lock only for a small final delta
(implSyncWithLedger).
validateNewTransaction Source #
Arguments
| ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) | |
| ⇒ LedgerConfig blk | |
| → WhetherToIntervene | |
| → GenTx blk | |
| → TxMeasure blk | |
| → LedgerTables 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), LedgerTables blk DiffMK), DiffTimeMeasure → 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 MempoolRejectionDetails Source #
Constructors
| MempoolRejectedByLedger | The ledger's |
| MempoolRejectedByTimeoutSoft !DiffTime | The tx violated It did not violate |
Instances
| Eq MempoolRejectionDetails Source # | |
Defined in Ouroboros.Consensus.Mempool.Impl.Common | |
| Show MempoolRejectionDetails Source # | |
Defined in Ouroboros.Consensus.Mempool.Impl.Common | |
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. |
| TraceMempoolTipMovedBetweenSTMBlocks | When performing a re-sync we will read the LedgerDB tip twice. This trace will be emitted if in between those two steps the LedgerDB moved to an alternative fork. It is completely innocuous but we would like to double check that it happens very rarely or almost never. |
Instances
| (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 # | |||||
| 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 # | |||||
| 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-4.0.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 MempoolRejectionDetails) :*: S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize)))) :+: (C1 ('MetaCons "TraceMempoolRemoveTxs" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(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 [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 "TraceMempoolTipMovedBetweenSTMBlocks" 'PrefixI 'False) (U1 ∷ Type → Type)))) | |||||
Conversions
snapshotFromIS ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ InternalState blk → MempoolSnapshot blk Source #
snapshotFromValidTxs ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ [TxTicket (TxMeasureWithDiffTime blk) (Validated (GenTx blk))] → Point blk → SlotNo → MempoolSnapshot blk Source #
Create a Mempool Snapshot from a list of validated transactions.
Unlike snapshotFromIS this has to build the transaction sequence and the
set of transaction ids, so it is O(n) in the number of transactions and
computes the txid of every one of them. Only use it when there is no internal
state to take those from, for example after revalidating transactions in
computeSnapshot.
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.