blockbook/README.md

183 lines
7.4 KiB
Markdown
Raw Normal View History

2017-08-28 11:10:33 -06:00
# blockbook
2018-05-30 09:15:22 -06:00
## **blockbook is currently in the state of heavy development, do not expect this documentation to be up to date**
## Build and install using docker
Run in the project root
```
2018-05-30 09:15:22 -06:00
make all
```
2018-05-30 09:15:22 -06:00
to create blockbook debian packages.
## Install manually
2017-08-28 11:10:33 -06:00
2018-02-01 14:28:20 -07:00
Setup go environment (Debian 9):
2017-08-28 11:10:33 -06:00
```
2018-02-28 04:54:09 -07:00
sudo apt-get update && apt-get install -y \
build-essential git wget pkg-config lxc-dev libzmq3-dev libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev
cd /opt
wget https://storage.googleapis.com/golang/go1.9.2.linux-amd64.tar.gz && tar xf go1.9.2.linux-amd64.tar.gz
sudo ln -s /opt/go/bin/go /usr/bin/go
2017-08-28 11:10:33 -06:00
go help gopath
```
Install RocksDB: https://github.com/facebook/rocksdb/blob/master/INSTALL.md
2018-02-21 12:25:05 -07:00
and compile the static_lib and tools
2017-08-28 11:10:33 -06:00
```
2018-02-01 14:28:20 -07:00
git clone https://github.com/facebook/rocksdb.git
cd rocksdb
2018-02-21 12:25:05 -07:00
make release
2017-08-28 11:10:33 -06:00
```
2018-03-13 09:09:28 -06:00
Setup variables for gorocksdb: https://github.com/tecbot/gorocksdb
2017-08-28 11:10:33 -06:00
```
2018-03-13 09:09:28 -06:00
export CGO_CFLAGS="-I/path/to/rocksdb/include"
export CGO_LDFLAGS="-L/path/to/rocksdb -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4"
2017-08-28 11:10:33 -06:00
```
2018-01-19 07:58:46 -07:00
Install ZeroMQ: https://github.com/zeromq/libzmq
2018-03-13 09:09:28 -06:00
Install go-dep tool:
2018-01-19 07:58:46 -07:00
```
2018-03-13 09:09:28 -06:00
RUN go get github.com/golang/dep/cmd/dep
2018-01-19 07:58:46 -07:00
```
2018-03-13 09:09:28 -06:00
Get blockbook sources, install dependencies, build:
2017-08-28 11:10:33 -06:00
```
2018-02-01 14:28:20 -07:00
cd $GOPATH/src
git clone https://github.com/trezor/blockbook.git
2018-02-01 14:28:20 -07:00
cd blockbook
2018-03-13 09:09:28 -06:00
dep ensure
2018-02-01 14:28:20 -07:00
go build
2017-08-28 11:10:33 -06:00
```
## Usage
```
2018-02-07 14:51:19 -07:00
./blockbook --help
2018-01-25 10:04:35 -07:00
```
2018-02-07 14:51:19 -07:00
## Example command
To run blockbook with fast synchronization, connection to ZeroMQ and providing https and socket.io interface, with database in local directory *data* and connected to local bitcoind at http://localhost:8332 with user rpc/rpc:
```
./blockbook -sync -parse -httpserver=127.0.0.1:8333 -socketio=127.0.01:8334 -certfile=server/testcert -zeromq=tcp://127.0.0.1:28332
```
Blockbook logs only to stderr, logging to files is disabled. Verbosity of logs can be tuned by command line parameters *-v* and *-vmodule*, details at https://godoc.org/github.com/golang/glog
2018-02-28 04:54:09 -07:00
2018-03-13 09:09:28 -06:00
# Supported coins
2018-02-28 04:54:09 -07:00
- [BTC](bchain/coins/btc/btc.md)
- [BTC Testnet](bchain/coins/btc/btctestnet.md)
2018-05-30 09:15:22 -06:00
- BCH
- BCH Testnet
2018-04-06 04:01:28 -06:00
- [ZCash](bchain/coins/zec/zec.md)
2018-05-30 09:15:22 -06:00
- ZCash Testnet
2018-04-09 04:06:04 -06:00
- [Ethereum](bchain/coins/eth/eth.md)
2018-04-06 04:01:28 -06:00
- [Ethereum Ropsten Testnet](bchain/coins/eth/ethropsten.md)
2018-02-28 04:54:09 -07:00
2018-01-25 10:04:35 -07:00
# Data storage in RocksDB
Blockbook stores data the key-value store RocksDB. Data are stored in binary form to save space.
2018-01-27 16:30:55 -07:00
The data are separated to different column families:
2018-01-25 10:04:35 -07:00
- **default**
at the moment not used, will store statistical data etc.
2018-01-27 16:30:55 -07:00
- **height** - maps *block height* to *block hash*
2018-01-25 10:04:35 -07:00
*Block heigh* stored as array of 4 bytes (big endian uint32)
*Block hash* stored as array of 32 bytes
2018-01-25 10:04:35 -07:00
Example - the first four blocks (all data hex encoded)
```
0x00000000 : 0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943
0x00000001 : 0x00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206
0x00000002 : 0x000000006c02c8ea6e4ff69651f7fcde348fb9d557a06e6957b65552002a7820
0x00000003 : 0x000000008b896e272758da5297bcd98fdc6d97c9b765ecec401e286dc1fdbe10
2018-01-25 10:04:35 -07:00
```
- **outputs** - maps *output script+block height* to *array of outpoints*
2018-01-25 10:04:35 -07:00
*Output script (ScriptPubKey)+block height* stored as variable length array of bytes for output script + 4 bytes (big endian uint32) block height
*array of outpoints* stored as array of 32 bytes for transaction id + variable length outpoint index for each outpoint
2018-01-25 10:04:35 -07:00
Example - (all data hex encoded)
```
0x001400efeb484a24a1c1240eafacef8566e734da429c000e2df6 : 0x1697966cbd76c75eb9fc736dfa3ba0bc045999bab1e8b10082bc0ba546b0178302
0xa9143e3d6abe282d92a28cb791697ba001d733cefdc7870012c4b1 : 0x7246e79f97b5f82e7f51e291d533964028ec90be0634af8a8ef7d5a903c7f6d301
2018-01-25 10:04:35 -07:00
```
2018-01-27 16:30:55 -07:00
- **inputs** - maps *transaction outpoint* to *input transaction* that spends it
*Transaction outpoint* stored as array of 32 bytes for transaction id + variable length outpoint index
*Input transaction* stored as array of 32 bytes for transaction id + variable length input index
2018-01-27 16:30:55 -07:00
Example - (all data hex encoded)
```
0x7246e79f97b5f82e7f51e291d533964028ec90be0634af8a8ef7d5a903c7f6d300 : 0x0a7aa90ea0269c79f844c516805e4cac594adb8830e56fca894b66aab19136a428
0x7246e79f97b5f82e7f51e291d533964028ec90be0634af8a8ef7d5a903c7f6d301 : 0x4303a9fcfe6026b4d33ba488df6443c9a99bca7b7fcb7c6f6cd65cea24a749b700
```
2018-02-02 09:25:14 -07:00
## Registry of ports
| coin | blockbook http port | blockbook socket.io port | RPC port | zmq port |
|-------------|---------------------|--------------------------|----------|----------|
| btc | 9030 | 9130 | 8030 | 38330 |
| bch | 9031 | 9131 | 8031 | 38331 |
| zec | 9032 | 9132 | 8032 | 38332 |
| dash | 9033 | 9133 | 8033 | 38333 |
| ltc | 9034 | 9134 | 8034 | 38334 |
| btg | 9035 | 9135 | 8035 | 38335 |
| eth | 9036 | 9136 | 8036 | |
| etc | 9037 | 9137 | 8037 | |
| xem | 9038 | 9138 | 8038 | 38336 |
| btc-testnet | 19030 | 19130 | 18030 | 48330 |
| bch-testnet | 19031 | 19131 | 18031 | 48331 |
| zec-testnet | 19032 | 19132 | 18032 | 48332 |
| eth-testnet | 19036 | 19136 | 18036 | |
2018-02-02 09:25:14 -07:00
## Todo
2018-05-14 07:46:39 -06:00
- add db data version (column data version) checking to db to avoid data corruption
2018-05-11 06:20:01 -06:00
- improve txcache (time of storage, number/size of cached txs, purge cache)
2018-05-30 09:15:22 -06:00
- collect blockbook stats (number of items in indexes, etc)
2018-05-11 06:20:01 -06:00
- update documentation
- create/integrate blockchain explorer
2018-04-06 04:01:28 -06:00
- support all coins from https://github.com/trezor/trezor-common/blob/master/coins.json
2018-05-11 06:20:01 -06:00
- full ethereum support (tokens, balance)
- protobuf websocket interface instead of socket.io
2018-02-02 09:25:14 -07:00
- xpub index
- tests
2018-03-14 05:34:26 -06:00
- fix program dependencies to concrete versions
2018-05-11 06:20:01 -06:00
- protect socket.io interface against illicit usage
2018-05-30 09:15:22 -06:00
- ~~optimize mempool (use non verbose get transaction, possibly parallelize)~~
- ~~update used paths and users according to specification by system admin~~
2018-05-11 06:20:01 -06:00
- ~~cleanup of the socket.io - do not send unnecessary data~~
- ~~handle different versions of Bitcoin Core~~
- ~~log live traffic from production bitcore server and replay it in blockbook~~
- ~~find memory leak in initial import - disappeared with index v2~~
2018-04-06 04:01:28 -06:00
- ~~zcash support~~
- ~~basic ethereum support~~
2018-03-14 05:34:26 -06:00
- ~~disconnect blocks - use block data if available to avoid full scan~~
- ~~compute statistics of data, txcache, usage, etc.~~
- ~~disconnect blocks - remove disconnected cached transactions~~
- ~~implement getmempoolentry~~
2018-03-08 11:52:25 -07:00
- ~~support altcoins, abstraction of blockchain server/service~~
2018-03-07 15:27:40 -07:00
- ~~cache transactions in RocksDB~~
2018-03-03 17:08:57 -07:00
- ~~parallel sync - rewrite - it is not possible to gracefully stop it now, can leave holes in the block~~
2018-02-28 04:54:09 -07:00
- ~~mempool - return also input transactions~~
- ~~blockchain - return inputs from mempool~~
- ~~do not return duplicate txids~~
- ~~legacy socket.io JSON interface~~
- ~~disconnect blocks - optimize - full range scan is too slow and takes too much disk space (creates snapshot of the whole outputs), split to multiple iterators~~
- ~~parallel sync - let rocksdb to compact itself from time to time, otherwise it consumes too much disk space~~