owned this note
owned this note
Published
Linked with GitHub
# Migration of GuanYu Testnet #4 to Laozi Testnet #1
This document describes procedures to upgrade Bandchain from GuanYu testnet #4 to a Laozi testnet #1. We will perform these steps together at following block and date
```env
GUANYU_HALTED_BLOCK=183838
LAOZI_GENESIS_DATE="2021-05-13T15:00:00Z"
```
## Setup environment
```bash!
# Laozi's genesis date
export GENESIS_DATE="2021-05-13T15:00:00Z"
# GuanYu's halted block
export HALTED_BLOCK=183838
# validator's wallet
export WALLET_NAME=<YOUR_WALLET>
# Laozi's new node name
export MONIKER=<YOUR_MONIKER>
export CHAIN_ID_LAOZI=band-laozi-testnet1
export CHAIN_ID_GUANYU=band-guanyu-testnet4
export PERSISTENT_PEERS_LAOZI="f4f5d520a65e4b0c64b9f139758ec36e595ef843@35.240.194.225:26656,2056308116c741434d61a7bd482bac1c3ceb306a@35.244.13.157:26656"
export PERSISTENT_PEERS_GUANYU="9d6c18be762b76c5eded626e70d343ddaaacb361@34.87.136.8:26656,74a3d65ea7ba44e4ef617d72faece1a627819703@35.200.195.237:26656"
```
## Migrate Validator
### 1. Stop current node by running the command below
```bash=
sudo systemctl stop bandd.service
sudo systemctl stop yoda.service
```
### 2. Upgrade GuanYu node to the latest version preparing for exporting genesis file
Since there is latest patch that improve exporting genesis file method, latest version of GuanYu Bandchain is required.
```bash=
cd bandchain/chain
git checkout master
git pull
git checkout v1.3.0-rc0
make install
```
Please make sure that `bandd` and `bandcli` is now the latest version.
```bash=
bandd version --long
# name: bandchain
# server_name: bandd
# client_name: bandcli
# version: 1.3.0-rc0
# commit: 49e2ae8f644eeceb814c2dab005dec400ce0f8e7
# build_tags: ledger
# go: go version go1.14.15 linux/amd64
```
### 3. Export genesis file & wallet
The following information will be included in the genesis file
```bash=
cd $HOME
bandd export --for-zero-height --height $HALTED_BLOCK > guanyu_testnet3_genesis.json
```
If wallet exists in exisitng chain, they can be exported.
```bash=
bandcli keys export $WALLET_NAME
```
After run the command, it will ask to input password to encrypt the private key. Then, private key will be displayed on terminal, similar to the example below.
```bash
#
# -----BEGIN TENDERMINT PRIVATE KEY-----
# ...
# -----END TENDERMINT PRIVATE KEY-----
#
```
Copy the result similar to above and save to a file.
```bash=
vim $HOME/${WALLET_NAME}_privkey.txt
```
### 4. Verify integrity genesis file.
Expected hash of the genesis file will be announced on Band Protocol's discord channel).
In order to preserve consistency of generating hash, all fields in JSON content should be sorted. This can be done by using `jq` command. Then, pipe the output to `shasum` to produce hash.
```bash=
sudo apt-get update
sudo apt-get install -y jq
jq -S -c -M '' guanyu_testnet3_genesis.json | shasum -a 256
# fa1087294e54f230c492ecbe89fd7bc97b32bb27309d71a140a06453cff936af
```
We will announce a SHA256 hash to be compared with your hash, so, **Please compare them before further steps**.
### 5. Install Laozi version of bandd (**v2.0.0-rc0**).
After genesis file of GuanYu is exported, new version of bandd **v2.0.0-rc0** will be used to begin initializing and run the new Laozi node. This can be done by executing the following commands.
```bash=
# Remove old version of go (1.14)
rm -r $HOME/go/bin
sudo rm -r /usr/local/go
# Install new version of go (1.15)
wget https://dl.google.com/go/go1.15.8.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.15.8.linux-amd64.tar.gz
echo "export PATH=\$PATH:/usr/local/go/bin:$HOME/go/bin" >> $HOME/.profile
source $HOME/.profile
# Clone Laozi code from new repository and build bandd and yoda
git clone https://github.com/bandprotocol/chain.git
cd chain
git checkout v2.0.0-rc0
make install
```
Make sure that `bandd` version is the latest Laozi version.
```bash=
bandd version --long
# name: bandchain
# server_name: bandd
# version: 2.0.0-rc0
# commit: da9bad3e887a764bedde27dca89ba670c3122a4b
# build_tags: ledger
# go: go version go1.15.8 linux/amd64
```
### 6. Migrate the exported genesis file to be compatible with Laozi Bandchain
Since GuanYu Bandchain uses Cosmos SDK v0.39 while Laozi Bandchain uses Cosmos SDK v0.42, Migrating the genesis file is required for compatibility.
After migrated the genesis file, please make sure that SHA256 hash of the file is valid.
```bash=
cd $HOME
bandd migrate guanyu_testnet3_genesis.json --chain-id=$CHAIN_ID_LAOZI --genesis-time=$GENESIS_DATE > laozi_testnet1_genesis.json
jq -S -c -M '' laozi_testnet1_genesis.json | shasum -a 256
# 0a6289b4b047af32647caeb1de8ab170d91e838beb4169447ae0af81b6135e6a
```
We will announce a SHA256 hash to be compared with your hash, so, **Please compare them before further steps**.
### 7. Initialize Laozi Bandchain node
Init the Laozi node and copy configuration files from QuanYu folder (.bandd) to Laozi folder (.band).
```bash=
bandd init $MONIKER --chain-id $CHAIN_ID_LAOZI
cp $HOME/.bandd/config/priv_validator_key.json $HOME/.band/config
cp $HOME/.bandd/config/node_key.json $HOME/.band/config
cp -r $HOME/.bandd/files $HOME/.band
mv laozi_testnet1_genesis.json $HOME/.band/config/genesis.json
```
Import the exported key to the node. When importing the key, it will ask for password to decrypt the key.
```bash=
# Only import if you have exported key
bandd keys import $WALLET_NAME $HOME/${WALLET_NAME}_privkey.txt
# Please make sure that the key has been imported successfully
bandd keys list
# If key has been import successfully, then delete the file
rm $HOME/${WALLET_NAME}_privkey.txt
```
After imported the key. Make sure that the key has been imported successfully by running the command `bandd keys list`.
### 8. Update persistence peers of your node to BandChain peers.
This can be done by editing `persistent_peers` property in `$HOME/.band/config/config.toml`.
```bash=
sed -E -i \
"s/persistent_peers = \".*\"/persistent_peers = \"$PERSISTENT_PEERS_LAOZI\"/" \
$HOME/.band/config/config.toml
```
### 9. Finally, start Laozi Bandchain
```bash=
sudo systemctl start bandd
```
Log output can be showed with `journalctl -u bandd.service -f`. If genesis time is future, the node will wait until reach the genesis time to start the first block. Log should be displayed similar to following log
```
... INF Starting Node service impl=Node
... INF Genesis time is in the future. Sleeping until then... genTime=2021-04-23T11:00:00Z
```
If all goes well, the node daemon should have been started syncing after pass agreed block time.
**You may continue seting up Yoda to 1st step, then wait for genesis block to begin, then start the 3th step of Yoda Migation.**
```
... INF starting ABCI with Tendermint
.
.
.
... INF committed state app_hash=... height=1 module=state num_txs=0
... INF indexed block height=1 module=txindex
```
## Migrate Yoda
Keyring folder of Yoda should be renamed to `keyring-test`.
### 1. Migrate keyring
```bash=
# PLEASE MAKE SURE THAT NO TRALING SLASH IN BOTH PATHS
mv $HOME/.yoda/keyring-test-band $HOME/.yoda/keyring-test
```
### 2. Start Yoda
First let's config Yoda to use the new chain ID.
```bash=
yoda config chain-id $CHAIN_ID_LAOZI
```
Then, start the Yoda.
```bash=
sudo systemctl start yoda
```
type `journalctl -u yoda.service -f` to view Yoda log.
### 3. Send MsgActivate to reactivate yourself as an oracle provider
```bash=
bandd tx oracle activate \
--from $WALLET_NAME \
--chain-id $CHAIN_ID_LAOZI
```
Now, block explorer can be accessed [here](https://laozi-testnet1.cosmoscan.io) to check your validator status.
And that is all about upgrading Bandchain node to the new era. Happy staking :).
## Recovery Procedures
In case we need to rollback to GuanYu testnet #4, please follow these steps.
### 1. Stop current node by running the command below
```bash=
sudo systemctl stop bandd
sudo systemctl stop yoda
```
### 2. Install go 1.14
```bash=
rm -r $HOME/go/bin
sudo rm -r /usr/local/go
# Install go
sudo tar -C /usr/local -xzf go1.14.15.linux-amd64.tar.gz
echo "export PATH=\$PATH:/usr/local/go/bin:$HOME/go/bin" >> $HOME/.profile
source $HOME/.profile
```
### 3. Bring back `bandd` **v1.2.7a** and `yoda`
```bash=
cd bandchain/chain
git checkout v1.2.7a
make install
# PLEASE MAKE SURE THAT NO TRALING SLASH IN BOTH PATHS
mv $HOME/.yoda/keyring-test $HOME/.yoda/keyring-test-band
```
### 4. Update persistence peers of your node to BandChain peers.
```bash=
sed -E -i \
"s/persistent_peers = \".*\"/persistent_peers = \"${PERSISTENT_PEERS_GUANYU}\"/" \
$HOME/.bandd/config/config.toml
```
### 5. Restart bandd service
```bash=
sudo systemctl start bandd
```
Tail the log output with `journalctl -u bandd.service -f`. If all goes well, you should see that the node daemon has started syncing on wenchang-mainnet chain again.
```
... bandd: I[..] starting ABCI with Tendermint module=main
... bandd: I[..] Executed block module=state height=xx validTxs=0 invalidTxs=0
... bandd: I[..] Committed state module=state height=xx txs=0 appHash=...
...
```
### 6. Re-config & Start Yoda
Set Yoda chain ID to the old ID, then start it.
```bash=
yoda config chain-id $CHAIN_ID_GUANYU
sudo systemctl start yoda
```