Updated regtest setup guide

This commit is contained in:
hackrush 2018-02-01 19:24:13 +05:30
parent ba6044ad14
commit 9c4e67b865

View file

@ -3,37 +3,94 @@ title: How do I setup an isolated regtest network to test LBRY?
category: developer category: developer
--- ---
## Prerequisites ## Why use a regtest server
A regtest server provides for a way to instantly generate blocks so that transactions can be instantaneous, so ultimately no waiting for confirmations from the blockchain. Also, no problem if you accidently corrupt your wallet, since no real funds are lost! Just delete the files and setup a new one.
## Setup
To begin setting up the network, there are a few things you need. To begin setting up the network, there are a few things you need.
Note that you need a Linux distribution to run all this. A virtual machine is Note that you need a Linux distribution to run all this. A virtual machine is fine.
fine.
### virtual environment ### Virtual Environment
First up it's a good idea to create a Python virtual environment. This requires First up it's a good idea to create a Python virtual environment. This requires you to have a functional python2.7 setup, with the Python package manager `pip` installed. To create a new virtual environment in a folder `lbry-env`, run this:
you to have a functional python2.7 setup, with the Python package manager `pip` `virtualenv -p /usr/bin/python2.7 lbry-env`
installed. To create a new virtual environment in a folder `lbry-env`, run this: To enter the environment, run:
`virtualenv -p /usr/bin/python2.7 lbry-env` To enter the environment, run
`source lbry-env/bin/activate`. `source lbry-env/bin/activate`.
### lbrycrd ### lbrycrd
You need to download a build of `lbrycrd` from [here](https://github.com/lbryio/lbrycrd/releases/), no installation required. You need to download a build of `lbrycrd` from [here](https://github.com/lbryio/lbrycrd/releases/), no installation required. To configure `lbrycrd` you need to create a file at `~/.lbrycrd/lbrycrd.conf`,
To configure `lbrycrd` you to create a file at `~/.lbrycrd/lbrycrd.conf`,
containing the following. containing the following.
```ini ```ini
rpcuser=test rpcuser=test
rpcpassword=test rpcpassword=test
rpcport=18332 rpcport=18332
rpcallowip=0.0.0.0/0
regtest=1 regtest=1
dnsseed=0
upnp=0
server=1 server=1
txindex=0 txindex=1
daemon=0 daemon=1
listen=0
discover=0
```
### lbryum-server
To install lbryum-server you first need to install the package `leveldb`. After that, download the source from [here](https://github.com/lbryio/lbryum-server/releases), and run the following _not_ inside the environment.
```bash
cd lbryum-server
sudo pip2 install -r requirements.txt
```
If you're not running debian/*buntu, or a derivative of those, you need to edit the `configure` file a bit. On line 11, remove the `apt-get` line and manually install the required packages. On line 51, change `adduser` to `useradd` and on the same line, change `--disabled-password` to `-p !`.
```bash
sudo ./configure
sudo python2 setup.py install
```
The `sudo ./configure` commands creates a new user in the system by the name "lbryum", which is the user through which we'll be the running the server. lbryum-server also need W/R access to `/var/lbryum-server`
To do that run:
```bash
sudo chown -R lbryum /var/lbryum-server
```
When installed, append/use the following config options to the `/etc/lbryum.conf` file.
```ini
[lbrycrdd]
lbrycrdd_host = localhost
lbrycrdd_port = 18332
# user and password from lbrycrd.conf
lbrycrdd_user = test
lbrycrdd_password = test
[network]
type=lbrycrd_regtest
```
### lbryum
To install lbryum, first download the source from [here](https://github.com/lbryio/lbryum/releases). To install it, run the following inside the virtual environment.
```bash
cd lbryum
pip2 install -r requirements.txt
pip2 install -e .
```
After installation completes, you must set the config option for lbryum using:
```bash
lbryum setconfig default_servers '{ "localhost": { "t": "50001" }}'
lbryum setconfig chain 'lbrycrd_regtest'
```
Alternatively, you can create a file `touch ~/.lbryum/config` and paste the following config:
```json
{
"chain": "lbrycrd_regtest",
"default_servers": {
"localhost": {
"t": "50001"
}
}
}
``` ```
### lbry ### lbry
@ -42,117 +99,92 @@ Download source from [here](https://github.com/lbryio/lbry/releases), and run th
```bash ```bash
cd lbry cd lbry
pip2 install -r requirements.txt pip2 install -r requirements.txt
pip2 install . pip2 install -e .
mkdir ~/.lbrynet
touch ~/.lbrynet/daemon_settings.yml
``` ```
### lbryum Append the following in the newly created `~/.lbrynet/daemon_settings.yml` file
```yml
blockchain_name: lbrycrd_regtest
lbryum_servers:
- localhost:50001
reflect_uploads: false
share_usage_data: false
use_upnp: false
```
To install lbryum, first download the source from [here](https://github.com/lbryio/lbryum/releases). To install it, run ### Last step
the following inside the virtual environment. Go to the `lbryum` folder once again and run:
```bash ```bash
cd lbryum pip2 install -e .
pip2 install -r requirements.txt
pip2 install .
``` ```
This is to ensure that `lbrynet-daemon` uses the correct wallet.
## Firing up the regtest server
### lbryum-server
To install lbryum-server you first need to install the package `leveldb`. After
that, download the source from [here](https://github.com/lbryio/lbryum-server/releases), and run the following inside the
environment.
```bash
cd lbryum-server
pip2 install -r requirements.txt
```
If you're not running debian/*buntu, or a derivative of those, you need to
edit the `configure` file a bit. On line 11, remove the `apt-get` line and
manually install the required packages. On line 48, change `adduser` to
`useradd` and on the same line, change `--disabled-password` to `-p !`.
```bash
sudo ./configure
sudo python2 setup.py install
```
When installed, append the following to the `/etc/lbryum.conf` file.
```ini
[lbrycrdd]
lbrycrdd_host = localhost
lbrycrdd_port = 18332
lbrycrdd_user = test
lbrycrdd_password = test
[network]
type = lbrycrd_regtest
```
## Setup
### Wallet backup ### Wallet backup
To start off with, if you've already used LBRY on your machine, you need to To start off, if you've already used LBRY on your machine, you need to backup the wallet by copying the folders `~/.lbrynet` and `~/.lbryum`, then delete them to start from fresh. Run
backup the wallet by copying the folders `~/.lbrynet` and `~/.lbryum`, then `mkdir ~/.lbryum`
delete them to start from fresh. Run
`mkdir ~/.lbryum; touch ~/.lbryum/blockchain_headers` to create a new empty
file there. If you don't do this, it'll try downloading the current blockchain
headers from a server.
### lbrycrd Now it should be all set-up, just execute the commands in the following order and the regtest server should be good to go.
### 1) lbrycrd
To run the `lbrycrd` daemon, run the following in the `lbrycrd` folder. To run the `lbrycrd` daemon, run the following in the `lbrycrd` folder.
`./lbrycrdd` `./lbrycrdd`
To generate blocks, run `./lbrycrd-cli generate <num_of_blocks>` To generate blocks, run `./lbrycrd-cli generate <num_of_blocks>`
You'll need to generate some blocks to get the network going. You'll need to generate some blocks to get the network going. Start off by generating at least 100.
Start off by generating 100. `./lbrycrd-cli generate 173`
If you'd prefer a more verbose output from lbrycrdd, run lbrycrd using
`./lbrycrdd -printtoconsole`
### lbryum ### 2) lbryum-server
To run the server, run `lbryum-server`. To run the server, run:
You also need to run the `lbryum` daemon, `lbryum daemon start -v`
After that, you need to setup lbryum. Run the following two commands to make
it use the local server in regtest mode.
```bash ```bash
lbryum setconfig default_servers '{ "localhost": { "t": "50001" }}' sudo runuser -l lbryum -c 'lbryum-server --conf=/etc/lbryum.conf'
lbryum setconfig chain 'lbrycrd_regtest' ```
Note: conf flag can be left out if the config is in the default directory(default: `/etc/lbryum.conf`)
### 3) lbryum
To run the lbryum, run:
```bash
lbryum daemon start
``` ```
At this point it's a good idea to restart everything. Generate some more Generate some more blocks, get a wallet address by running:
blocks, get a wallet address by `lbrynet-cli wallet_new_address`, and then `lbryum getunusedaddress`
send some credits to your wallet by doing and then send some credits to your wallet by doing
`./lbrycrd-cli sendtoaddress <address> <num_of_credits>` `./lbrycrd-cli sendtoaddress <address> <num_of_credits>`
### lbry ### 4) lbry
You can now run `lbrynet-daemon`, and it should connect to the `lbryum server`. You can now run `lbrynet-daemon`, and it should connect to the `lbryum`. Now you can use the regtest stack as you would normally use lbryum.
If you want to publish a claim inside the regtest network, you need to edit
`reflect_uploads` on line 177 in `lbry/lbrynet/conf.py` from `True` to `False`.
## Shutdown ## Shutdown
To stop the network, run `lbrynet-cli daemon_stop`, `lbryum daemon stop`, and To stop the network, run `lbrynet-cli daemon_stop`, `lbryum daemon stop`, and kill the `lbryum-server` process and stop lbrycrd by `lbrycrdd-cli stop`. If you want to use your wallet and the official servers again, backup the new regtest wallet, and replace it with your own.
kill the `lbryum-server` and `lbrycrdd` processes. If you want to use your
wallet and the official servers again, backup the new regtest wallet, and
replace it with your own.
## Note ## Note 1
If something goes wrong and you get a "Block not found" error, remember to You need to generate a few blocks everytime you make a new transaction in the form of send, receive, claim, update, publish, support, tip etc. for it to show up in the daemon and lbryum etc.
delete `/var/lbryum-server` before trying again.
## Note 2
If something goes wrong and you get a "Block not found" error, remember to delete `/var/lbryum-server` before trying again.
## Cheatsheet ## Cheatsheet
#### Required processes in the correct order #### Required processes in the correct order
```bash ```bash
lbrycrdd -regtest -server -printtoconsole lbrycrdd
lbryum-server sudo runuser -l lbryum -c 'lbryum-server --conf=/etc/lbryum.conf'
lbryum daemon start -v lbryum daemon start
lbrynet-daemon lbrynet-daemon
``` ```
@ -164,10 +196,10 @@ lbrycrd-cli generate 5
#### Get a wallet address #### Get a wallet address
```bash ```bash
lbrynet-cli wallet_new_address lbryum getunsusedaddress
``` ```
#### Send credits from lbrycrd to your wallet #### Send credits from lbrycrd to your wallet
```bash ```bash
lbryrd-cli sendtoaddress <address> <num_of_credits> lbrycrd-cli sendtoaddress <address> <num_of_credits>
``` ```