This PR adds a way to persist the coins cache on shutdown to a file named coinscache.dat
, similar to what is done for the mempool. On startup this file is used to warm the cache so it doesn’t get cold between restarts. This can be useful for users who want to connect blocks quickly with a high -dbcache
value.
This introduces a new config arg, -persistcoinscache
, that is defaulted to false. With a higher cache value the amount of disk space used for the file could be very large, so it defaults to off to prevent any footguns. With lower cache values this configuration could cause the cache to flush sooner than necessary and would probably not provide any benefit.
With a max dbcache after a reindex or IBD it will dump the entire utxo set and load it into memory on startup. Testing this today I had a file size of 2.4GB and it took ~22 minutes to fully reinsert the utxo set into the cache with an SSD.
After #17487 we can add a change to not wipe the cache on periodic flushes. Users could then run the node continuously with the entire utxo set in memory. Benchmarking shows running in this configuration could save several hundred milliseconds when connecting blocks, vs an empty cache that is cleared periodically or during restarts.