2018-07-02 12:54:06 +02:00
|
|
|
# Index Schema
|
|
|
|
|
2021-08-18 15:59:27 +02:00
|
|
|
The index is stored at a single RocksDB database using the following column families.
|
|
|
|
Most of the data is stored in key-only DB rows (i.e. having empty values).
|
2018-07-02 12:54:06 +02:00
|
|
|
|
2021-03-26 09:05:58 +01:00
|
|
|
## Transaction outputs' index (`funding`)
|
2018-07-02 12:54:06 +02:00
|
|
|
|
|
|
|
Allows efficiently finding all funding transactions for a specific address:
|
|
|
|
|
2021-03-26 09:05:58 +01:00
|
|
|
| Script Hash Prefix | Confirmed Block Height |
|
|
|
|
| -------------------- | ---------------------- |
|
|
|
|
| `SHA256(script)[:8]` | `height as u32` |
|
2018-07-02 12:54:06 +02:00
|
|
|
|
2021-03-26 09:05:58 +01:00
|
|
|
## Transaction inputs' index (`spending`)
|
2018-07-02 12:54:06 +02:00
|
|
|
|
|
|
|
Allows efficiently finding spending transaction of a specific output:
|
|
|
|
|
2021-03-26 09:05:58 +01:00
|
|
|
| Previous Outpoint Prefix | Confirmed Block Height |
|
|
|
|
| ------------------------ | ---------------------- |
|
|
|
|
| `txid[:8] as u64 + vout` | `height as u32` |
|
2018-07-02 12:54:06 +02:00
|
|
|
|
|
|
|
|
2021-03-26 09:05:58 +01:00
|
|
|
## Transaction ID index (`txid`)
|
2018-07-02 12:54:06 +02:00
|
|
|
|
2021-03-26 09:05:58 +01:00
|
|
|
In order to save storage space, we map the 8-byte transaction ID prefix to its confirmed block height:
|
2018-07-02 12:54:06 +02:00
|
|
|
|
2021-03-26 09:05:58 +01:00
|
|
|
| Txid Prefix | Confirmed height |
|
|
|
|
| ----------- | ---------------- |
|
|
|
|
| `txid[:8]` | `height as u32` |
|
2018-07-02 12:54:06 +02:00
|
|
|
|
|
|
|
Note that this mapping allows us to use `getrawtransaction` RPC to retrieve actual transaction data from without `-txindex` enabled
|
|
|
|
(by explicitly specifying the [blockhash](https://github.com/bitcoin/bitcoin/commit/497d0e014cc79d46531d570e74e4aeae72db602d)).
|
2021-08-18 15:59:27 +02:00
|
|
|
|
|
|
|
## Headers (`headers`)
|
|
|
|
|
|
|
|
For faster loading, we store all block headers in RocksDB:
|
|
|
|
|
|
|
|
| Serialized header |
|
|
|
|
| ----------------------- |
|
|
|
|
| `header as BlockHeader` |
|
|
|
|
|
|
|
|
In addition, we also store the chain tip:
|
|
|
|
|
2021-09-18 19:19:58 +02:00
|
|
|
| Key | | Value |
|
|
|
|
| --- | - | ------------------------ |
|
|
|
|
| `T` | | `blockhash as BlockHash` |
|
2021-08-18 15:59:27 +02:00
|
|
|
|
|
|
|
## Configuration (`config`)
|
|
|
|
|
2021-09-18 19:19:58 +02:00
|
|
|
| Key | | Value |
|
|
|
|
| --- | - | --------------------------- |
|
|
|
|
| `C` | | `serialized config as JSON` |
|
2021-08-18 15:59:27 +02:00
|
|
|
|