Skip to content

Commit 409c870

Browse files
committed
Add archive_node toggle and chain_path option
1 parent ccee0c6 commit 409c870

File tree

13 files changed

+108
-42
lines changed

13 files changed

+108
-42
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vagrant/
2-
inventory
2+
inventory
3+
polkadot_debug.yml

README.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ cp inventory.sample inventory
3333

3434
Needless to say, you need to update the dummy values in the inventory file. For each Kusama/Polkadot node, you need to update:
3535

36-
1. Server IP
37-
2. validator_name (especially important if you want to participate in the Thousand Validators Program)
38-
3. log_name (so your central monitoring server knows which node it is)
39-
4. telemetryUrl
36+
1. Server IP: Your server public IP
37+
2. validator_name: This is the node name that will show up on telemtry monitoring board. It is especially important if you want to participate in the Thousand Validators Program. For us, we use something like `polkachu-kusama-01` and `polkachu-polkadot-02` to keep it unique and organized.
38+
3. log_name: This is for your internal central monitoring server. We just use something like `kusama1` and `polkadot2` to keep it simple.
39+
4. telemetryUrl: Most likely you will use `wss://telemetry-backend.w3f.community/submit/`
40+
5. archive_node (optional): Set this to true if you want to run an archive node. An archive node is not required for a validator. An archive node has the complete chain data and requires much larger storage space. Most validators do not need an archive node.
41+
6. chain_path (optional): You can set an alternative path to store chain data. This is especially useful when you run an archive node and want to store chain data on a mounted disk. A mounted disk offers more flexibility when you want to wrap disk, increase or decrease disk size, etc.
4042

4143
You will also need to update:
4244

@@ -59,7 +61,7 @@ The structure allows you to target `vars` to each node, or either Kusama or Polk
5961

6062
Make sure that you are familiar with the files in the `group_vars` folder. They follow this clustered structure closely. The files in this folder often need to be changed to stay up to date with the latest releases. I, for one, bump these program versions religiously so I live on the cutting edge!
6163

62-
## Main Playbook to Set Up a Kusama/Polkadot Validator (Archive Node)
64+
## Main Playbook to Set Up a Kusama/Polkadot Validator (Pruned Node)
6365

6466
The key Ansible playbook is `polkadot_full_setup.yml`. It will set up a fresh validator from scratch. Notice that it will restore from a snapshot from https://polkashots.io. It is very possible that you will get an error on the checksum of data to restore in your first attempt because the snapshot is updated regularly. When this happens, update the files accordingly.
6567

@@ -74,19 +76,33 @@ Notice that you need to specify a target when you run this playbook (and other p
7476
1. Prevent you from updating all nodes by mistake
7577
2. Allow you to experiment a move on a low-risk node before rolling out to the whole cluster
7678

77-
## Various Playbooks for Different Purposes
79+
## Main Playbook to Set Up a Kusama/Polkadot Pruned Node
80+
81+
The main setup playbook is:
82+
83+
```bash
84+
ansible-playbook -i inventory polkadot_full_archive_node_setup.yml -e "target=VALIDATOR_TARGET"
85+
```
86+
87+
Most validators DO NOT need archive node.
88+
89+
## A Pitfall
90+
91+
We introduced pruned node / archive node toggle in the version 0.2.0 release. The database for pruned node and archive node is not compatible. If you have trouble start your `polkadot` service, a simple trouble-shooting method is just to delete the whole polkadot `db` directory.
92+
93+
## Other Playbooks for Different Purposes
7894

7995
The most commonly used playbooks are:
8096

81-
| Playbook | Description |
82-
| ------------------------- | ----------------------------------------------------------------------------------------- |
83-
| `polkadot_full_setup.yml` | Run the initial full setup |
84-
| `polkadot_prepare.yml ` | Do the prep work, such as firewall, set up a proxy, copy service files, create users, etc.|
85-
| `polkadot_update.yml` | Update the Polkadot binary and restart the service. You probably need to use it regularly |
86-
| `polkadot_restore.yml` | Restore the Polkadot database with a screenshot. Only useful for initial setup |
87-
| `node_exporter.yml` | Update Node Exporter |
88-
| `process_exporter.yml` | Update Process Exporter |
89-
| `promtail.yml` | Update Promtail |
97+
| Playbook | Description |
98+
| ------------------------- | ------------------------------------------------------------------------------------------ |
99+
| `polkadot_full_setup.yml` | Run the initial full setup |
100+
| `polkadot_prepare.yml ` | Do the prep work, such as firewall, set up a proxy, copy service files, create users, etc. |
101+
| `polkadot_update.yml` | Update the Polkadot binary and restart the service. You probably need to use it regularly |
102+
| `polkadot_restore.yml` | Restore the Polkadot database with a screenshot. Only useful for initial setup |
103+
| `node_exporter.yml` | Update Node Exporter |
104+
| `process_exporter.yml` | Update Process Exporter |
105+
| `promtail.yml` | Update Promtail |
90106

91107
The less commonly used playbooks are:
92108

group_vars/polkadot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
polkadot_network_id: polkadot
33
chain: polkadot
4-
polkadot_db_snapshot_url: 'https://dot-rocksdb.polkashots.io/polkadot-5547438.RocksDb.7z'
5-
polkadot_db_snapshot_checksum: '441f6a623a1f68e2afa558b3432e504955bae640d2155a05ddf7460452472dec'
4+
polkadot_db_snapshot_url: 'https://dot-rocksdb.polkashots.io/polkadot-5771552.RocksDb.7z'
5+
polkadot_db_snapshot_checksum: '02e6bff302ff9c43db649fb08a3576fee8adcc38c0c787ae08386a9ee3fdec25'
66
# Emergence use when we need to downgrade polkadot
77
# polkadot_version: "0.8.30"
88
# polkadot_checksum: "9dddd2ede827865c6e81684a138b0f282319e07f717c166b92834699f43274cd"

inventory.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
192.168.1.10 validator_name=polkachu-kusama-test-0 log_name=kusama1 telemetryUrl=wss://telemetry.polkadot.io/submit/
33

44
[polkadot1]
5-
192.168.1.20 validator_name=polkachu-polkadot-test-0 log_name=polkadot1 telemetryUrl=wss://telemetry.polkadot.io/submit/
5+
192.168.1.20 validator_name=polkachu-polkadot-test-0 log_name=polkadot1 telemetryUrl=wss://telemetry.polkadot.io/submit/ chain_path="your_alternative_path_to_store_chain_data' archive_node=true
66

77
[kusama:children]
88
kusama1
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
- name: Wait for system ready
3+
hosts: '{{ target }}'
4+
gather_facts: false
5+
become: true
6+
tasks:
7+
- name: check archive node flag
8+
fail:
9+
msg: 'you need to set the archive_node flag as true'
10+
when: archive_node is not defined
11+
12+
- name: Wait for nodes to become reachable
13+
wait_for_connection:
14+
15+
- name: Update and upgrade the machine
16+
apt:
17+
upgrade: dist
18+
update_cache: true
19+
20+
- name: Validator Archive Node Setup
21+
hosts: '{{ target }}'
22+
become: true
23+
gather_facts: false
24+
roles:
25+
- validator_polkadot_prepare
26+
- process_exporter
27+
- node_exporter
28+
- promtail
29+
- validator_polkadot_update

polkadot_full_setup.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: Wait for system ready
3-
hosts: "{{ target }}"
3+
hosts: '{{ target }}'
44
gather_facts: false
55
become: true
66
tasks:
@@ -13,13 +13,13 @@
1313
update_cache: true
1414

1515
- name: Validator Full Setup
16-
hosts: "{{ target }}"
16+
hosts: '{{ target }}'
1717
become: true
1818
gather_facts: false
1919
roles:
2020
- validator_polkadot_prepare
21-
- validator_polkadot_update
2221
- process_exporter
2322
- node_exporter
2423
- promtail
24+
- validator_polkadot_update
2525
- validator_polkadot_restore
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: backup keystore
33
copy:
4-
src: "/home/polkadot/.local/share/polkadot/chains/{{ polkadot_network_id }}/keystore"
5-
dest: /home/polkadot/keystore
4+
src: "{{ chain_path | default('/home/polkadot/.local/share/polkadot') }}/chains/{{ polkadot_network_id }}/keystore"
5+
dest: '/home/polkadot/keystore'
66
remote_src: yes

roles/validator_polkadot_prepare/tasks/user.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
- name: add polkadot user
88
user:
99
name: polkadot
10-
groups: ["polkadot"]
10+
groups: ['polkadot']
1111
append: yes
1212
shell: /bin/bash
13+
14+
- name: set folder permission if there is an alternative base_path for polkadot
15+
file:
16+
path: '{{ chain_path }}'
17+
state: directory
18+
owner: polkadot
19+
group: polkadot
20+
recurse: true
21+
mode: 0755
22+
when: chain_path is defined
23+
changed_when: false

roles/validator_polkadot_prepare/templates/polkadot.service.j2

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{% set execution = hostvars[inventory_hostname].execution|default(None) %}
22
{% set wasm_execution = hostvars[inventory_hostname].wasm_execution|default(None) %}
3+
{% set archive_node = hostvars[inventory_hostname].archive_node|default(false) %}
4+
{% set chain_path = hostvars[inventory_hostname].chain_path|default(None) %}
35

46
[Unit]
57
Description=Polkadot Node
@@ -14,10 +16,17 @@ ExecStart=/usr/local/bin/polkadot \
1416
{% if wasm_execution is not none and wasm_execution|length %}
1517
--wasm-execution {{ wasm_execution }} \
1618
{% endif %}
19+
{% if chain_path is not none and chain_path|length %}
20+
--base-path {{ chain_path }} \
21+
{% endif %}
1722
--validator \
1823
--rpc-methods=Unsafe \
24+
{% if archive_node is not none and archive_node | bool is sameas true %}
25+
--pruning=archive \
26+
{% else %}
1927
--unsafe-pruning \
2028
--pruning=1000 \
29+
{% endif %}
2130
-lsync=warn,afg=warn,babe=warn \
2231
--public-addr=/ip4/{{ hostvars[inventory_hostname].public_ip.json.ip }}/tcp/{{ proxy_port }} \
2332
--listen-addr=/ip4/127.0.0.1/tcp/{{ p2p_port }} \

roles/validator_polkadot_restart/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
- name: wait for polkadot service started
1111
uri:
1212
url: http://localhost:9933
13-
status_code: "200"
14-
method: "POST"
13+
status_code: '200'
14+
method: 'POST'
1515
body_format: json
1616
body: |
1717
{ "jsonrpc":"2.0", "method":"system_health", "params":[], "id":1 }

0 commit comments

Comments
 (0)