Skip to content

Commit

Permalink
code refactor, add kava support, set user as variable instead of hard…
Browse files Browse the repository at this point in the history
…-coding to ubuntu
  • Loading branch information
husonghua committed Nov 20, 2021
1 parent f7b31d5 commit 0dbfc52
Show file tree
Hide file tree
Showing 27 changed files with 295 additions and 312 deletions.
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ This repo is to set up the Cosmos-based node. It currently support:

- Juno (mainnet and testnet)
- Sifchain (betanet and testnet)
- Kava (mainnet)
- 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"
ansible-playbook -i inventory juno.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.
Expand All @@ -24,12 +25,15 @@ First, make sure that you have a production inventory file with your confidentia
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:
Needless to say, you need to update the dummy values in the inventory file. For each node, you need to update the server IP, validator_name and log_name (log_name is optional if you do not install Promtail). While you are free to keep the default, you might also want to update:

1. ansible_user: The sample file assumes `ubuntu`.
1. ansible_user: The sample file assumes `ubuntu`, but feel free to use other user name. This user need sudo privilege.
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).
4. path: This is to make sure that the ansible_user can access the `go` executable. If your ansible_user is not `ubuntu`, you need to update it.
5. node_exporter: Default is `true`. Change it to `false` if you do not want to install node_exporter
6. promtail: Default is `true`. Change it to `false` if you do not want to install promtail
7. 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). You do not need this if you do not install promtail

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.

Expand All @@ -43,14 +47,30 @@ The basic cluster structure is:

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
## Playbooks

The key Ansible playbook is `xxxxx_full_setup.yml` files. It will set up a fresh node from scratch. For example:
The key Ansible playbook is `<chain>.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"
ansible-playbook -i inventory sifchain.yml -e "target=sifchain_betanet"
```

Playbooks are:

| Playbook | Description |
| -------------- | ------------------------------------------------------------------------------------ |
| `prepare.yml ` | Prepare the server with node_exporter, promtail, go, cosmovisor, and firewall rules |
| `juno.yml` | Set up Juno node. It include the general `prepare` task and `juno` specific task |
| `sifchain.yml` | Set up Juno node. It include the general `prepare` task and `sifchain` specific task |
| `kava.yml` | Set up Juno node. It include the general `prepare` task and `kava` specific task |

## Additional Info

When you install a node that has upgrades in the past, you can either sync from Block 1, or use a snapshot to time travel. We strongly recommend snapshots, which will save you time of syncing and debugging. Here are a list of trusted snapshot providers. Do your own research and make sure that you can trust the snapshot providers

- Various chains: https://www.chainlayer.io/quicksync/
- Sifchain: see https://github.com/Sifchain/sifchain-validators/blob/master/docs/setup/standalone/manual.md

## Some Useful Commands

block height
Expand Down
5 changes: 5 additions & 0 deletions group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# node_exporter
node_exporter_version: '1.2.2'
node_exporter_checksum: '344bd4c0bbd66ff78f14486ec48b89c248139cdd485e992583ea30e89e0e5390'

# promtail
promtail_version: '2.4.1'
promtail_checksum: 978391a174e71cfef444ab9dc012f95d5d7eae0d682eaf1da2ea18f793452031

# go
go_version: '1.17.1'
16 changes: 1 addition & 15 deletions group_vars/evmos_testnet.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
validator_name: polkachu-evmos-testnet
log_name: evmos_testnet
network: evmos
folder: '.evmosd'
daemon: evmosd
Expand All @@ -9,16 +7,4 @@ genesis: 'https://raw.githubusercontent.com/CosmosContracts/testnets/main/uni/ge
repo: https://github.com/CosmosContracts/juno
minimum_has_price: '0.025ujunox'
peers: '[email protected]:26656,[email protected]:26726,[email protected]:26658,[email protected]:26626,[email protected]:26666,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:46656,[email protected]:26656,[email protected]:24656,[email protected]: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
seeds: 'c36cec90ded95d162b85f8ecd00ecd7c8849ca75@arsiamons.seed.evmos.org:26656,3787335176bbb91bf14a67724ebe0f0940ca5afb@evmos-seed.artifact-staking.io:26656,faa31510d9280e74e7f2e767a62023bd5c896c27@evmos-testnet.mercury-nodes.net:29447'
6 changes: 2 additions & 4 deletions group_vars/juno_mainnet.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
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.025ujuno'
genesis: 'https://raw.githubusercontent.com/CosmosContracts/mainnet/main/juno-1/genesis.json'
peers: '[email protected]:26656,[email protected]:39656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:38656,[email protected]:38656,[email protected]:38656,[email protected]:26656,[email protected]:26656,[email protected]:26656'
minimum_has_price: '0.025ujuno'
6 changes: 2 additions & 4 deletions group_vars/juno_testnet.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
validator_name: polkachu-juno-testnet
log_name: juno_testnet
network: juno
folder: '.juno'
daemon: junod
chain_id: uni
node_version: v1.0.0
genesis: 'https://raw.githubusercontent.com/CosmosContracts/testnets/main/uni/genesis.json'
repo: https://github.com/CosmosContracts/juno
minimum_has_price: '0.025ujunox'
genesis: 'https://raw.githubusercontent.com/CosmosContracts/testnets/main/uni/genesis.json'
peers: '[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:36656,[email protected]:26656,[email protected]:26656'
minimum_gas_price: '0.025ujunox'
10 changes: 10 additions & 0 deletions group_vars/kava_mainnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
network: kava
folder: '.kvd'
daemon: kvd
chain_id: kava-8
node_version: v0.15.1
repo: https://github.com/kava-labs/kava
genesis: 'https://kava-genesis-files.s3.amazonaws.com/kava-8-genesis-migrated-from-block-1878508.json'
peers: '[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:50056,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:21656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656'
minimum_gas_price: '0.001ukava'
seeds: '[email protected]:26656'
5 changes: 2 additions & 3 deletions group_vars/sifchain_betanet.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
validator_name: polkachu-sifchain-betanet
log_name: sifchain_betanet
network: sifnoded
folder: '.sifnoded'
daemon: sifnoded
chain_id: sifchain-1
node_version: master
genesis: 'https://raw.githubusercontent.com/Sifchain/networks/master/betanet/sifchain-1/genesis.json.gz'
repo: https://github.com/Sifchain/sifnode.git
genesis: 'https://raw.githubusercontent.com/Sifchain/networks/master/betanet/sifchain-1/genesis.json.gz'
peers: '[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656'
9 changes: 5 additions & 4 deletions group_vars/sifchain_testnet.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
validator_name: polkachu-sifchain-testnet
log_name: sifchain_testnet

chain_type: testnet
network: sifnoded
folder: '.sifnoded'
daemon: sifnoded
chain_id: sifchain-testnet-1
node_version: testnet-0.9.0
repo: https://github.com/Sifchain/sifnode.git
genesis: 'https://raw.githubusercontent.com/Sifchain/networks/master/testnet/sifchain-testnet-1/genesis.json.gz'
peers: '[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656'
22 changes: 15 additions & 7 deletions inventory.sample
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
[sifchain_betanet]
10.0.0.1
10.0.0.1 validator_name=polkachu-sifchain-betanet log_name=sifchain_betanet

[sifchain_testnet]
10.0.0.2
10.0.0.2 validator_name=polkachu-sifchain-testnet log_name=sifchain_testnet

[juno_testnet]
10.0.0.2
10.0.0.2 validator_name=polkachu-juno-testnet log_name=juno_testnet

[juno_mainnet]
10.0.0.3
10.0.0.3 validator_name=polkachu-juno-mainnet log_name=juno_mainnet

[evmos_testnet]
10.0.0.4
10.0.0.4 validator_name=polkachu-evmos-testnet log_name=evmos_testnet

[kava_mainnet]
10.0.0.5 validator_name=polkachu-kava-mainnet log_name=kava_mainnet

[sifchain:children]
sifchain_betanet
Expand All @@ -24,9 +27,14 @@ juno_testnet
[evmos:children]
evmos_testnet

[kava:children]
kava_mainnet

[all:vars]
ansible_user=ubuntu
ansible_port=22
ansible_ssh_private_key_file="~/.ssh/id_rsa"
log_monitor=10.0.0.100
path="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/go/bin:/home/ubuntu/go/bin"
path="/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/go/bin:/home/ubuntu/go/bin"
node_exporter=true
promtail=true
log_monitor=10.0.0.100
6 changes: 4 additions & 2 deletions juno_full_setup.yml → juno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
roles:
- prepare

- name: Install Juno
- name: Install node
hosts: '{{ target }}'
gather_facts: false
roles:
- juno
- standard_node_installation
- initialize_juno
- launch_node
15 changes: 15 additions & 0 deletions kava.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Prepare
hosts: '{{ target }}'
become: true
gather_facts: false
roles:
- prepare

- name: Install node
hosts: '{{ target }}'
gather_facts: false
roles:
- standard_node_installation
- initialize_kava
- launch_node
32 changes: 32 additions & 0 deletions roles/initialize_juno/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- name: Initialize Node
command: '{{ daemon }} init {{ validator_name }} --chain-id {{ chain_id }} -o'
environment:
PATH: '{{ path }}'

- name: Update minimum gas price on config file
lineinfile:
path: '/home/{{ ansible_user }}/{{ folder }}/config/app.toml'
regexp: 'minimum-gas-prices '
line: 'minimum-gas-prices = "{{ minimum_gas_price }}"'
state: present

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

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

- name: Enable prometheus on the config.toml file
lineinfile:
path: '/home/{{ ansible_user }}/{{ folder }}/config/config.toml'
regexp: 'prometheus = false'
line: 'prometheus = true'
state: present
33 changes: 33 additions & 0 deletions roles/initialize_kava/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Initialize Node
command: '{{ daemon }} init {{ validator_name }} --chain-id {{ chain_id }} -o'
environment:
PATH: '{{ path }}'

- name: Update app.toml file
lineinfile:
path: '/home/{{ ansible_user }}/{{ folder }}/config/app.toml'
regexp: 'minimum-gas-prices '
line: 'minimum-gas-prices = "{{ minimum_gas_price }}"'
state: present

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

- name: Update seeds on the config.toml file
lineinfile:
path: '/home/{{ ansible_user }}/{{ folder }}/config/config.toml'
regexp: 'seeds = ""'
line: 'seeds = "{{ seeds }}"'
state: present

- name: Download genesis file
get_url:
url: '{{ genesis }}'
dest: '/home/{{ ansible_user }}/{{ folder }}/config/genesis.json'
mode: '0644'
force: true
27 changes: 27 additions & 0 deletions roles/initialize_sifchain/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- name: Initialize Node
command: '{{ daemon }} init {{ validator_name }} --chain-id {{ chain_id }} -o'
environment:
PATH: '{{ path }}'

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

- name: Download genesis file
get_url:
url: '{{ genesis }}'
dest: '/tmp/genesis.json.gz'
mode: '0700'

- name: unarchive genesis file
shell: 'gunzip /tmp/genesis.json.gz -f'

- name: copy the genesis file
copy:
remote_src: true
src: /tmp/genesis.json
dest: /home/{{ ansible_user }}/.sifnoded/config
Loading

0 comments on commit 0dbfc52

Please sign in to comment.