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



Pure side of the Mempool implementation.

Operations are performed in a pure style returning data types that model the control flow through the operation and can then be interpreted to perform the actual STM/IO operations.



implTryAddTxs Source #


:: forall m blk. ( MonadSTM m, LedgerSupportsMempool blk, HasTxId ( GenTx blk))
=> StrictTVar m ( InternalState blk)

The InternalState TVar.

-> LedgerConfig blk

The configuration of the ledger.

-> ( GenTx blk -> TxSizeInBytes )

The function to calculate the size of a transaction.

-> Tracer m ( TraceEventMempool blk)

The tracer.

-> WhetherToIntervene
-> [ GenTx blk]

The list of transactions to add to the mempool.

-> m ([ MempoolAddTxResult blk], [ GenTx blk])

Add a list of transactions (oldest to newest) by interpreting a TryAddTxs from pureTryAddTxs .

This function returns two lists: the transactions that were added or rejected, and the transactions that could not yet be added, because the Mempool capacity was reached. See addTxs for a function that blocks in case the Mempool capacity is reached.

Transactions are added one by one, updating the Mempool each time one was added successfully.

See the necessary invariants on the Haddock for tryAddTxs .

This function does not sync the Mempool contents with the ledger state in case the latter changes, it relies on the background thread to do that.

INVARIANT: The code needs that read and writes on the state are coupled together or inconsistencies will arise. To ensure that STM transactions are short, each iteration of the helper function is a separate STM transaction.

pureGetSnapshotFor :: forall blk. ( LedgerSupportsMempool blk, HasTxId ( GenTx blk), ValidateEnvelope blk) => LedgerConfig blk -> ForgeLedgerState blk -> MempoolCapacityBytesOverride -> InternalState blk -> MempoolSnapshot blk TicketNo Source #

Get a snapshot of the mempool state that is valid with respect to the given ledger state

pureRemoveTxs :: ( LedgerSupportsMempool blk, HasTxId ( GenTx blk), ValidateEnvelope blk) => LedgerConfig blk -> MempoolCapacityBytesOverride -> [ GenTxId blk] -> InternalState blk -> LedgerState blk -> RemoveTxs blk Source #

Craft a RemoveTxs that manually removes the given transactions from the mempool, returning inside it an updated InternalState.

pureSyncWithLedger :: ( LedgerSupportsMempool blk, HasTxId ( GenTx blk), ValidateEnvelope blk) => InternalState blk -> LedgerState blk -> LedgerConfig blk -> MempoolCapacityBytesOverride -> SyncWithLedger blk Source #

Create a SyncWithLedger value representing the values that will need to be stored for committing this synchronization with the Ledger.

See the documentation of runSyncWithLedger for more context.

runRemoveTxs :: forall m blk. IOLike m => StrictTVar m ( InternalState blk) -> RemoveTxs blk -> STM m ( Maybe ( TraceEventMempool blk)) Source #

Intepret a RemoveTxs with the resulting values produced by manually removing the transactions given to pureRemoveTxs from the mempool.

runSyncWithLedger :: forall m blk. IOLike m => StrictTVar m ( InternalState blk) -> SyncWithLedger blk -> STM m ( Maybe ( TraceEventMempool blk), MempoolSnapshot blk TicketNo ) Source #

Intepret a SyncWithLedger value produced by syncing the transactions in the mempool with the current ledger state of the ChainDB .

The transactions that exist within the mempool will be revalidated against the current ledger state. Transactions which are found to be invalid with respect to the current ledger state, will be dropped from the mempool, whereas valid transactions will remain.

n.b. in our current implementation, when one opens a mempool, we spawn a thread which performs this action whenever the ChainDB tip point changes.


implSnapshotFromIS :: HasTxId ( GenTx blk) => InternalState blk -> MempoolSnapshot blk TicketNo Source #

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