2018-07-07 09:15:37 +00:00
## Installation
2018-08-17 12:32:14 +00:00
Install [latest Rust ](https://rustup.rs/ ) (1.28+),
2018-08-12 10:35:02 +00:00
[latest Bitcoin Core ](https://bitcoincore.org/en/download/ ) (0.16+)
and [latest Electrum wallet ](https://electrum.org/#download ) (3.2+).
2018-07-07 09:15:37 +00:00
2018-07-15 04:49:23 +00:00
Also, install the following packages (on Debian):
2018-07-07 09:15:37 +00:00
```bash
$ sudo apt update
2018-07-15 04:49:23 +00:00
$ sudo apt install clang cmake # for building 'rust-rocksdb'
2018-07-07 09:15:37 +00:00
```
## Build
First build should take ~20 minutes:
```bash
$ cargo build --release
```
## Bitcoind configuration
Allow Bitcoin daemon to sync before starting Electrum server:
```bash
2018-08-02 11:03:19 +00:00
$ bitcoind -server=1 -txindex=0 -prune=0
2018-07-07 09:15:37 +00:00
```
2018-08-02 11:05:56 +00:00
If you are using `-rpcuser=USER` and `-rpcpassword=PASSWORD` for authentication, please use `--cookie="USER:PASSWORD"` command-line flag.
2018-07-08 19:21:16 +00:00
Otherwise, [`~/.bitcoin/.cookie` ](https://github.com/bitcoin/bitcoin/blob/0212187fc624ea4a02fc99bc57ebd413499a9ee1/contrib/debian/examples/bitcoin.conf#L70-L72 ) will be read, allowing this server to use bitcoind JSONRPC interface.
2018-07-07 09:15:37 +00:00
## Usage
2018-07-12 20:25:49 +00:00
First index sync should take ~2 hours:
2018-07-07 09:15:37 +00:00
```bash
2018-08-02 11:05:56 +00:00
$ cargo run --release -- -vvv --timestamp --db-dir ./db [--cookie="USER:PASSWORD"]
2018-07-12 20:25:49 +00:00
2018-07-12T21:30:46 - DEBUG - BlockchainInfo { chain: "main", blocks: 531645, headers: 531645, bestblockhash: "00000000000000000006e41b275b21fc44e3b7afa8a8092aa6a7e4b84345f1f1", size_on_disk: 199667678141, pruned: false }
2018-07-12T21:30:46 - DEBUG - opening "./db/mainnet" with StoreOptions { bulk_import: true }
2018-07-12T21:30:46 - INFO - indexing 1313 blk*.dat files
2018-07-12T21:30:58 - DEBUG - applying 531646 new headers from height 0
2018-07-12T22:34:36 - DEBUG - last indexed block: best=00000000000000000006e41b275b21fc44e3b7afa8a8092aa6a7e4b84345f1f1 height=531645 @ 2018-07-12T18:20:51Z
2018-07-12T22:34:37 - INFO - starting full compaction
2018-07-12T23:18:53 - INFO - finished full compaction
2018-07-12T23:18:53 - DEBUG - opening "./db/mainnet" with StoreOptions { bulk_import: false }
2018-07-12T23:19:05 - DEBUG - applying 531646 new headers from height 0
2018-07-12T23:19:05 - DEBUG - downloading new block headers (531646 already indexed) from 0000000000000000002face92073e7b1dbcb02df32ea891b187a6c10b37dc8ad
2018-07-12T23:19:06 - INFO - best=0000000000000000002face92073e7b1dbcb02df32ea891b187a6c10b37dc8ad height=531656 @ 2018-07-12T20:07:12Z (11 left to index)
2018-07-12T23:19:08 - DEBUG - applying 11 new headers from height 531646
2018-07-12T23:19:11 - INFO - RPC server running on 127.0.0.1:50001
2018-07-07 09:15:37 +00:00
```
The index database is stored here:
```bash
$ du db/
2018-07-12 20:25:49 +00:00
37G db/mainnet/
2018-07-07 09:15:37 +00:00
```
## Electrum client
```bash
# Connect only to the local server, for better privacy
2018-07-25 09:21:55 +00:00
$ ./scripts/local-electrum.bash
2018-08-15 12:02:24 +00:00
+ ADDR=127.0.0.1
+ PORT=50001
+ PROTOCOL=t
+ electrum --oneserver --server=127.0.0.1:50001:t
< snip >
2018-07-07 09:15:37 +00:00
```
2018-08-15 12:00:14 +00:00
In order to use a secure connection, TLS-terminating proxy (e.g. [hitch ](https://github.com/varnish/hitch )) is recommended:
```bash
$ hitch --backend=[127.0.0.1]:50001 --frontent=[127.0.0.1]:50002 pem_file
$ electrum --oneserver --server=127.0.0.1:50002:s
```
2018-07-07 09:15:37 +00:00
## Monitoring
Indexing and serving metrics are exported via [Prometheus ](https://github.com/pingcap/rust-prometheus ):
```bash
$ sudo apt install prometheus
$ echo "
scrape_configs:
- job_name: electrs
static_configs:
2018-08-14 07:13:59 +00:00
- targets: ['localhost:4224']
2018-07-07 09:15:37 +00:00
" | sudo tee -a /etc/prometheus/prometheus.yml
$ sudo systemctl restart prometheus
$ firefox 'http://localhost:9090/graph?g0.range_input=1h& g0.expr=index_height& g0.tab=0'
```