hub/README.md

127 lines
9 KiB
Markdown
Raw Normal View History

2022-05-18 22:31:52 +02:00
## LBRY Hub
2022-03-08 17:01:19 +01:00
2022-05-18 22:31:52 +02:00
This repo provides a python library, `hub`, for building services that use the processed data from the [LBRY blockchain](https://github.com/lbryio/lbrycrd) in an ongoing manner. Hub contains a set of three core executable services that are used together:
2022-05-18 22:49:42 +02:00
* `scribe` ([hub.scribe.service](https://github.com/lbryio/hub/tree/master/hub/service.py)) - maintains a [rocksdb](https://github.com/lbryio/lbry-rocksdb) database containing the LBRY blockchain.
2022-08-15 20:59:13 +02:00
* `herald` ([hub.herald.service](https://github.com/lbryio/hub/tree/master/hub/herald/service.py)) - an electrum server for thin-wallet clients (such as [lbry-sdk](https://github.com/lbryio/lbry-sdk)), provides an api for clients to use thin simple-payment-verification (spv) wallets and to resolve and search claims published to the LBRY blockchain. A drop in replacement port of herald written in go - [herald.go](https://github.com/lbryio/herald.go) is currently being worked on.
2022-05-18 22:49:42 +02:00
* `scribe-elastic-sync` ([hub.elastic_sync.service](https://github.com/lbryio/hub/tree/master/hub/elastic_sync/service.py)) - a utility to maintain an elasticsearch database of metadata for claims in the LBRY blockchain
2022-03-22 17:59:08 +01:00
2022-08-01 17:48:13 +02:00
![](https://raw.githubusercontent.com/lbryio/hub/master/docs/diagram.png)
2022-05-18 22:31:52 +02:00
Features and overview of `hub` as a python library:
* Uses Python 3.7-3.9 (3.10 probably works but hasn't yet been tested)
2022-05-18 22:49:42 +02:00
* An interface developers may implement in order to build their own applications able to receive up-to-date blockchain data in an ongoing manner ([hub.service.BlockchainReaderService](https://github.com/lbryio/hub/tree/master/hub/service.py))
* Protobuf schema for encoding and decoding metadata stored on the blockchain ([hub.schema](https://github.com/lbryio/hub/tree/master/hub/schema))
* [Rocksdb 6.25.3](https://github.com/lbryio/lbry-rocksdb/) based database containing the blockchain data ([hub.db](https://github.com/lbryio/hub/tree/master/hub/db))
* [A community driven performant trending algorithm](https://raw.githubusercontent.com/lbryio/hub/master/docs/trending%20algorithm.pdf) for searching claims ([code](https://github.com/lbryio/hub/blob/master/hub/elastic_sync/fast_ar_trending.py))
2022-03-08 17:01:19 +01:00
## Installation
2022-03-24 17:54:32 +01:00
Scribe may be run from source, a binary, or a docker image.
2022-05-18 22:49:42 +02:00
Our [releases page](https://github.com/lbryio/hub/releases) contains pre-built binaries of the latest release, pre-releases, and past releases for macOS and Debian-based Linux.
Prebuilt [docker images](https://hub.docker.com/r/lbry/hub/tags) are also available.
2022-03-08 17:01:19 +01:00
2022-03-24 17:54:32 +01:00
### Prebuilt docker image
2022-03-08 17:01:19 +01:00
`docker pull lbry/hub:master`
2022-03-10 17:47:14 +01:00
2022-03-24 17:54:32 +01:00
### Build your own docker image
2022-03-10 17:47:14 +01:00
```
2022-05-18 22:49:42 +02:00
git clone https://github.com/lbryio/hub.git
cd hub
docker build -t lbry/hub:development .
2022-03-10 17:47:14 +01:00
```
2022-03-08 17:01:19 +01:00
2022-03-24 17:54:32 +01:00
### Install from source
Scribe has been tested with python 3.7-3.9. Higher versions probably work but have not yet been tested.
2022-03-08 17:01:19 +01:00
2022-05-05 20:07:39 +02:00
1. clone the scribe repo
2022-03-22 04:18:42 +01:00
```
2022-05-18 22:49:42 +02:00
git clone https://github.com/lbryio/hub.git
cd hub
2022-03-22 04:18:42 +01:00
```
2. make a virtual env
```
2022-05-18 22:49:42 +02:00
python3.9 -m venv hub-venv
2022-03-22 04:18:42 +01:00
```
3. from the virtual env, install scribe
```
2022-05-18 22:49:42 +02:00
source hub-venv/bin/activate
2022-03-22 04:18:42 +01:00
pip install -e .
```
2022-03-08 17:01:19 +01:00
2022-05-18 22:31:52 +02:00
That completes the installation, now you should have the commands `scribe`, `scribe-elastic-sync` and `herald`
2022-05-18 22:31:52 +02:00
These can also optionally be run with `python -m hub.scribe`, `python -m hub.elastic_sync`, and `python -m hub.herald`
2022-03-24 17:54:32 +01:00
## Usage
### Requirements
Scribe needs elasticsearch and either the [lbrycrd](https://github.com/lbryio/lbrycrd) or [lbcd](https://github.com/lbryio/lbcd) blockchain daemon to be running.
2022-03-24 17:54:32 +01:00
With options for high performance, if you have 64gb of memory and 12 cores, everything can be run on the same machine. However, the recommended way is with elasticsearch on one instance with 8gb of memory and at least 4 cores dedicated to it and the blockchain daemon on another with 16gb of memory and at least 4 cores. Then the scribe hub services can be run their own instance with between 16 and 32gb of memory (depending on settings) and 8 cores.
As of block 1147423 (4/21/22) the size of the scribe rocksdb database is 120GB and the size of the elasticsearch volume is 63GB.
2022-03-24 17:54:32 +01:00
### docker-compose
2022-05-18 22:49:42 +02:00
The recommended way to run a scribe hub is with docker. See [this guide](https://github.com/lbryio/hub/blob/master/docs/cluster_guide.md) for instructions.
2022-03-22 18:53:00 +01:00
2022-05-18 22:49:42 +02:00
If you have the resources to run all of the services on one machine (at least 300gb of fast storage, preferably nvme, 64gb of RAM, 12 fast cores), see [this](https://github.com/lbryio/hub/blob/master/docs/docker_examples/docker-compose.yml) docker-compose example.
2022-05-04 21:24:47 +02:00
### From source
### Options
#### Content blocking and filtering
2022-05-18 22:49:42 +02:00
For various reasons it may be desirable to block or filtering content from claim search and resolve results, [here](https://github.com/lbryio/hub/blob/master/docs/blocking.md) are instructions for how to configure and use this feature as well as information about the recommended defaults.
2022-05-18 22:31:52 +02:00
#### Common options across `scribe`, `herald`, and `scribe-elastic-sync`:
- `--db_dir` (required) Path of the directory containing lbry-rocksdb, set from the environment with `DB_DIRECTORY`
2022-05-18 22:31:52 +02:00
- `--daemon_url` (required for `scribe` and `herald`) URL for rpc from lbrycrd or lbcd<rpcuser>:<rpcpassword>@<lbrycrd rpc ip><lbrycrd rpc port>.
- `--reorg_limit` Max reorg depth, defaults to 200, set from the environment with `REORG_LIMIT`.
- `--chain` With blockchain to use - either `mainnet`, `testnet`, or `regtest` - set from the environment with `NET`
- `--max_query_workers` Size of the thread pool, set from the environment with `MAX_QUERY_WORKERS`
2022-05-18 22:31:52 +02:00
- `--cache_all_tx_hashes` If this flag is set, all tx hashes will be stored in memory. For `scribe`, this speeds up the rate it can apply blocks as well as process mempool. For `herald`, this will speed up syncing address histories. This setting will use 10+g of memory. It can be set from the environment with `CACHE_ALL_TX_HASHES=Yes`
- `--cache_all_claim_txos` If this flag is set, all claim txos will be indexed in memory. Set from the environment with `CACHE_ALL_CLAIM_TXOS=Yes`
- `--prometheus_port` If provided this port will be used to provide prometheus metrics, set from the environment with `PROMETHEUS_PORT`
#### Options for `scribe`
- `--db_max_open_files` This setting translates into the max_open_files option given to rocksdb. A higher number will use more memory. Defaults to 64.
- `--address_history_cache_size` The count of items in the address history cache used for processing blocks and mempool updates. A higher number will use more memory, shouldn't ever need to be higher than 10000. Defaults to 1000.
2022-05-18 01:58:01 +02:00
- `--index_address_statuses` Maintain an index of the statuses of address transaction histories, this makes handling notifications for transactions in a block uniformly fast at the expense of more time to process new blocks and somewhat more disk space (~10gb as of block 1161417).
#### Options for `scribe-elastic-sync`
- `--reindex` If this flag is set drop and rebuild the elasticsearch index.
2022-05-18 22:31:52 +02:00
#### Options for `herald`
- `--host` Interface for server to listen on, use 0.0.0.0 to listen on the external interface. Can be set from the environment with `HOST`
- `--tcp_port` Electrum TCP port to listen on for hub server. Can be set from the environment with `TCP_PORT`
- `--udp_port` UDP port to listen on for hub server. Can be set from the environment with `UDP_PORT`
- `--elastic_host` Hostname or ip address of the elasticsearch instance to connect to. Can be set from the environment with `ELASTIC_HOST`
- `--elastic_port` Elasticsearch port to connect to. Can be set from the environment with `ELASTIC_PORT`
- `--elastic_notifier_host` Elastic sync notifier host to connect to, defaults to localhost. Can be set from the environment with `ELASTIC_NOTIFIER_HOST`
- `--elastic_notifier_port` Elastic sync notifier port to connect using. Can be set from the environment with `ELASTIC_NOTIFIER_PORT`
- `--query_timeout_ms` Timeout for claim searches in elasticsearch in milliseconds. Can be set from the environment with `QUERY_TIMEOUT_MS`
- `--blocking_channel_ids` Space separated list of channel claim ids used for blocking. Claims that are reposted by these channels can't be resolved or returned in search results. Can be set from the environment with `BLOCKING_CHANNEL_IDS`.
- `--filtering_channel_ids` Space separated list of channel claim ids used for blocking. Claims that are reposted by these channels aren't returned in search results. Can be set from the environment with `FILTERING_CHANNEL_IDS`
2022-05-18 01:58:01 +02:00
- `--index_address_statuses` Use the address history status index, this makes handling notifications for transactions in a block uniformly fast (must be turned on in `scribe` too).
2022-03-22 18:53:00 +01:00
2022-03-08 17:01:19 +01:00
## Contributing
Contributions to this project are welcome, encouraged, and compensated. For more details, please check [this](https://lbry.tech/contribute) link.
## License
This project is MIT licensed. For the full license, see [LICENSE](LICENSE).
## Security
We take security seriously. Please contact security@lbry.com regarding any security issues. [Our PGP key is here](https://lbry.com/faq/pgp-key) if you need it.
## Contact
The primary contact for this project is [@jackrobison](mailto:jackrobison@lbry.com).