| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Mempool.API
Contents
Synopsis
- data Mempool m blk idx = Mempool {
- tryAddTxs :: [GenTx blk] -> m ([(GenTx blk, MempoolAddTxResult blk)], [GenTx blk])
- removeTxs :: [GenTxId blk] -> m ()
- syncWithLedger :: m (MempoolSnapshot blk idx)
- getSnapshot :: STM m (MempoolSnapshot blk idx)
- getSnapshotFor :: ForgeLedgerState blk -> STM m (MempoolSnapshot blk idx)
- getCapacity :: STM m MempoolCapacityBytes
- getTxSize :: GenTx blk -> TxSizeInBytes
- zeroIdx :: idx
- addTxs :: forall m blk idx. MonadSTM m => Mempool m blk idx -> [GenTx blk] -> m [(GenTx blk, MempoolAddTxResult blk)]
- data ForgeLedgerState blk
- = ForgeInKnownSlot SlotNo (TickedLedgerState blk)
- | ForgeInUnknownSlot (LedgerState blk)
- newtype MempoolCapacityBytes = MempoolCapacityBytes {}
- data MempoolSnapshot blk idx = MempoolSnapshot {
- snapshotTxs :: [(GenTx blk, idx)]
- snapshotTxsAfter :: idx -> [(GenTx blk, idx)]
- snapshotTxsForSize :: Word32 -> [(GenTx blk, idx)]
- snapshotLookupTx :: idx -> Maybe (GenTx blk)
- snapshotHasTx :: GenTxId blk -> Bool
- snapshotMempoolSize :: MempoolSize
- snapshotSlotNo :: SlotNo
- snapshotLedgerState :: TickedLedgerState blk
- data MempoolAddTxResult blk
- = MempoolTxAdded
- | MempoolTxRejected !(ApplyTxErr blk)
- isMempoolTxAdded :: MempoolAddTxResult blk -> Bool
- isMempoolTxRejected :: MempoolAddTxResult blk -> Bool
- data MempoolSize = MempoolSize {
- msNumTxs :: !Word32
- msNumBytes :: !Word32
- data TraceEventMempool blk
- = TraceMempoolAddedTx !(GenTx blk) !MempoolSize !MempoolSize
- | TraceMempoolRejectedTx !(GenTx blk) !(ApplyTxErr blk) !MempoolSize
- | TraceMempoolRemoveTxs ![GenTx blk] !MempoolSize
- | TraceMempoolManuallyRemovedTxs ![GenTxId blk] ![GenTx blk] !MempoolSize
- type TxSizeInBytes = Word32
Documentation
data Mempool m blk idx Source #
Mempool
The mempool is the set of transactions that should be included in the next block. In principle this is a set of all the transactions that we receive from our peers. In order to avoid flooding the network with invalid transactions, however, we only want to keep valid transactions in the mempool. That raises the question: valid with respect to which ledger state?
We opt for a very simple answer to this: the mempool will be interpreted as a list of transactions; which are validated strictly in order, starting from the current ledger state. This has a number of advantages:
- It's simple to implement and it's efficient. In particular, no search for a valid subset is ever required.
- When producing a block, we can simply take the longest possible prefix of transactions that fits in a block.
- It supports wallets that submit dependent transactions (where later transaction depends on outputs from earlier ones).
Constructors
| Mempool | |
Fields
| |
addTxs :: forall m blk idx. MonadSTM m => Mempool m blk idx -> [GenTx blk] -> m [(GenTx blk, MempoolAddTxResult blk)] Source #
Wrapper around implTryAddTxs that blocks until all transaction have
either been added to the Mempool or rejected.
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.
POSTCONDITON: > processed <- addTxs mpEnv txs > map fst processed == txs
data ForgeLedgerState blk Source #
The ledger state wrt to which we should produce a block
The transactions in the mempool will be part of the body of a block, but a block consists of a header and a body, and the full validation of a block consists of first processing its header and only then processing the body. This is important, because processing the header may change the state of the ledger: the update system might be updated, scheduled delegations might be applied, etc., and such changes should take effect before we validate any transactions.
Constructors
| ForgeInKnownSlot SlotNo (TickedLedgerState blk) | The slot number of the block is known This will only be the case when we realized that we are the slot leader
and we are actually producing a block. It is the caller's responsibility
to call |
| ForgeInUnknownSlot (LedgerState blk) | The slot number of the block is not yet known When we are validating transactions before we know in which block they
will end up, we have to make an assumption about which slot number to use
for |
newtype MempoolCapacityBytes Source #
Represents the maximum number of bytes worth of transactions that a
Mempool can contain.
Constructors
| MempoolCapacityBytes | |
Fields | |
Instances
| Eq MempoolCapacityBytes Source # | |
Defined in Ouroboros.Consensus.Mempool.API Methods (==) :: MempoolCapacityBytes -> MempoolCapacityBytes -> Bool # (/=) :: MempoolCapacityBytes -> MempoolCapacityBytes -> Bool # | |
| Show MempoolCapacityBytes Source # | |
Defined in Ouroboros.Consensus.Mempool.API Methods showsPrec :: Int -> MempoolCapacityBytes -> ShowS # show :: MempoolCapacityBytes -> String # showList :: [MempoolCapacityBytes] -> ShowS # | |
| NoThunks MempoolCapacityBytes Source # | |
Defined in Ouroboros.Consensus.Mempool.API | |
data MempoolSnapshot blk idx Source #
A pure snapshot of the contents of the mempool. It allows fetching information about transactions in the mempool, and fetching individual transactions.
This uses a transaction sequence number type for identifying transactions within the mempool sequence. The sequence number is local to this mempool, unlike the transaction hash. This allows us to ask for all transactions after a known sequence number, to get new transactions. It is also used to look up individual transactions.
Note that it is expected that getTx will often return Nothing
even for tx sequence numbers returned in previous snapshots. This happens
when the transaction has been removed from the mempool between snapshots.
Constructors
| MempoolSnapshot | |
Fields
| |
data MempoolAddTxResult blk Source #
The result of attempting to add a transaction to the mempool.
Constructors
| MempoolTxAdded | The transaction was added to the mempool. |
| MempoolTxRejected !(ApplyTxErr blk) | The transaction was rejected and could not be added to the mempool for the specified reason. |
Instances
| Eq (ApplyTxErr blk) => Eq (MempoolAddTxResult blk) Source # | |
Defined in Ouroboros.Consensus.Mempool.API Methods (==) :: MempoolAddTxResult blk -> MempoolAddTxResult blk -> Bool # (/=) :: MempoolAddTxResult blk -> MempoolAddTxResult blk -> Bool # | |
| Show (ApplyTxErr blk) => Show (MempoolAddTxResult blk) Source # | |
Defined in Ouroboros.Consensus.Mempool.API Methods showsPrec :: Int -> MempoolAddTxResult blk -> ShowS # show :: MempoolAddTxResult blk -> String # showList :: [MempoolAddTxResult blk] -> ShowS # | |
isMempoolTxAdded :: MempoolAddTxResult blk -> Bool Source #
isMempoolTxRejected :: MempoolAddTxResult blk -> Bool Source #
data MempoolSize Source #
The size of a mempool.
Constructors
| MempoolSize | |
Fields
| |
Instances
| Eq MempoolSize Source # | |
Defined in Ouroboros.Consensus.Mempool.API | |
| Show MempoolSize Source # | |
Defined in Ouroboros.Consensus.Mempool.API Methods showsPrec :: Int -> MempoolSize -> ShowS # show :: MempoolSize -> String # showList :: [MempoolSize] -> ShowS # | |
| Semigroup MempoolSize Source # | |
Defined in Ouroboros.Consensus.Mempool.API Methods (<>) :: MempoolSize -> MempoolSize -> MempoolSize # sconcat :: NonEmpty MempoolSize -> MempoolSize # stimes :: Integral b => b -> MempoolSize -> MempoolSize # | |
| Monoid MempoolSize Source # | |
Defined in Ouroboros.Consensus.Mempool.API Methods mempty :: MempoolSize # mappend :: MempoolSize -> MempoolSize -> MempoolSize # mconcat :: [MempoolSize] -> MempoolSize # | |
data TraceEventMempool blk Source #
Events traced by the Mempool.
Constructors
| TraceMempoolAddedTx | |
Fields
| |
| TraceMempoolRejectedTx | |
Fields
| |
| TraceMempoolRemoveTxs | |
Fields
| |
| TraceMempoolManuallyRemovedTxs | |
Fields
| |
Instances
| (Eq (GenTx blk), Eq (GenTxId blk), Eq (ApplyTxErr blk)) => Eq (TraceEventMempool blk) Source # | |
Defined in Ouroboros.Consensus.Mempool.API Methods (==) :: TraceEventMempool blk -> TraceEventMempool blk -> Bool # (/=) :: TraceEventMempool blk -> TraceEventMempool blk -> Bool # | |
| (Show (GenTx blk), Show (GenTxId blk), Show (ApplyTxErr blk)) => Show (TraceEventMempool blk) Source # | |
Defined in Ouroboros.Consensus.Mempool.API Methods showsPrec :: Int -> TraceEventMempool blk -> ShowS # show :: TraceEventMempool blk -> String # showList :: [TraceEventMempool blk] -> ShowS # | |
Re-exports
type TxSizeInBytes = Word32 #