Repository navigation
Conversation
Move the best_block_v2 locator handling from TxIndex::DB into BaseIndex::DB behind a constructor flag, so other indexes can reuse it when they change their on-disk format.
Make the key prefix a template parameter so other indexes can reuse them. Not in db_key.h, which holds the height-based scheme of blockfilterindex and coinstatsindex.
Move the logic that assigns a sequence number to a newly indexed block and the creation of the salted hasher out of TxIndex::DB into free functions in block_seq, so other indexes using the same scheme can share them.
Use the txindex key scheme: a 5-byte salted hash of the spent outpoint, followed by the block sequence and the offset of the spending tx. As in txindex, entries of disconnected blocks are kept, so CustomRemove goes away and FindSpender only returns spends in the active chain. Fall back to the legacy entries if no spend is found.
Pin the encodings of the new and legacy keys, and add unit tests for hash prefix false positives, for entries of disconnected blocks being kept but not returned, and for the fallback to legacy entries. Add a functional test that upgrades a v31 datadir, reorgs a block indexed in the legacy format and downgrades again.
Mimic TxIndex::FindTx: skip a candidate that cannot be read and return std::optional. With 5-byte hash prefixes collisions are no longer negligible, and failing on an unreadable false positive would hide the real spender.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Concept ACK!
I have done this before. IIRC the db size went from ~84GB -> ~62GB. The time to index is also much lower. Do we want to also enable pruning in one go like we are with #36002? I don't think it would be controversial so we could do it all in 1 PR. |
Sorry @andrewtoth, i wasnt aware of it 😅 , should i compare with ur code and add u as co author?
sounds awesome!
Sure! i will add the commits, but it will take me some time o7 |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
No worries, it was nothing I published. Let's just keep going with this. I don't need to be added as co-author.
On second thought, if we merge #36002 first we can reuse the TxLookupResult (sorry I have to push an update there) |
|
Sounds good to me, i will wait an then add here |
|
Concept ACK |
|
Concept ACK |
|
Concept ACK |
|
🐙 This pull request conflicts with the target branch and needs rebase. |

This applies the txindex key scheme from #35531 to
txospenderindex. The motivation is to save space and to allow replicating what #36002 does fortxindex, by referencing blocks instead of local files.The first commits refactor the index code so the #35531 scheme can be shared:
BaseIndex::DBcan opt in to the versioned sync locator, and the block sequence keys, sequence assignment and salted hasher move from txindex intoindex/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, soCustomRemoveis gone. Entries written by v31 are still read as a fallback. The last commit makesFindSpenderskip candidates it cannot read and returnstd::optional, mimickingTxIndex::FindTx, since with 5-byte prefixes an unreadable false positive could otherwise hide the real spender.Each entry is about 33% smaller (key 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.