Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
husonghua committed Nov 18, 2021
1 parent 67c12b8 commit 8fa6cb1
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 35 deletions.
132 changes: 112 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,121 @@
# Substrate-based Validator Node Ansible Setup
# Cosmos-based Node Ansible Setup

This repo is to set up the Cosmos-based node. It currently support:

- Juno (mainnet and testnet)
- Sifchain (betanet and testnet)
- Evmos (testnet)

## Summary

You run one playbook and set up a node. For example:

```bash
ansible-playbook -i inventory juno_full_setup.yml -e "target=juno_testnet"
```

But before you rush with this easy setup, you probably want to read on so you understand the structure of this Ansible program and all the features it offers.

## Some Preparations

First, make sure that you have a production inventory file with your confidential server info. You will start by copying the sample inventory file (included in the repo). The sample file gives you a good idea on how to define the inventory.

```bash
cp inventory.sample inventory
```

Needless to say, you need to update the dummy values in the inventory file. For each node, you need to update the server IP. While you are free to keep the default, you might also want to update:

1. ansible_user: The sample file assumes `ubuntu`.
2. ansible_port: The sample file assumes `22`. But if you are like me, you will have a different ssh port other than `22` to avoid port sniffing.
3. ansible_ssh_private_key_file: The sample file assumes `~/.ssh/id_rsa`, but you might have a different key location.
4. log_monitor: Enter your monitor server IP. It is most likely a private IP address if you use a firewall around your private virtual cloud (VPC).

It is beyond the scope of this guide to help you create a sudo user, alternate ssh port, create a private key, install Ansible on your machine, etc. You can do a quick online search and find the answers. In my experience, Digital Ocean have some quality guides on these topics. Stack Overflow can help you trouble-shoot if you are stuck.

## Basic Cluster Structure

The basic cluster structure is:

1. Name each juno node as `juno_testnet`, `juno_mainnet`, etc. Group all Juno nodes into `juno` group.
2. Name each juno node as `sifchain_testnet`, `sifchain_mainnet`, etc. Group all Sifchain nodes into `sifchain` group.
3. ...

The structure allows you to target `vars` to each node, or a group cluster, or the whole cluster. Make sure that you are familiar with the files in the `group_vars` folder. They follow this clustered structure closely.

## Main Playbook

The key Ansible playbook is `xxxxx_full_setup.yml` files. It will set up a fresh node from scratch. For example:

```bash
ansible-playbook -i inventory sifchain_full_setup.yml -e "target=sifchain_betanet"
```

## Some Useful Commands

block height

```bash
watch -n 60 -d "curl -s http://localhost:26657/status | jq -r .result.sync_info.latest_block_height"
curl -s localhost:26657/net_info | jq -r .result.peers[].node_info.moniker
```

Connected Peers

```bash
curl -s localhost:26657/net_info | jq -r '.result.peers[] | .node_info.moniker, .node_info.id, .node_info.listen_addr, .remote_ip'
```

Check logs and cosmovisor status

```bash
journalctl -u cosmovisor.service -f
journalctl -u cosmovisor.service -f | grep "committed"
systemctl status cosmovisor
curl -s localhost:26657/net_info | jq -r '.result.peers[] | .node_info.moniker, .node_info.id, .node_info.listen_addr, .remote_ip'
curl -s localhost:26657/net_info | jq -r .result.peers[].node_info.moniker
watch -n 2 " curl -s localhost:26657/net_info | jq -r '.result.n_peers'"
```

Sifchain: create validator

```bash
sifnoded tx staking create-validator \
--amount 1000000000000000000000rowan \
--commission-max-change-rate "0.01" \
--commission-rate "0.02" \
--commission-max-rate "0.1" \
--min-self-delegation "1" \
--website "https://polkachu.com" \
--identity "0A6AF02D1557E5B4" \
--details "Polkachu is the trusted staking service provider for blockchain projects. 100% refund for downtime slash. Contact us at hello@polkachu.com" \
--pubkey=$(sifnoded tendermint show-validator) \
--moniker 'Polkachu' \
--chain-id sifchain-1 \
--gas-adjustment="1.5" \
--gas="200000" \
--fees 100000000000000000rowan \
--from polkachu
```

Sifchain: Delegate

```bash
sifnoded tx staking delegate sifvaloper1gp957czryfgyvxwn3tfnyy2f0t9g2p4pfj2j90 420000000000000000000rowan \
--chain-id sifchain-1 \
--from=polkachu \
--gas-adjustment="1.5" \
--gas="200000" \
--fees 100000000000000000rowan
```

```bash
junod tx staking create-validator \
--amount 6000000ujunox \
--commission-max-change-rate "0.1" \
--commission-max-rate "0.20" \
--commission-rate "0.1" \
--min-self-delegation "1" \
--details "This is my validator" \
--pubkey=$(junod tendermint show-validator) \
--moniker '[Polkachu] 1% fee' \
--chain-id uni \
--gas-prices 0.025ujunox \
--from polkachu
```

junod tx staking edit-validator --website="https://polkachu.com" --from=polkachu --gas-prices="0.025ujunox" --chain-id=uni
junod tx staking delegate junovaloper1gp957czryfgyvxwn3tfnyy2f0t9g2p4pvzc6k3 1390000ujunox --chain-id=uni --from=polkachu --gas-prices="0.025ujunox"
--amount 6000000ujunox \
--commission-max-change-rate "0.1" \
--commission-max-rate "0.20" \
--commission-rate "0.1" \
--min-self-delegation "1" \
--details "This is my validator" \
--pubkey=$(junod tendermint show-validator) \
--moniker '[Polkachu] 1% fee' \
--chain-id uni \
--gas-prices 0.025ujunox \
--from polkachu
```
24 changes: 24 additions & 0 deletions group_vars/evmos_testnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
validator_name: polkachu-evmos-testnet
log_name: evmos_testnet
network: evmos
folder: '.evmosd'
daemon: evmosd
chain_id: evmos_9000-2
node_version: v0.2.0
genesis: 'https://raw.githubusercontent.com/CosmosContracts/testnets/main/uni/genesis.json'
repo: https://github.com/CosmosContracts/juno
minimum_has_price: '0.025ujunox'
peers: 'be7593d1d2cae15a574537f9107f525200824767@194.163.187.94:26656,78605eed3018a74d9c8c3a912cd8e6d5c9a9ca4b@65.21.232.149:26726,3bd90caf48ddd2d6b290550ecccd63348fc51da0@95.217.107.96:26658,f8da50943569f160854ac21c9ffb46fb4ff7bc0d@144.217.252.197:26626,1c4c38243893889a17fd3e677999f896b2b18586@95.217.35.111:26666,0e4dec8dd2cb74277bae3a9e7f1816603e97ce60@161.97.178.48:26656,3e7b138c766dc6da32decca8665da1afb2b6bb88@207.244.249.17:26656,5502b008356087cb689211bb3c4285b7ce7f6571@95.217.154.12:26656,8227d17c3cf123108c69bf671295e5fb22d9beb3@161.97.115.68:26656,56de4d8fe7421f5a4fb6ba75b20d749be3eecf22@95.217.84.54:26656,06e3dfce2d729250e810bd5605ad7f05f3b1fc2c@75.119.155.119:26656,7cb1576a6ed3dbdc62bc30908ff7d7e910c5b08f@78.46.52.20:46656,5502b008356087cb689211bb3c4285b7ce7f6571@95.217.154.12:26656,5576b0160761fe81ccdf88e06031a01bc8643d51@195.201.108.97:24656,13e850d14610f966de38fc2f925f6dc35c7f4bf4@176.9.60.27:26656'
seed: 'c36cec90ded95d162b85f8ecd00ecd7c8849ca75@arsiamons.seed.evmos.org:26656,3787335176bbb91bf14a67724ebe0f0940ca5afb@evmos-seed.artifact-staking.io:26656,faa31510d9280e74e7f2e767a62023bd5c896c27@evmos-testnet.mercury-nodes.net:29447'
# evmosd tx staking create-validator \
# --amount=1000000000000aphoton \
# --pubkey=$(evmosd tendermint show-validator) \
# --moniker="polkachu-evomos-testnet" \
# --chain-id= evmos_9000-2 \
# --commission-rate="0.10" \
# --commission-max-rate="0.20" \
# --commission-max-change-rate="0.01" \
# --min-self-delegation="1000000" \
# --gas="auto" \
# --gas-prices="0.025aphoton" \
# --from=polkachu
4 changes: 3 additions & 1 deletion group_vars/juno_mainnet.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
validator_name: polkachu-juno-mainnet
log_name: juno_mainnet
network: juno
folder: '.juno'
daemon: junod
chain_id: juno-1
node_version: v1.0.0
genesis: 'https://raw.githubusercontent.com/CosmosContracts/mainnet/main/juno-1/genesis.json'
repo: https://github.com/CosmosContracts/juno
minimum_has_price: '0.025ujunox'
minimum_has_price: '0.025ujuno'
peers: 'c12726cfc959b54c90c0831216bab970645b536c@18.223.79.98:26656,b1f46f1a1955fc773d3b73180179b0e0a07adce1@162.55.244.250:39656,7f593757c0cde8972ce929381d8ac8e446837811@178.18.255.244:26656,7b22dfc605989d66b89d2dfe118d799ea5abc2f0@167.99.210.65:26656,4bd9cac019775047d27f9b9cea66b25270ab497d@137.184.7.164:26656,bd822a8057902fbc80fd9135e335f0dfefa32342@65.21.202.159:38656,15827c6c13f919e4d9c11bcca23dff4e3e79b1b8@51.38.52.210:38656,e665df28999b2b7b40cff2fe4030682c380bf294@188.40.106.109:38656,92804ce50c85ff4c7cf149d347dd880fc3735bf4@34.94.231.154:26656,795ed214b8354e8468f46d1bbbf6e128a88fe3bd@34.127.19.222:26656,ea9c1ac0e91639b2c7957d9604655e2263abe4e1@185.181.103.136:26656'
2 changes: 2 additions & 0 deletions group_vars/juno_testnet.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
validator_name: polkachu-juno-testnet
log_name: juno_testnet
network: juno
folder: '.juno'
daemon: junod
chain_id: uni
node_version: v1.0.0
Expand Down
1 change: 0 additions & 1 deletion group_vars/sifchain.yml

This file was deleted.

1 change: 1 addition & 0 deletions group_vars/sifchain_betanet.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
validator_name: polkachu-sifchain-betanet
log_name: sifchain_betanet
network: sifnoded
daemon: sifnoded
chain_id: sifchain-1
Expand Down
2 changes: 2 additions & 0 deletions group_vars/sifchain_testnet.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
validator_name: polkachu-sifchain-testnet
log_name: sifchain_testnet

chain_type: testnet
chain_id: sifchain-testnet-1
node_version: testnet-0.9.0
Expand Down
32 changes: 28 additions & 4 deletions inventory.sample
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
[juno-test]
10.0.0.1 validator_name=polkadot-juno-test log_name=juno-test
[sifchain_betanet]
10.0.0.1

[sifchain_testnet]
10.0.0.2

[juno_testnet]
10.0.0.2

[juno_mainnet]
10.0.0.3

[evmos_testnet]
10.0.0.4

[sifchain:children]
sifchain_betanet
sifchain_testnet

[juno:children]
juno_mainnet
juno_testnet

[evmos:children]
evmos_testnet

[all:vars]
ansible_user=ansible
ansible_user=ubuntu
ansible_port=22
ansible_ssh_private_key_file="~/.ssh/id_rsa"
log_monitor=10.0.0.2
log_monitor=10.0.0.100
path="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/go/bin:/home/ubuntu/go/bin"
25 changes: 16 additions & 9 deletions roles/juno/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,29 @@

- name: Update config files
lineinfile:
path: '/home/ubuntu/.{{ network }}/config/app.toml'
path: '/home/ubuntu/{{ folder }}/config/app.toml'
regexp: 'minimum-gas-prices '
line: 'minimum-gas-prices = "{{ minimum_has_price }}"'
state: present

- name: Update the config.toml file
lineinfile:
path: '/home/ubuntu/.{{ network }}/config/config.toml'
path: '/home/ubuntu/{{ folder }}/config/config.toml'
regexp: 'persistent_peers = ""'
line: 'persistent_peers = "{{ peers }}"'
state: present

- name: Enable prometheus on the config.toml file
lineinfile:
path: '/home/ubuntu/{{ folder }}/config/config.toml'
regexp: 'prometheus = false'
line: 'prometheus = true'
state: present

- name: Download genesis file
get_url:
url: '{{ genesis }}'
dest: '/home/ubuntu/.{{ network }}/config/genesis.json'
dest: '/home/ubuntu/{{ folder }}/config/genesis.json'
mode: '0644'

- name: register public ip
Expand All @@ -55,24 +62,24 @@

- name: Set up external address
lineinfile:
path: '/home/ubuntu/.{{ network }}/config/config.toml'
path: '/home/ubuntu/{{ folder }}/config/config.toml'
regexp: 'external_address = ""'
line: 'external_address = "{{ public_ip.json.ip }}:26656"'
state: present

- name: Create directories
- name: Create cosmovisor directories
file:
path: '{{ item }}'
state: directory
mode: '0755'
with_items:
- '/home/ubuntu/.{{ network }}/cosmovisor/genesis/bin'
- '/home/ubuntu/.{{ network }}/cosmovisor/upgrades'
- '/home/ubuntu/{{ folder }}/cosmovisor/genesis/bin'
- '/home/ubuntu/{{ folder }}/cosmovisor/upgrades'

- name: copy
- name: copy daemon file to cosmovisor
copy:
src: '/home/ubuntu/go/bin/{{ daemon }}'
dest: '/home/ubuntu/.{{ network }}/cosmovisor/genesis/bin'
dest: '/home/ubuntu/{{ folder }}/cosmovisor/genesis/bin'
remote_src: true
mode: '0755'

Expand Down
5 changes: 5 additions & 0 deletions roles/prepare/tasks/firewall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
when:
- not ufw_status_result.stdout is search("26657/tcp.*ALLOW IN.*Anywhere")

- name: open prometheus port
command: ufw allow 26660/tcp
when:
- not ufw_status_result.stdout is search("26660/tcp.*ALLOW IN.*Anywhere")

- name: enable firewall
shell: |
set -o pipefail
Expand Down

0 comments on commit 8fa6cb1

Please sign in to comment.