Safe Haskell | None |
---|---|
Language | Haskell2010 |
Ouroboros.Consensus.Mempool.API
Description
Exposes the
datatype which captures the public API of the
Mempool. Also exposes all the types used to interact with said API.Mempool
The interface is then initialized in Ouroboros.Consensus.Mempool.Init with the functions from Ouroboros.Consensus.Mempool.Update and Ouroboros.Consensus.Mempool.Query.
Synopsis
- data Mempool m blk = Mempool {
- tryAddTxs ∷ WhetherToIntervene → [GenTx blk] → m ([MempoolAddTxResult blk], [GenTx blk])
- removeTxs ∷ [GenTxId blk] → m ()
- syncWithLedger ∷ m (MempoolSnapshot blk)
- getSnapshot ∷ STM m (MempoolSnapshot blk)
- getSnapshotFor ∷ ForgeLedgerState blk → STM m (MempoolSnapshot blk)
- getCapacity ∷ STM m MempoolCapacityBytes
- getTxSize ∷ GenTx blk → TxSizeInBytes
- data MempoolAddTxResult blk
- = MempoolTxAdded !(Validated (GenTx blk))
- | MempoolTxRejected !(GenTx blk) !(ApplyTxErr blk)
- addLocalTxs ∷ ∀ m blk. MonadSTM m ⇒ Mempool m blk → [GenTx blk] → m [MempoolAddTxResult blk]
- addTxs ∷ ∀ m blk. MonadSTM m ⇒ Mempool m blk → [GenTx blk] → m [MempoolAddTxResult blk]
- isMempoolTxAdded ∷ MempoolAddTxResult blk → Bool
- isMempoolTxRejected ∷ MempoolAddTxResult blk → Bool
- mempoolTxAddedToMaybe ∷ MempoolAddTxResult blk → Maybe (Validated (GenTx blk))
- data ForgeLedgerState blk
- = ForgeInKnownSlot SlotNo (TickedLedgerState blk)
- | ForgeInUnknownSlot (LedgerState blk)
- data MempoolSnapshot blk = MempoolSnapshot {
- snapshotTxs ∷ [(Validated (GenTx blk), TicketNo)]
- snapshotTxsAfter ∷ TicketNo → [(Validated (GenTx blk), TicketNo)]
- snapshotLookupTx ∷ TicketNo → Maybe (Validated (GenTx blk))
- snapshotHasTx ∷ GenTxId blk → Bool
- snapshotMempoolSize ∷ MempoolSize
- snapshotSlotNo ∷ SlotNo
- snapshotLedgerState ∷ TickedLedgerState blk
- data TicketNo
- type TxSizeInBytes = Word32
- zeroTicketNo ∷ TicketNo
- type MempoolCapacityBytes = MempoolCapacityBytes
- type MempoolCapacityBytesOverride = MempoolCapacityBytesOverride
- type MempoolSize = MempoolSize
- data TraceEventMempool
- computeMempoolCapacity ∷ LedgerSupportsMempool blk ⇒ TickedLedgerState blk → MempoolCapacityBytesOverride → MempoolCapacityBytes
Mempool
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).
When only one thread is operating on the mempool, operations that mutate the state based on the input arguments (tryAddTxs and removeTxs) will produce the same result whether they process transactions one by one or all in one go, so this equality holds:
void (tryAddTxs wti txs) === forM_ txs (tryAddTxs wti . (:[])) void (trAddTxs wti [x,y]) === tryAddTxs wti x >> void (tryAddTxs wti y)
This shows that
is an homomorphism from tryAddTxs
wti++
and >>
,
which informally makes these operations "distributive".
Constructors
Mempool | |
Fields
|
Transaction adding
data MempoolAddTxResult blk Source #
The result of attempting to add a transaction to the mempool.
Constructors
MempoolTxAdded !(Validated (GenTx blk)) | The transaction was added to the mempool. |
MempoolTxRejected !(GenTx blk) !(ApplyTxErr blk) | The transaction was rejected and could not be added to the mempool for the specified reason. |
Instances
(Eq (GenTx blk), Eq (Validated (GenTx blk)), Eq (ApplyTxErr blk)) ⇒ Eq (MempoolAddTxResult blk) Source # | |
Defined in Ouroboros.Consensus.Mempool.API Methods (==) ∷ MempoolAddTxResult blk → MempoolAddTxResult blk → Bool Source # (/=) ∷ MempoolAddTxResult blk → MempoolAddTxResult blk → Bool Source # | |
(Show (GenTx blk), Show (Validated (GenTx blk)), Show (ApplyTxErr blk)) ⇒ Show (MempoolAddTxResult blk) Source # | |
Defined in Ouroboros.Consensus.Mempool.API |
addLocalTxs ∷ ∀ m blk. MonadSTM m ⇒ Mempool m blk → [GenTx blk] → m [MempoolAddTxResult blk] Source #
addTxs ∷ ∀ m blk. MonadSTM m ⇒ Mempool m blk → [GenTx blk] → m [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.
See the necessary invariants on the Haddock for tryAddTxs
.
isMempoolTxAdded ∷ MempoolAddTxResult blk → Bool Source #
isMempoolTxRejected ∷ MempoolAddTxResult blk → Bool Source #
mempoolTxAddedToMaybe ∷ MempoolAddTxResult blk → Maybe (Validated (GenTx blk)) Source #
Ledger state to forge on top of
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 |
Mempool Snapshot
data MempoolSnapshot blk 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
|
Re-exports
We allocate each transaction a (monotonically increasing) ticket number as it enters the mempool.
Instances
Bounded TicketNo Source # | |
Enum TicketNo Source # | |
Defined in Ouroboros.Consensus.Mempool.TxSeq Methods succ ∷ TicketNo → TicketNo Source # pred ∷ TicketNo → TicketNo Source # toEnum ∷ Int → TicketNo Source # fromEnum ∷ TicketNo → Int Source # enumFrom ∷ TicketNo → [TicketNo] Source # enumFromThen ∷ TicketNo → TicketNo → [TicketNo] Source # enumFromTo ∷ TicketNo → TicketNo → [TicketNo] Source # enumFromThenTo ∷ TicketNo → TicketNo → TicketNo → [TicketNo] Source # | |
Eq TicketNo Source # | |
Ord TicketNo Source # | |
Defined in Ouroboros.Consensus.Mempool.TxSeq | |
Show TicketNo Source # | |
NoThunks TicketNo Source # | |
type TxSizeInBytes = Word32 Source #
Transactions are typically not big, but in principle in future we could have ones over 64k large.
zeroTicketNo ∷ TicketNo Source #
The transaction ticket number from which our counter starts.
Deprecated re-exports
type MempoolCapacityBytes = MempoolCapacityBytes Source #
Deprecated: Use Ouroboros.Consensus.Mempool (MempoolCapacityBytes)
type MempoolCapacityBytesOverride = MempoolCapacityBytesOverride Source #
Deprecated: Use Ouroboros.Consensus.Mempool (MempoolCapacityBytesOverride)
type MempoolSize = MempoolSize Source #
Deprecated: Use Ouroboros.Consensus.Mempool (MempoolSize)
data TraceEventMempool Source #
Deprecated: Use Ouroboros.Consensus.Mempool (TraceEventMempool)
computeMempoolCapacity ∷ LedgerSupportsMempool blk ⇒ TickedLedgerState blk → MempoolCapacityBytesOverride → MempoolCapacityBytes Source #
Deprecated: Use Ouroboros.Consensus.Mempool (computeMempoolCapacity)