ouroboros-consensus-0.1.0.1: Consensus layer for the Ouroboros blockchain protocol
Safe Haskell None
Language Haskell2010

Ouroboros.Consensus.Mempool.Impl.Types

Description

Types required for implementing the Mempool.

Synopsis

Internal State

data InternalState blk Source #

Internal state in the mempool

Constructors

IS

Fields

  • isTxs :: !( TxSeq ( 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

    This comes from applyChainTick ( tickedSlotNo ).

  • isLastTicketNo :: ! TicketNo

    The mempool TicketNo counter.

    See vrLastTicketNo for more information.

  • isCapacity :: ! MempoolCapacityBytes

    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.Types

Associated Types

type Rep ( InternalState blk) :: Type -> Type Source #

( NoThunks ( Validated ( GenTx blk)), NoThunks ( GenTxId blk), NoThunks ( Ticked ( LedgerState blk)), StandardHash blk, Typeable blk) => NoThunks ( InternalState blk) Source #
Instance details

Defined in Ouroboros.Consensus.Mempool.Impl.Types

type Rep ( InternalState blk) Source #
Instance details

Defined in Ouroboros.Consensus.Mempool.Impl.Types

isMempoolSize :: 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.

Validation result

data ValidationResult invalidTx blk Source #

Constructors

ValidationResult

Fields

extendVRNew :: ( LedgerSupportsMempool blk, HasTxId ( GenTx blk)) => LedgerConfig blk -> ( GenTx blk -> TxSizeInBytes ) -> WhetherToIntervene -> GenTx 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 ( 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.

validateIS :: ( LedgerSupportsMempool blk, HasTxId ( GenTx blk), ValidateEnvelope blk) => InternalState blk -> LedgerState blk -> LedgerConfig blk -> MempoolCapacityBytesOverride -> ValidationResult ( Validated ( GenTx blk)) blk Source #

Validate the internal state against the current ledger state and the given BlockSlot , revalidating if necessary.

validateStateFor :: ( LedgerSupportsMempool blk, HasTxId ( GenTx blk), ValidateEnvelope blk) => MempoolCapacityBytesOverride -> LedgerConfig 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 ).

Tick ledger state

Conversions

internalStateFromVR :: ValidationResult invalidTx blk -> InternalState blk Source #

Construct internal state from ValidationResult

Discards information about invalid and newly valid transactions