trueblocks-core
trueblocks-core copied to clipboard
chifra cmd - need a better method for upgrading cache files
I think (but I may be wrong) that the "method" of upgrading the cache is to allow the "ReadValue" to proceed until it fails, and when it does go through the same code one would go through when the cache item does not exist, but this is not robust.
For example, you could have three fields in the old data of size 16,16,32 and only two fields in the new data of size 32,32. This would not fail during reading, but it is incorrect as in the new data the first 32-bit field will get filled with garbage.
Instead, before readying anything, we should call into a function (that can be auto-generated with and // EXISTING_CODE section) called NeedsUpgrade(version) bool. It can return true if the the version is backLevel.
This is how the C++ code worked.