ouroboros-consensus-0.26.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Mempool.Impl.Common

Description

Synopsis

Internal state

data InternalState blk Source #

Internal state in the mempool

Constructors

IS 

Fields

  • isTxs ∷ !(TxSeq (TxMeasure blk) (Validated (GenTx blk)))

    Transactions currently in the mempool

    NOTE: the total size of the transactions in isTxs may exceed the current capacity (isCapacity). When the capacity computed from the ledger has shrunk, we don't remove transactions from the Mempool to satisfy the new lower limit. We let the transactions get removed in the normal way: by becoming invalid w.r.t. the updated ledger state. We treat a Mempool over capacity in the same way as a Mempool at capacity.

  • isTxIds ∷ !(Set (GenTxId blk))

    The cached IDs of transactions currently in the mempool.

    This allows one to more quickly lookup transactions by ID from a MempoolSnapshot (see snapshotHasTx).

    This should always be in-sync with the transactions in isTxs.

  • isTxKeys ∷ !(LedgerTables (LedgerState blk) KeysMK)

    The cached set of keys needed for the transactions currently in the mempool.

    INVARIANT: isTxKeys == foldMap (getTransactionKeySets . txForgetValidated) $ toList isTxs

  • isTxValues ∷ !(LedgerTables (LedgerState blk) ValuesMK)

    The cached values corresponding to reading isTxKeys at isLedgerState. These values can be used unless we switch to a different ledger state. It usually happens in the forging loop that the same ledger state that was in isLedgerState is used, but ticked to a different slot so we can reuse these values.

    INVARIANT: isTxValues should be equal to getForkerAtTarget ... isLedgerState >>= f -> forkerReadTables f isTxKeys

  • isLedgerState ∷ !(TickedLedgerState blk DiffMK)

    The cached ledger state after applying the transactions in the Mempool against the chain's ledger state. New transactions will be validated against this ledger.

    INVARIANT: isLedgerState is the ledger resulting from applying the transactions in isTxs against the ledger identified isTip as tip.

  • isTip ∷ !(Point blk)

    The tip of the chain that isTxs was validated against

  • isSlotNo ∷ !SlotNo

    The most recent SlotNo that isTxs was validated against

    Note in particular that if the mempool is revalidated against a state S at slot s, then the state will be ticked (for now to the successor slot, see tickLedgerState) and isSlotNo will be set to succ s, which is different from the slot of the original ledger state, which will remain in isTip.

  • isLastTicketNo ∷ !TicketNo

    The mempool TicketNo counter.

    See vrLastTicketNo for more information.

  • isCapacity ∷ !(TxMeasure blk)

    Current maximum capacity of the Mempool. Result of computeMempoolCapacity using the current chain's TickedLedgerState.

    NOTE: this does not correspond to isLedgerState, which is the TickedLedgerState after applying the transactions in the Mempool. There might be a transaction in the Mempool triggering a change in the maximum transaction capacity of a block, which would change the Mempool's capacity (unless overridden). We don't want the Mempool's capacity to depend on its contents. The mempool is assuming all its transactions will be in the next block. So any changes caused by that block will take effect after applying it and will only affect the next block.

Instances

Instances details
Generic (InternalState blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Mempool.Impl.Common

Associated Types

type Rep (InternalState blk) 
Instance details

Defined in Ouroboros.Consensus.Mempool.Impl.Common

Methods

fromInternalState blk → Rep (InternalState blk) x #

toRep (InternalState blk) x → InternalState blk #

(NoThunks (Validated (GenTx blk)), NoThunks (GenTxId blk), NoThunks (TickedLedgerState blk DiffMK), NoThunks (TxIn (LedgerState blk)), NoThunks (TxOut (LedgerState blk)), NoThunks (TxMeasure blk), StandardHash blk, Typeable blk) ⇒ NoThunks (InternalState blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Mempool.Impl.Common

type Rep (InternalState blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Mempool.Impl.Common

isMempoolSizeTxLimits 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 ∷ TypeType) 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.

Ledger interface

data LedgerInterface (m ∷ TypeType) blk Source #

Abstract interface needed to run a Mempool.

Constructors

LedgerInterface 

Fields

chainDBLedgerInterface ∷ ∀ (m ∷ TypeType) blk. IOLike m ⇒ ChainDB m blk → LedgerInterface m blk Source #

Create a LedgerInterface from a ChainDB.

Validation

data RevalidateTxsResult blk Source #

Constructors

RevalidateTxsResult 

Fields

computeSnapshot Source #

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

isLastTicketNo and vrLastTicketNo

→ [TxTicket (TxMeasure blk) (Validated (GenTx blk))] 
MempoolSnapshot blk 

Compute snapshot is largely the same as revalidate the transactions but we ignore the diffs.

revalidateTxsFor Source #

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

isLastTicketNo and vrLastTicketNo

→ [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 txMeasure before this function.

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

  • (Validated (GenTx blk))

    New, valid transaction that was added to the Mempool.

  • MempoolSize

    The size of the Mempool before adding the transaction.

  • MempoolSize

    The size of the Mempool after adding the transaction.

TraceMempoolRejectedTx 

Fields

  • (GenTx blk)

    New, invalid transaction thas was rejected and thus not added to the Mempool.

  • (ApplyTxErr blk)

    The reason for rejecting the transaction.

  • MempoolSize

    The current size of the Mempool.

TraceMempoolRemoveTxs 

Fields

  • [(Validated (GenTx blk), ApplyTxErr blk)]

    Previously valid transactions that are no longer valid because of changes in the ledger state (details are in the provided ApplyTxErr). These transactions have been removed from the Mempool.

  • MempoolSize

    The current size of the Mempool.

TraceMempoolManuallyRemovedTxs 

Fields

  • (NonEmpty (GenTxId blk))

    Transactions that have been manually removed from the Mempool.

  • [Validated (GenTx blk)]

    Previously valid transactions that are no longer valid because they dependend on transactions that were manually removed from the Mempool. These transactions have also been removed from the Mempool.

    This list shares not transactions with the list of manually removed transactions.

  • MempoolSize

    The current size of the Mempool.

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

Instances details
Generic (TraceEventMempool blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Mempool.Impl.Common

Associated Types

type Rep (TraceEventMempool blk) 
Instance details

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 ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Validated (GenTx blk))) :*: (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize))) :+: C1 ('MetaCons "TraceMempoolRejectedTx" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (GenTx blk)) :*: (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (ApplyTxErr blk)) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize)))) :+: (C1 ('MetaCons "TraceMempoolRemoveTxs" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Validated (GenTx blk), ApplyTxErr blk)]) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize)) :+: C1 ('MetaCons "TraceMempoolManuallyRemovedTxs" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (NonEmpty (GenTxId blk))) :*: (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Validated (GenTx blk)]) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize))))) :+: ((C1 ('MetaCons "TraceMempoolSynced" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EnclosingTimed)) :+: C1 ('MetaCons "TraceMempoolSyncNotNeeded" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Point blk)))) :+: (C1 ('MetaCons "TraceMempoolAttemptingAdd" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (GenTx blk))) :+: (C1 ('MetaCons "TraceMempoolLedgerFound" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Point blk))) :+: C1 ('MetaCons "TraceMempoolLedgerNotFound" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Point blk)))))))

Methods

fromTraceEventMempool blk → Rep (TraceEventMempool blk) x #

toRep (TraceEventMempool blk) x → TraceEventMempool blk #

(Show (GenTx blk), Show (Validated (GenTx blk)), Show (GenTxId blk), Show (ApplyTxErr blk), StandardHash blk) ⇒ Show (TraceEventMempool blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Mempool.Impl.Common

(Eq (GenTx blk), Eq (Validated (GenTx blk)), Eq (GenTxId blk), Eq (ApplyTxErr blk), StandardHash blk) ⇒ Eq (TraceEventMempool blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Mempool.Impl.Common

type Rep (TraceEventMempool blk) Source # 
Instance details

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 ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Validated (GenTx blk))) :*: (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize))) :+: C1 ('MetaCons "TraceMempoolRejectedTx" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (GenTx blk)) :*: (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (ApplyTxErr blk)) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize)))) :+: (C1 ('MetaCons "TraceMempoolRemoveTxs" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Validated (GenTx blk), ApplyTxErr blk)]) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize)) :+: C1 ('MetaCons "TraceMempoolManuallyRemovedTxs" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (NonEmpty (GenTxId blk))) :*: (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Validated (GenTx blk)]) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MempoolSize))))) :+: ((C1 ('MetaCons "TraceMempoolSynced" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EnclosingTimed)) :+: C1 ('MetaCons "TraceMempoolSyncNotNeeded" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Point blk)))) :+: (C1 ('MetaCons "TraceMempoolAttemptingAdd" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (GenTx blk))) :+: (C1 ('MetaCons "TraceMempoolLedgerFound" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Point blk))) :+: C1 ('MetaCons "TraceMempoolLedgerNotFound" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe 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.