8000 feat: namada mainnet services by alexandrglaznyov · Pull Request #6 · MELLIFERA-Labs/crun · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: namada mainnet services #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ python crun.py

## Supported networks

- Namada mainnet
- Lava testnet
- Lava mainnet
- Warden testnet
Expand Down
8 changes: 4 additions & 4 deletions crun.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ def install(network_name, extra_vars):
print_error('Network %s not found' % network_name)
return
final_config = {**default_vars, **config, **ext}
if os.path.exists(final_config['cosmos_folder']):
print_error('Cosmos folder %s already exists. Please remove it before running the installation or change "cosmos_folder" var with --extra-var option' % final_config['cosmos_folder'])
return
# if os.path.exists(final_config['cosmos_folder']):
# print_error('Cosmos folder %s already exists. Please remove i 10000 t before running the installation or change "cosmos_folder" var with --extra-var option' % final_config['cosmos_folder'])
# return

if os.geteuid() != 0:
print_error('Installation requires root privileges. Creating services file and start systemd unit.\nPlease run: sudo crun install %s' % network_name)
return
Expand Down
31 changes: 31 additions & 0 deletions resources/playbook/group_vars/namada_mainnet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
chain_id: namada.5f5de2dd1b88cba30586420
netname: namada_mainnet

version: v1.0.0

download_binary_url: https://storage.mellifera.network/bins/namada/{{ version }}/namada-v1.0.0.tar.lz4
cometbft_download_binary_url: https://storage.mellifera.network/bins/general/cometbft

namada_nerwork_configs_server: https://github.com/anoma/namada-mainnet-genesis/releases/download/mainnet-genesis

genesis: https://storage.mellifera.network/namada_mainnet/genesis.json
addressbook: https://storage.mellifera.network/namada_mainnet/addrbook.json
snapshot: https://storage.mellifera.network/namada_mainnet/snapshot_latest.tar.lz4

peers: "tcp://05309c2cce2d163027a47c662066907e89cd6b99@104.251.123.123:26656,tcp://54386c1252ecabe5ba1fae2f083b37ca5ebd57dc@192.64.82.62:26656,tcp://2bf5cdd25975c239e8feb68153d69c5eec004fdb@64.118.250.82:46656,tcp://509f1e843cf881650a4151aa804ddd7a7188e88f@195.201.197.246:32656,tcp://3879583b9c6b1ac29d38fefb5a14815dd79282d6@peer-mainnet-namada.grandvalleys.com:38656,tcp://96f7945f9470faacce66888d798bf1f131913b6c@namada-mainnet-peer.denodes.xyz:26656,tcp://ac1976c8d2b6fcd75643e0e17e44cb7b00b203d3@139.45.205.58:26656,tcp://e75f49448703666b26eb6f414e044fdb6842dd9a@37.27.56.233:26656,tcp://2583e978c1d267a5a22975a3aa2b5f7a0e9f9b2a@0xcryptovestor.com:28656,tcp://eaa6bda69dc3281186b5f150c21e62e6e4325d34@152.53.104.210:26656"
seeds: "tcp://05309c2cce2d163027a47c662066907e89cd6b99@14.243.91.37:16656,tcp://509f1e843cf881650a4151aa804ddd7a7188e88f@195.201.197.246:32656,tcp://75f923ea0a181a6ae917a00cfe81d780c3d1d11a@95.216.78.215:26656,tcp://eaa6bda69dc3281186b5f150c21e62e6e4325d34@152.53.104.210:26656"

cosmos_folder: '.local/share'

custom_port_prefix: 236
service_name: namadad

state_sync_rpc: "https://namada-mainnet-rpc.mellifera.network:443"
state_sync_peer: "b7f19137e79ed78319f407c3e0fd6d86a98da5cf@namada-mainnet-ps.mellifera.network:26656"

# public endpoints
public_rpc: "https://namada-mainnet-rpc.mellifera.network:443"
public_seed: "b7f19137e79ed78319f407c3e0fd6d86a98da5cf@namada-mainnet-ps.mellifera.network:26656"
public_rest: "https://namada-mainnet-indexer.mellifera.network"
public_grpc: "https://namada-mainnet-masp.mellifera.network"

25 changes: 17 additions & 8 deletions resources/playbook/local.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
- name: Install node locally
- name: Install node locally
hosts: localhost
become: true # Enables privilege escalation
roles:
- cosmos_software
- cosmos_install
- cosmos_init
- cosmos_configure
- cosmos_start
become: true
tasks:
- name: Include Namada role
include_role:
name: cosmos_namada_configure
when: netname == 'namada_mainnet'

- name: Include other roles
include_role:
name: "{{ item }}"
loop:
- cosmos_software
- cosmos_install
- cosmos_init
- cosmos_configure
- cosmos_start
when: netname != 'namada_mainnet'
162 changes: 162 additions & 0 deletions resources/playbook/roles/cosmos_namada_configure/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
- name: register public ip
uri:
url: 'https://api.ipify.org?format=json'
register: public_ip

- name: Check if namada binary is already downloaded
stat:
path: /usr/local/bin/namada
register: namada_stat

- name: Download namada binary
become: true
ansible.builtin.shell: |
rm -rf /usr/local/bin/namada*
curl -L {{ download_binary_url }} | tar -Ilz4 -xf - -C /usr/local/bin/
when: not namada_stat.stat.exists

- name: Check if cometbft binary is already downloaded
stat:
path: /usr/local/bin/cometbft
register: cometbft_stat

- name: Download CometBFT binary
become: true
ansible.builtin.shell: |
rm -rf /usr/local/bin/cometbft
wget -P /usr/local/bin {{ cometbft_download_binary_url }}
chmod +x /usr/local/bin/cometbft
when: not cometbft_stat.stat.exists

- name: Export environment variables to .bashrc
become: true
ansible.builtin.lineinfile:
path: "/home/{{ ansible_env.USER }}/.bashrc"
line: "export {{ item.key }}={{ item.value }}"
create: yes
loop:
- { key: 'NAMADA_NETWORK_CONFIGS_SERVER', value: '{{ genesis }}' }
- { key: 'XDG_DATA_HOME', value: "{{ ansible_env.HOME }}/{{ cosmos_folder }}" }

- name: Reload bashrc
become: true
ansible.builtin.shell: ". /home/ubuntu/.bashrc"

- name: Force install
block:
- name: Ensure that service is stopped
ansible.builtin.systemd:
name: '{{ service_name }}'
state: stopped
become: true
ignore_errors: true

- name: Ensure that the folder does not exist
ansible.builtin.file:
path: '{{ ansible_env.HOME }}/{{ cosmos_folder }}/namada'
state: absent
when: force_install is defined

- name: Init Node
ansible.builtin.command:
cmd: 'namadac utils join-network --chain-id {{ chain_id }}'
environment:
NAMADA_NETWORK_CONFIGS_SERVER: "{{ namada_nerwork_configs_server }}"
XDG_DATA_HOME: "{{ ansible_env.HOME }}/{{ cosmos_folder }}"

- name: Update peers in config.toml file
lineinfile:
path: '{{ ansible_env.HOME }}/{{ cosmos_folder }}/namada/{{ chain_id }}/config.toml'
regexp: '^persistent_peers ='
line: 'persistent_peers = "{{ peers }}"'
state: present
when: peers is defined

- name: Update seeds in config.toml file
lineinfile:
path: '{{ ansible_env.HOME }}/{{ cosmos_folder }}/namada/{{ chain_id }}/config.toml'
regexp: '^seeds ='
line: 'seeds = "{{ seeds }}"'
state: present
when: seeds is defined

- name: Adjust config.toml port
lineinfile:
path: '{{ ansible_env.HOME }}/{{ cosmos_folder }}/namada/{{ chain_id }}/config.toml'
regexp: '{{ item.key }}'
line: '{{ item.value }}'
loop: '{{ config_port_changes | dict2items }}'

- name: Set up external address
lineinfile:
path: '{{ ansible_env.HOME }}/{{ cosmos_folder }}/namada/{{ chain_id }}/config.toml'
regexp: 'external_address = "'
line: 'external_address = "{{ public_ip.json.ip }}:{{ custom_port_prefix }}56"'
state: present

- name: Create cometbft and config directories
ansible.builtin.file:
path: "{{ ansible_env.HOME }}/{{ cosmos_folder }}/namada/{{ chain_id }}/cometbft/config"
state: directory
mode: '0755'

- name: Dowload addrbook
ansible.builtin.get_url:
url: '{{ addressbook }}'
dest: '{{ ansible_env.HOME }}/{{ cosmos_folder }}/namada/{{ chain_id }}/cometbft/config/addrbook.json'
mode: '0644'
force: true
when: addressbook is defined

- name: Download and wait for snapshot
block:
- name: Download snapshot
ansible.builtin.shell: |
curl -L {{ snapshot }} | tar -Ilz4 -xf - -C {{ ansible_env.HOME }}/{{ cosmos_folder }}/namada/{{ chain_id }}
register: snapshot_download
async: 3000
poll: 0
args:
executable: /bin/bash

- name: Wait for snapshot download
ansible.builtin.async_status:
jid: "{{ snapshot_download.ansible_job_id }}"
register: job_status
until: job_status.finished
retries: 1000
delay: 5
when: install_from == 'snapshot'

- name: Use state sync
block:
- name: Use state sync peer
lineinfile:
path: '{{ ansible_env.HOME }}/{{ cosmos_folder }}/namada/{{ chain_id }}/config.toml'
regexp: '^persistent_peers ='
line: 'persistent_peers = "{{ state_sync_peer }}"'
state: present
when: state_sync_peer is defined and state_sync_peer | length > 0

- name: Apply state sync settings
shell: "{{ lookup('template', 'use_state_sync.sh.j2') }}"
args:
executable: /bin/bash
when: install_from == 'state_sync'

- name: Copy service file
become: true
ansible.builtin.template:
src: 'namada.service.j2'
dest: '/etc/systemd/system/{{ service_name }}.service'
owner: root
group: root
mode: '0644'

- name: S 9E7A tart namada service
become: true
ansible.builtin.systemd:
name: '{{ service_name }}'
state: restarted
daemon_reload: true
enabled: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=namada service
After=network-online.target

[Service]
User={{ ansible_env.USER }}
WorkingDirectory={{ ansible_env.HOME }}/{{ cosmos_folder }}/namada
Environment=CMT_LOG_LEVEL=p2p:none,pex:error
Environment=NAMADA_CMT_STDOUT=true
ExecStart=/usr/local/bin/namada ledger run
StandardOutput=journal
StandardError=journal
Restart=always
RestartSec=10
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
STATE_SYNC_RPC="{{ state_sync_rpc }}"
LATEST_HEIGHT=$(curl -s $STATE_SYNC_RPC/block | jq -r .result.block.header.height); \
BLOCK_HEIGHT=$((LATEST_HEIGHT - 2300)); \
TRUST_HASH=$(curl -s "$STATE_SYNC_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$STATE_SYNC_RPC,$STATE_SYNC_RPC\"| ; \
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"|" {{ ansible_env.HOME }}/{{ cosmos_folder }}/namada/{{ chain_id }}/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
config_port_changes:
'laddr = "tcp://0.0.0.0:26656"': 'laddr = "tcp://0.0.0.0:{{ custom_port_prefix }}56"'
'laddr = "tcp://127.0.0.1:26657"': 'laddr = "tcp://0.0.0.0:{{ custom_port_prefix }}57"'
'proxy_app = "tcp://127.0.0.1:26658"': 'proxy_app = "tcp://127.0.0.1:{{ custom_port_prefix }}58"'
'prometheus_listen_addr = ":26660"': 'prometheus_listen_addr = ":{{ custom_port_prefix }}61"'

0