Revival of #31703 with all outstanding review feedback addressed.
- EmplaceCoinInternalDANGERis also fuzz tested now
- Warning and logging moved from FlushStateToDisktoCCoinsViewDB::BatchWrite, ensuringAssumeUTXOsnapshot writes also display progress warnings
- Removed the redundant changed counter in BatchWritesince we now trackdirty_countdirectly
- All instances use dirty_count(not num_dirty) and parameter alignment is corrected
Since #28280 and #28233, the percentage of dirty entries in the cache when a flush happens may in practice be far from 100%. The log output, the decision to warn about a large flush (#31534), and the disk-full detection, however always use the entire size of the cache.
Fix this by keeping track of the number of dirty entries in
CCoinsViewCache, and using that number. We’ve dropped the usage ofDynamicMemoryUsageas it’s the wrong metric, even before the non-wiping flushes were introduced (if everything is dirty, memory usage is correlated with, but not the same as, the amount of disk space written or used). They could be improved by keeping track of proper write size estimates in a follow-up, but here we’re just using a fixed 48 bytes per entry estimate.