Description
(Created on Aug 31, 2023 by @iljakuklic)
Mempool and chainstate operate concurrently. When a transaction is processed, mempool employs the transaction verifier. The verifier in turn performs a series of chainstate queries. However, the state of the blockchain may change between the individual queries so it may happen that a transaction is validated with respect to an inconsistent blockchain state.
Currently, this is mitigated by checking the tip before and after the verification. If it does not match the verification is re-attempted up to a certain small number of times. This should almost always work since blocks are not supposed to come in very often by computer time standards. It is, however, still somewhat suboptimal and improvements can be made. Besides having an inconsistent view of the state, performing many inter-subsystem queries incurs non-trivial synchronisation overhead.
A possible improvement is to collect all the pieces of information required to verify the transaction in one query and store it in a data structure. The data structure can be then used as a storage backend for transaction verifier. That way, the number of subsystem calls is minimised and we get consistent state to query against. In addition to that, the BlockingHandle
machinery to call subsystems from non-async
contexts would likely be no longer needed.