consensus-test
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Consensus.Mempool.Fairness

Description

Tests fairness aspects of the mempool.

See testTxSizeFairness for more details on the tests we run in this module.

Synopsis

Documentation

testTxSizeFairness ∷ TestParams → IO () Source #

Test if the mempool treats small and large transactions in the same way.

We run the following test:

  • Given a mempool mp.
  • Concurrently:
  • Run N threads that add small transactions to mp.
  • Run N threads that add large transactions to mp.
  • Remove transactions from mp one by one, with a small delay between removals. Collect the removed transactions.

We give the threads that add small transactions a head start to make sure that the mempool fills up with small transactions. In this way the thread that removes transactions one by one will remove small transactions first. Then, if the mempool is fair, it will not always try to add a small transaction as soon as it can, but it will eventually wait until enough capacity has been freed (by the remover thread) so that a large transaction can be added.

After collecting M removed transactions, let diff be the difference between the number of small and large transactions that were added to mp, then we check that:

diff / M <= toleranceThreshold

See TestParams for an explanation of the different parameters that influence this test.