Add script and playbook to create validator

This commit is contained in:
Shreerang Kale 2025-05-15 17:22:46 +05:30
parent 187b254399
commit efbeed60a2
4 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,30 @@
---
- name: Create validator on running chain
hosts: localhost
vars:
data_directory: "{{ lookup('env', 'DATA_DIRECTORY') }}"
deployment_dir: "{{ lookup('env', 'MAINNET_DEPLOYMENT_DIR') }}"
key_name: "{{ lookup('env', 'KEY_NAME') }}"
pvt_key: "{{ lookup('env', 'PVT_KEY') }}"
tasks:
- name: Fail if DATA_DIRECTORY or MAINNET_DEPLOYMENT_DIR env vars are not set
fail:
msg: >-
Required environment variables are not set.
Please export both DATA_DIRECTORY and MAINNET_DEPLOYMENT_DIR before running the playbook.
when: lookup('env', 'DATA_DIRECTORY') == '' or lookup('env', 'MAINNET_DEPLOYMENT_DIR') == ''
- name: Fail if pvt_key is not set
fail:
msg: >-
Neither private key (pvt_key) is set.
Please export PVT_KEY.
when: not pvt_key
- name: Import private key in laconicd
shell: |
laconic-so deployment --dir {{ data_directory }}/{{ deployment_dir }} exec laconicd "laconicd keys import-hex {{ key_name }} {{ pvt_key }}"
- 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"

View File

@ -75,6 +75,42 @@
laconic-so deployment --dir $DATA_DIRECTORY/$MAINNET_DEPLOYMENT_DIR logs laconicd -f laconic-so deployment --dir $DATA_DIRECTORY/$MAINNET_DEPLOYMENT_DIR logs laconicd -f
``` ```
## Create Validator
- Get your private key from testnet deployment:
```bash
# Replace <testnet-deployment-dir> with the absolute path to the testnet deployment directory and <key-name> with the name of your key
docker run -it \
-v <testnet-deployment-dir>/data/laconicd-data:/root/.laconicd \
cerc/laconicd:local bash -c "laconicd keys export <key-name> --unarmored-hex --unsafe"
```
- Export required env vars:
```bash
# private key of the existing account
export PVT_KEY=<private-key-in-hex-format>
# desired key name
export KEY_NAME=<key-name>
export DATA_DIRECTORY=<data-directory>
export MAINNET_DEPLOYMENT_DIR=<mainnet-deployment-dir>
```
- Run ansible playbook to create validator on running chain:
```bash
ansible-playbook -i localhost, -c local playbooks/validator/create-validator.yml
```
- Check the validator list:
```bash
laconic-so deployment --dir $DATA_DIRECTORY/$MAINNET_DEPLOYMENT_DIR exec laconicd 'laconicd query staking validators'
```
## Register Your Node ## Register Your Node
- Get your node's address: - Get your node's address:

20
scripts/create-validator.sh Executable file
View File

@ -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

View File

@ -12,6 +12,7 @@ services:
volumes: volumes:
- laconicd-data:/root/.laconicd - laconicd-data:/root/.laconicd
- ../config/mainnet-laconicd/run-laconicd.sh:/opt/run-laconicd.sh - ../config/mainnet-laconicd/run-laconicd.sh:/opt/run-laconicd.sh
- ../config/mainnet-laconicd/create-validator.sh:/scripts/create-validator.sh
ports: ports:
- "6060" - "6060"
- "26657" - "26657"