1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 01:43:29 +01:00

Add short schema description

This commit is contained in:
Roman Zeyde 2018-07-02 13:54:06 +03:00
parent aa6f20017a
commit b421df8c10
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with 35 additions and 4 deletions

View File

@ -1,9 +1,5 @@
# Electrum Server in Rust
<p>
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c3/Gold-121700.jpg" width="40%" />
</p>
[![Build Status](https://travis-ci.com/romanz/electrs.svg?branch=master)](https://travis-ci.com/romanz/electrs)
An efficient re-implementation of Electrum Server, inspired by [ElectrumX](https://github.com/kyuupichan/electrumx)
@ -81,3 +77,7 @@ scrape_configs:
$ sudo systemctl restart prometheus
$ firefox 'http://localhost:9090/graph?g0.range_input=1h&g0.expr=index_height&g0.tab=0'
```
## Index database
The database schema is described [here](doc/schema.md).

31
doc/schema.md Normal file
View File

@ -0,0 +1,31 @@
# Index Schema
The index is stored at a single RocksDB database using the following schema:
## Transaction outputs' index
Allows efficiently finding all funding transactions for a specific address:
| Code | Script Hash Prefix | Funding TxID Prefix |
| ------ | -------------------- | --------------------- |
| `b'O'` | `SHA256(script)[:8]` | `txid[:8]` |
## Transaction inputs' index
Allows efficiently finding spending transaction of a specific output:
| Code | Funding TxID Prefix | Funding Output Index | Spending TxID Prefix |
| ------ | -------------------- | --------------------- | --------------------- |
| `b'I'` | `txid[:8]` | `uint16` | `txid[:8]` |
## Full Transaction IDs
In order to save storage space, we store the full transaction IDs once, and use their 8-byte prefixes for the indexes above.
| Code | Transaction ID | Confirmed height |
| ------ | ----------------- |------------------|
| `b'T'` | `txid` (32 bytes) | `uint32` |
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)).