diff --git a/.gitignore b/.gitignore index abaaaab..f6d522d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ *-deployment *-spec.yml + +# Validator playbook vars +playbooks/validator/validator-vars.yml diff --git a/playbooks/README.md b/playbooks/README.md new file mode 100644 index 0000000..c3cb8e7 --- /dev/null +++ b/playbooks/README.md @@ -0,0 +1,50 @@ +# playbooks + +## Ansible Installation + +- Install [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-and-upgrading-ansible-with-pip) + +- Add location of the directory containing the ansible binary to your `PATH` + +- Set Locale Encoding to `UTF-8` + + Ansible requires the locale encoding to be `UTF-8`. You can either use the `LANG` prefix when running Ansible commands or set the system-wide locale + + - Option 1: Use `LANG` Prefix in Commands + + If you prefer not to change the system-wide locale, you can use the `LANG` prefix when running Ansible commands: + + ```bash + LANG=en_US.UTF-8 ansible-playbook your_playbook.yml + ``` + + - Option 2: Set System-Wide Locale + + - Edit the `/etc/default/locale` file: + + ```bash + sudo nano /etc/default/locale + ``` + + - Set the `LANG` variable to en_US.UTF-8: + + ``` + LANG="en_US.UTF-8" + ``` + + - Reboot your system or log out and log back in to apply the changes + + - Reference: + +- Verify ansible installation by running the following command: + + ```bash + ansible --version + # ansible [core 2.17.2] + ``` + +- Install `sshpass` used for automating SSH password authentication + + ```bash + sudo apt-get install sshpass + ``` \ No newline at end of file diff --git a/playbooks/validator/README.md b/playbooks/validator/README.md new file mode 100644 index 0000000..7acffbb --- /dev/null +++ b/playbooks/validator/README.md @@ -0,0 +1,67 @@ +# validator + +This directory contains playbooks for setting up and managing a validator on the Laconic chain. There are two main playbooks: + +* `create-validator.yml` - Creates a validator on an already running node +* (Coming soon) `setup-validator.yml` - Sets up and runs a validator node + +## Prerequisites + +- [Ansible](../README.md#ansible-installation) +- [Stack orchestrator](https://git.vdb.to/cerc-io/testnet-ops/src/branch/main/stack-orchestrator-setup) +- Private key or mnemonic of validator account from previous testnet + - Use + +## Configuration + +* Set the required environment variables: + ```bash + export DATA_DIRECTORY=/path/to/deployment/parent/directory + export DEPLOYMENT_DIR=validator-laconicd-deployment + ``` + +* Copy the example variables file and edit it: + ```bash + cp validator-vars.example.yml validator-vars.yml + ``` + +* Edit `validator-vars.yml` to set your validator parameters: + ```yaml + # Chain configuration + cerc_moniker: "YourValidatorName" # Your validator's name + cerc_chain_id: "laconic-mainnet" # Chain ID + + # TODO: Add persistent peer addresses + cerc_peers: "" # Comma-separated list of peers + ``` + +## Creating a Validator + +To create a validator: + +* Make sure your validator node is running and synced + + +* Set key name used for importing validator account + ```bash + export KEY_NAME= + ``` + +* Run the create-validator playbook: + ```bash + ansible-playbook playbooks/validator/create-validator.yml + ``` + +## Verification + +After running the playbook, you can verify your validator was created by: + +* Check the validator list: + ```bash + laconic-so deployment --dir $DATA_DIRECTORY/$DEPLOYMENT_DIR exec laconicd 'laconicd query staking validators' + ``` + +* Check your validator's details: + ```bash + laconic-so deployment --dir $DATA_DIRECTORY/$DEPLOYMENT_DIR exec laconicd 'laconicd query staking validator $(laconicd keys show validator --bech val -a)' + ``` diff --git a/playbooks/validator/create-validator.yml b/playbooks/validator/create-validator.yml new file mode 100644 index 0000000..fe6e1b9 --- /dev/null +++ b/playbooks/validator/create-validator.yml @@ -0,0 +1,27 @@ +--- +- name: Create validator on running chain + hosts: localhost + vars_files: + - validator-vars.yml + vars: + data_directory: "{{ lookup('env', 'DATA_DIRECTORY') }}" + deployment_dir: "{{ lookup('env', 'DEPLOYMENT_DIR') }}" + key_name: "{{ lookup('env', 'KEY_NAME') }}" + tasks: + - name: Fail if DATA_DIRECTORY or DEPLOYMENT_DIR env vars are not set + fail: + msg: >- + Required environment variables are not set. + Please export both DATA_DIRECTORY and DEPLOYMENT_DIR before running the playbook. + when: lookup('env', 'DATA_DIRECTORY') == '' or lookup('env', 'DEPLOYMENT_DIR') == '' + + - name: Fail if neither pvt_key nor mnemonic is set + fail: + msg: >- + Neither private key (pvt_key) nor mnemonic is set in validator-vars.yml. + Please set one of them to create the validator. + when: not pvt_key and not mnemonic + + - name: Run create-validator script + shell: | + laconic-so deployment --dir {{data_directory}}/{{deployment_dir}} exec laconicd "export KEY_NAME={{ key_name }} /scripts/create-validator.sh" diff --git a/playbooks/validator/validator-vars.example.yml b/playbooks/validator/validator-vars.example.yml new file mode 100644 index 0000000..091d7e6 --- /dev/null +++ b/playbooks/validator/validator-vars.example.yml @@ -0,0 +1,6 @@ +# Chain configuration +cerc_moniker: +cerc_chain_id: "laconic-mainnet" +cerc_peers: # Comma-separated list of peers +min_gas_price: 0.001 +cerc_loglevel: "info" diff --git a/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml b/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml index 33d3b26..f0b18c0 100644 --- a/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml +++ b/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml @@ -4,14 +4,15 @@ services: image: cerc/laconicd:local command: ["bash", "-c", "/opt/run-laconicd.sh"] environment: - CERC_MONIKER: ${CERC_MONIKER:-TestnetNode} - CERC_CHAIN_ID: ${CERC_CHAIN_ID:-laconic_9000-1} + CERC_MONIKER: ${CERC_MONIKER} + CERC_CHAIN_ID: ${CERC_CHAIN_ID:-laconic-mainnet} CERC_PEERS: ${CERC_PEERS} MIN_GAS_PRICE: ${MIN_GAS_PRICE:-0.001} CERC_LOGLEVEL: ${CERC_LOGLEVEL:-info} volumes: - laconicd-data:/root/.laconicd - ../config/mainnet-laconicd/run-laconicd.sh:/opt/run-laconicd.sh + - ../config/mainnet-laconicd/create-validator.sh:/scripts/create-validator.sh ports: - "6060" - "26657" diff --git a/stack-orchestrator/config/mainnet-laconicd/create-validator.sh b/stack-orchestrator/config/mainnet-laconicd/create-validator.sh new file mode 100644 index 0000000..f714877 --- /dev/null +++ b/stack-orchestrator/config/mainnet-laconicd/create-validator.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +DENOM=alnt + +# Create validator with fixed parameters +laconicd tx staking create-validator \ + --amount 900000000$DENOM \ + --pubkey $(laconicd tendermint show-validator) \ + --moniker "$CERC_MONIKER" \ + --chain-id "$CERC_CHAIN_ID" \ + --commission-rate 0.0 \ + --commission-max-rate 0.0 \ + --commission-max-change-rate 0.0 \ + --min-self-delegation 1 \ + --gas auto \ + --gas-adjustment 1.5 \ + --gas-prices $MIN_GAS_PRICE$DENOM \ + --from $KEY_NAME \ + --yes