Page MenuHomePhabricator

[Chronik] Add reverse lookup index, allow hashes in `/block/:hash_or_height`
ClosedPublic

Authored by tobias_ruck on Mar 22 2023, 14:47.

Details

Summary

Currently, we can only query blocks by height, because we only index by height. To query by hash, we need an index from hash -> height. However, since we already store the hash in the blk column family, this would be redundant. While this seems trivial for blocks, this would incur not an insignificant redundant space for the equivalent index for txs, or other future reverse indices.

We therefore add the ReverseLookup struct, which (instead of storing a hash -> height) stores a cheaphash(hash) -> [height] column family, which stores a list of heights for each entry to allow for collisions. See details in reverse_lookup.rs.

Test Plan

ninja check-crates && ninja && ./test/functional/test_runner.py chronik_block

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Fabien requested changes to this revision.Mar 23 2023, 08:55
Fabien added inline comments.
chronik/chronik-db/src/reverse_lookup.rs
1 ↗(On Diff #38767)

You summoned it

Macro whatyearisit:

This revision now requires changes to proceed.Mar 23 2023, 08:55
This revision is now accepted and ready to land.Mar 23 2023, 12:51