Skip to content

Test that we never block on adding a tx to an empty mempool #1226

@amesgen

Description

@amesgen

Since #49, adding a tx to the mempool is guarded by a lock


Therefore, while a tx is waiting to be added to the mempool, no other tx can enter the mempool. In order to avoid a deadlock, it must be guaranteed that adding a tx can not block forever. Such a deadlock is problematic both for the local node (as a restart is necessary), as well as for the entire network, as only empty blocks might otherwise be minted.

This requirement can be deduced from the following two properties:

  1. Transactions are removed from the mempool over time due to transactions becoming invalid (most commonly, due to being included in a minted block).
  2. Add a transaction to an empty mempool never blocks.

As the mempool will eventually become empty, no transaction can block forever.

The goal of this issue is to test the second property.


At the moment (6a8def9), this property is true for the block size capacity due to #21: As the capacity of the mempool is positive, the conditional mempoolsize < mempoolcapacity is always true when adding a tx to an empty mempool.

See #1225 for a recent change restoring this behavior for the ad-hoc reference scripts size limit (added in #1166) after #1168.

As of #1175, this property will be guaranteed by performing the per-tx size checks as part of the check whether to add the tx to the mempool, as the per-tx limit is smaller than the per-block limit, and the mempool capacity encompasses at least one block.


One strategy to test this would be to enrich the TestBlock used in Test.Consensus.Mempool with a per-tx size limit, and then add a simple test which tries to add overly large txs to an empty mempool.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions