This applies the txindex key scheme from #35531 to txospenderindex. The motivation is to save space and to allow replicating what #36002 does for txindex, by referencing blocks instead of local files.
The first commits refactor the index code so the #35531 scheme can be shared: BaseIndex::DB can opt in to the versioned sync locator, and the block sequence keys, sequence assignment and salted hasher move from txindex into index/block_seq.h, without changing txindex's on-disk format. The following commits switch txospenderindex to the new keys and add tests. As in txindex, entries of disconnected blocks are kept and lookups only count blocks in the active chain, so CustomRemove is gone. Entries written by v31 are still read as a fallback. The last commit makes FindSpender skip candidates it cannot read and return std::optional, mimicking TxIndex::FindTx, since with 5-byte prefixes an unreadable false positive could otherwise hide the real spender.
Each entry is about 33% smaller (key bytes):
- before: 's' (1) + SipHash-2-4 of the outpoint (8) + CDiskTxPos, as varints nFile (2) + nPos (4) + nTxOffset (3) = 18 bytes
- after: 'x' (1) + SipHash-1-3-UJ prefix (5) + block sequence varint (3) + tx offset (3) = 12 bytes
I did not have time to do a benchmark (my setup is really cheap, laptop where i work with an external SSD connected), will try to do on the next days. But same as #35531 i hope to reduce disk space and indexing time.