Join GitHub today
test: Add more thorough test for dbwrapper iterators #7956
I made a silly mistake in an experimental database wrapper where keys were sorted by char instead of uint8_t. As x86 char is signed the sorting (and thus seeking) for the block index database was messed up, resulting in a segfault due to missing records. This should be caught by the tests.
Add a test to catch:
Also add an assertion to CBlockIndex::GetAncestor, as this it the place it will segfault when block index records are missing. An assertion error is easier to diagnose than a pointer crash (although what we really need is a start-up check whether the database is complete otherwise suggest a reindex).
I think this needs another check: that shorter keys get sorted before longer keys if they're otherwise the same. I don't think that we use variable-length keys anywhere, at least not within the same key prefix, but it's good to have the sorting be well-defined as lexicographic.