This adds a fuzz target for the block index and various events in validation that interact with it.
It can create arbitrary tree-like structure of block indexes, simulating (so far) the following events:
- Adding a header
- Receiving the full block (may be valid or not)
ActivateBestChain()
- Reorging the chain to a new chain tip (possibly encountering invalid blocks on the way)- Pruning
It might be interesting / possible to extend this to more events, such as dealing with more than one chainstate (assumeutxo).
The test skips all actual validation of header/ block / transaction data by just simulating the outcome, and also doesn’t interact with the data directory.
The main goal is to ensure the integrity of the block index tree in all fuzzed constellations, by calling CheckBlockIndex()
at the end of each iteration.
Compared to #29158 this approach has a more limited scope (by skipping all actual validation), but it is fast - it doesn’t do a full init sequence on each iteration, but “cleans up” after itself by resetting the global validation state after each iteration.
One downside of this approach is that it needs to have public access to a few members / functions in Chainstate(Manager)
/ BlockManager
.
Looking for conceptual feedback for now, so will leave as draft for a bit - this was helpful while working on #31405 and found the problem described in #31512.