ouroboros-consensus-0.21.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellSafe-Inferred
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.

  • isLedgerState ∷ !(TickedLedgerState blk)

    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 ∷ !(ChainHash blk)

    The tip of the chain that isTxs was validated against

    This comes from the underlying ledger state (tickedLedgerState)

  • 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) ∷ TypeType #

Methods

fromInternalState blk → Rep (InternalState blk) x #

toRep (InternalState blk) x → InternalState blk #

(NoThunks (Validated (GenTx blk)), NoThunks (GenTxId blk), NoThunks (Ticked (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

type Rep (InternalState blk) = D1 ('MetaData "InternalState" "Ouroboros.Consensus.Mempool.Impl.Common" "ouroboros-consensus-0.21.0.0-inplace" 'False) (C1 ('MetaCons "IS" 'PrefixI 'True) ((S1 ('MetaSel ('Just "isTxs") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (TxSeq (TxMeasure blk) (Validated (GenTx blk)))) :*: (S1 ('MetaSel ('Just "isTxIds") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Set (GenTxId blk))) :*: S1 ('MetaSel ('Just "isLedgerState") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (TickedLedgerState blk)))) :*: ((S1 ('MetaSel ('Just "isTip") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (ChainHash blk)) :*: S1 ('MetaSel ('Just "isSlotNo") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SlotNo)) :*: (S1 ('MetaSel ('Just "isLastTicketNo") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TicketNo) :*: S1 ('MetaSel ('Just "isCapacity") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (TxMeasure blk))))))

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 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 blk Source #

Abstract interface needed to run a Mempool.

Constructors

LedgerInterface 

Validation

data ValidationResult invalidTx blk Source #

Constructors

ValidationResult 

Fields

extendVRNew ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ LedgerConfig blk → WhetherToInterveneGenTx blk → ValidationResult (GenTx blk) blk → Either (ApplyTxErr blk) (Validated (GenTx blk), ValidationResult (GenTx blk) blk) Source #

Extend ValidationResult with a new transaction (one which we have not previously validated) that may or may not be valid in this ledger state.

PRECONDITION: vrNewValid is Nothing. In other words: new transactions should be validated one-by-one, not by calling extendVRNew on its result again.

extendVRPrevApplied ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk)) ⇒ LedgerConfig blk → TxTicket (TxMeasure blk) (Validated (GenTx blk)) → ValidationResult (Validated (GenTx blk)) blk → ValidationResult (Validated (GenTx blk)) blk Source #

Extend ValidationResult with a previously validated transaction that may or may not be valid in this ledger state

n.b. Even previously validated transactions may not be valid in a different ledger state; it is still useful to indicate whether we have previously validated this transaction because, if we have, we can utilize reapplyTx rather than applyTx and, therefore, skip things like cryptographic signatures.

revalidateTxsFor Source #

Revalidate the given transactions ([TxTicket (GenTx blk)]), which are all the transactions in the Mempool against the given ticked ledger state, which corresponds to the chain's ledger state.

validateStateFor ∷ (LedgerSupportsMempool blk, HasTxId (GenTx blk), ValidateEnvelope blk) ⇒ MempoolCapacityBytesOverrideLedgerConfig blk → ForgeLedgerState blk → InternalState blk → ValidationResult (Validated (GenTx blk)) blk Source #

Given a (valid) internal state, validate it against the given ledger state and BlockSlot.

When these match the internal state's isTip and isSlotNo, this is very cheap, as the given internal state will already be valid against the given inputs.

When these don't match, the transaction in the internal state will be revalidated (revalidateTxsFor).

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

  • [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

Instances

Instances details
(Show (GenTx blk), Show (Validated (GenTx blk)), Show (GenTxId blk), Show (ApplyTxErr 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)) ⇒ Eq (TraceEventMempool blk) Source # 
Instance details

Defined in Ouroboros.Consensus.Mempool.Impl.Common

Conversions

internalStateFromVRValidationResult invalidTx blk → InternalState blk Source #

Construct internal state from ValidationResult

Discards information about invalid and newly valid transactions

snapshotFromIS ∷ ∀ blk. (HasTxId (GenTx blk), TxLimits blk) ⇒ InternalState blk → MempoolSnapshot blk Source #

Create a Mempool Snapshot from a given Internal State of the mempool.

validationResultFromISInternalState blk → ValidationResult invalidTx blk Source #

Construct a ValidationResult from internal state.

Ticking a ledger state

tickLedgerState ∷ ∀ blk. (UpdateLedger blk, ValidateEnvelope blk) ⇒ LedgerConfig blk → ForgeLedgerState blk → (SlotNo, TickedLedgerState blk) Source #

Tick the LedgerState using the given BlockSlot.