CCoinsViewCache code cleanup & deduplication
The change moves code responsible for updating the cache out of various CCoinsViewCache methods and into a Modifier class. This way the cache update code is just written once in a general way instead of being duplicated and split up to handle various special cases.
This is a refactoring, with changes to cache behavior only in 2 corner cases (with corresponding tests in coins_test.cpp) which don’t affect the meaning of data stored in the cache:
-
In BatchWrite, overwriting a non-dirty pruned cache entry with a fresh pruned cache entry now deletes the cache entry instead of leaving behind a dirty pruned entry that will trigger an unnecessary database write later.
-
In BatchWrite, overwriting a dirty pruned fresh cache entry with a nonpruned entry updates the entry without dropping the fresh flag. There’s no reason to drop the fresh flag in this case because the flag accurately describes the state of the base view and could prevent unnecessary database writes in the future if the utxo is spent later.