owned this note
owned this note
Published
Linked with GitHub
# Bandchain GuanYu Testnet #4: How to Join as a Validator
This document describes methods on how to join as a validator in GuanYu testnet #4.
## Step 1: Setting Up Validator Node
This step provides procedures to install Bandchain's executable and sync blocks with other peers.
Assuming to run on Ubuntu 20.04 LTS allowing connection on port `26656` for P2P connection.
Before beginning instructions, following variables should be set to be used in further instructions.
```bash=
# Chain ID of testnet #4
export CHAIN_ID=band-guanyu-testnet4
# Wallet name to be used as validator's account, please change this into your name (no whitespace).
export WALLET_NAME=<YOUR_WALLET_NAME>
# Name of your validator node, please change this into your name.
export MONIKER=<YOUR_MONIKER>
# Persistent peers for P2P communication
export PERSISTENT_PEERS="9d6c18be762b76c5eded626e70d343ddaaacb361@34.87.136.8:26656,74a3d65ea7ba44e4ef617d72faece1a627819703@35.200.195.237:26656"
# URL of genesis file for GuanYu testnet #4
export GENESIS_FILE_URL=https://raw.githubusercontent.com/bandprotocol/launch/master/band-guanyu-testnet4/genesis.json
# Data sources/oracle scripts files
export BIN_FILES_URL=https://raw.githubusercontent.com/bandprotocol/launch/master/band-guanyu-testnet4/files.tar.gz
# Faucet endpoint
export FAUCET_URL=https://guanyu-testnet4.bandchain.org/faucet/request
```
### Step 1.1: Install Prerequisites
The following application is required for Building and running Bandchain node.
- Go 1.14
- make, gcc, g++ (can be obtained from `build-essential` package on linux)
- wget, curl for downloading files
```bash=
# install required tools
sudo apt-get update && \
sudo apt-get upgrade -y && \
sudo apt-get install -y build-essential curl wget
# Install Go 1.14.15
wget https://dl.google.com/go/go1.14.15.linux-amd64.tar.gz
tar xf go1.14.15.linux-amd64.tar.gz
sudo mv go /usr/local/go
# Set Go path to $PATH variable
echo "export PATH=\$PATH:/usr/local/go/bin:~/go/bin" >> $HOME/.profile
source ~/.profile
```
Go binary should be at `/usr/local/go/bin` and any executable compiled by `go install` command should be at `~/go/bin`
### Step 1.2: Clone & Install Bandchain GuanYu
```bash=
# Clone Bandchain GuanYu version v1.2.7a
git clone https://github.com/bandprotocol/bandchain
cd bandchain/chain
git checkout v1.2.7a
# Install binaries to ~/go/bin
make install
```
### Step 1.3: Initialize the Bandchain
```bash=
cd $HOME
# Initialize configuration and genesis state
bandd init --chain-id $CHAIN_ID "$MONIKER"
# Replace genesis file with our genesis file
wget $GENESIS_FILE_URL -O $HOME/.bandd/config/genesis.json
# Download data sources / oracle scripts files, and store in $HOME/.bandd/files
wget -qO- $BIN_FILES_URL | tar xvz -C $HOME/.bandd/
```
### Step 1.4: Setup Peers
```bash=
# Add persistent peers to config.toml
sed -E -i \
"s/persistent_peers = \".*\"/persistent_peers = \"${PERSISTENT_PEERS}\"/" \
$HOME/.bandd/config/config.toml
```
### Step 1.5: Start Running Bandchain
We do recommend to run bandchain node as a daemon, which can be setup using `systemctl`. Run the following command to create a new daemon for `bandd` (This script work on non-root user).
```bash=
# Write bandd service file to /etc/systemd/system/bandd.service
export USERNAME=$(whoami)
sudo -E bash -c 'cat << EOF > /etc/systemd/system/bandd.service
[Unit]
Description=BandChain Node Daemon
After=network-online.target
[Service]
User=$USERNAME
ExecStart=/home/$USERNAME/go/bin/bandd start --rpc.laddr tcp://0.0.0.0:26657
Restart=always
RestartSec=3
LimitNOFILE=4096
[Install]
WantedBy=multi-user.target
EOF'
```
To register and start the daemon, run the following command.
```bash=
# Register bandd daemon to systemctl
sudo systemctl enable bandd
# Start bandd daemon
sudo systemctl start bandd
```
Once `bandd` service has been started, logs can be queried by running `journalctl -u bandd.service -f` command.
### Step 1.5: Wait for latest blocks to be synced
**This is an important step.** We should wait for newly started Bandchain node to sync their blocks until the latest block is reached. The latest block can be checked on [this Block Explorer](https://guanyu-testnet4.cosmoscan.io).
## Step 2: Become a Validator
This step provides procedures to register the node as a validator.
### Step 2.1: Create new Account to be Used as Validator
```bash=
# Create new account
bandcli keys add $WALLET_NAME
# Request new coins from faucet
curl --location --request POST "${FAUCET_URL}" \
--header 'Content-Type: application/json' \
--data-raw "{
\"address\": \"$(bandcli keys show $WALLET_NAME -a)\"
}"
```
### Step 2.2: Stake Tokens with the Validator Account
```bash=
bandcli tx staking create-validator \
--amount 3000000uband \
--commission-max-change-rate 0.01 \
--commission-max-rate 0.2 \
--commission-rate 0.1 \
--from $WALLET_NAME \
--min-self-delegation 1 \
--moniker "$MONIKER" \
--pubkey $(bandd tendermint show-validator) \
--chain-id $CHAIN_ID
```
After became a validator, the validator node will be shown on Block Explorer [here](https://guanyu-testnet4.cosmoscan.io/validators).
## Step 3: Setup Yoda
Based on design, validator need to send a transaction to submit reports based on certain oracle requests. The validator should send transactions to submit reports within specified timeframe. However, the method is quite tedious. Therefore, we have develop an application called `Yoda`, which is a bot application that help validator automatically listen new oracle requests on Bandchain, execute data sources, and submit report to Bandchain, so validators don't have to send the transactions manually.
### Step 3.1: Prerequisites
Before setting up Yoda, a REST endpoint need to be setup to execute data sources. If this step has not been done yet, please follow the instructions on following pages (select either one of these methods):
- [AWS Lambda Function](https://github.com/bandprotocol/bandchain/wiki/AWS-lambda-executor-setup).
- [Google Cloud Function](https://github.com/bandprotocol/bandchain/wiki/Google-Cloud-Function-executor-setup)
Then, check Yoda version that we have compiled. It should be `v1.2.7a`.
```bash=
yoda version
# 1.2.7a
```
### Step 3.2: Configure Yoda
Firstly, configure Yoda's basic configurations
```bash=
rm -rf ~/.yoda # clear old config if exist
yoda config chain-id $CHAIN_ID
yoda config node http://localhost:26657
yoda config validator $(bandcli keys show $WALLET_NAME -a --bech val)
yoda config broadcast-timeout "5m"
yoda config rpc-poll-interval "1s"
yoda config max-try 5
```
Secondly, add multiple reporter accounts to allow Yoda submitting transactions concurrently.
```bash=
yoda keys add REPORTER_1
yoda keys add REPORTER_2
yoda keys add REPORTER_3
yoda keys add REPORTER_4
yoda keys add REPORTER_5
```
Thirdly, config Executor REST endpoint
```bash=
export EXECUTOR_URL=<YOUR_EXECUTOR_URL>
yoda config executor "rest:${EXECUTOR_URL}?timeout=10s"
```
### Step 3.3: Start Yoda
We also do recommend to use `systemctl` the same as `bandd`.
```bash=
# Write yoda service to /etc/systemd/system/yoda.service
export USERNAME=$(whoami)
sudo -E bash -c 'cat << EOF > /etc/systemd/system/yoda.service
[Unit]
Description=Yoda Daemon
After=network-online.target
[Service]
User=$USERNAME
ExecStart=/home/$USERNAME/go/bin/yoda run
Restart=always
RestartSec=3
LimitNOFILE=4096
[Install]
WantedBy=multi-user.target
EOF'
```
Then, register and start the service
```bash=
# Register yoda to systemctl
sudo systemctl enable yoda
# Start the Yoda service
sudo systemctl start yoda
```
Once `yoda` service has been started, logs can be queried by running `journalctl -u yoda.service -f` command. Log should be similar to the following log example below. Once verified, you can stop tailing the log by typing `Control-C`.
```bash=
... systemd[...]: Started Yoda Daemon.
... yoda[...]: I[...] ⭐ Creating HTTP client with node URI: tcp://localhost:26657
... yoda[...]: I[...] 🚀 Starting WebSocket subscriber
... yoda[...]: I[...] 👂 Subscribing to events with query: tm.event = 'Tx'...
```
### Step 3.4: Register Reporters and Become Oracle Provider
Now, Yoda have multiple reporters. In order to register the reporters to be owned by the validator, the following commands should be run.
Firstly, reporter accounts must be create on Bandchain by supplying some small amount of BAND tokens.
```bash=
# Send 1uband from a wallet to each reporter.
bandcli tx multi-send 1uband $(yoda keys list -a) \
--from $WALLET_NAME \
--chain-id $CHAIN_ID
```
Secondly, register reporters to the validator, so that oracle requests for validator can be assigned to the reporters.
```bash=
bandcli tx oracle add-reporters $(yoda keys list -a) \
--from $WALLET_NAME \
--chain-id $CHAIN_ID
```
Finally, activate the validator to become an oracle provider
```bash=
bandcli tx oracle activate \
--from $WALLET_NAME \
--chain-id $CHAIN_ID
```
If all procedures are successful, then oracle provider status for the validator should be `active`.
```bash=
bandcli query oracle validator $(bandcli keys show -a $WALLET_NAME --bech val)
# {
# "is_active": true,
# "since": ...
# }
```
And now you have become a validator on Bandchain GuanYu testnet #4.
Happy staking :chart_with_upwards_trend:, and may the **HODL** be with you.