From 80acf3c745c3078655588b7a745ae64431987d76 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Fri, 16 May 2025 10:10:42 +0530 Subject: [PATCH] Fix script to create validator in subsequent nodes --- {genesis => config}/.gitkeep | 0 docs/run-first-validator.md | 14 +++++-- docs/run-validator.md | 5 ++- playbooks/validator/create-validator.yml | 2 +- playbooks/validator/run-validator.yml | 11 ++++- .../validator/validator-vars.example.yml | 3 +- scripts/create-validator.sh | 31 -------------- .../docker-compose-mainnet-laconicd.yml | 2 +- .../mainnet-laconicd/create-validator.sh | 40 +++++++++++++++++++ 9 files changed, 67 insertions(+), 41 deletions(-) rename {genesis => config}/.gitkeep (100%) delete mode 100755 scripts/create-validator.sh create mode 100755 stack-orchestrator/config/mainnet-laconicd/create-validator.sh diff --git a/genesis/.gitkeep b/config/.gitkeep similarity index 100% rename from genesis/.gitkeep rename to config/.gitkeep diff --git a/docs/run-first-validator.md b/docs/run-first-validator.md index da5ce49..012fa44 100644 --- a/docs/run-first-validator.md +++ b/docs/run-first-validator.md @@ -129,12 +129,18 @@ laconic-so deployment --dir $DATA_DIRECTORY/$MAINNET_DEPLOYMENT_DIR exec laconicd 'laconicd query bond list' ``` -## Publish Genesis File and Node Address +## Publish required artifacts -- Copy the genesis file to [genesis](./genesis) folder: +- Copy the genesis file to [config](./config) folder: ```bash - sudo cp $DATA_DIRECTORY/$MAINNET_DEPLOYMENT_DIR/data/laconicd-data/config/genesis.json ~/cerc/laconicd-stack/genesis/mainnet-genesis.json + cp $DATA_DIRECTORY/$MAINNET_DEPLOYMENT_DIR/data/laconicd-data/config/genesis.json ~/cerc/laconicd-stack/config/mainnet-genesis.json + ``` + +- Copy the staking amount file to [config](./config) folder: + + ```bash + cp /staking-amount.json ~/cerc/laconicd-stack/config/staking-amount.json ``` - Get your node's address: @@ -145,4 +151,4 @@ - Add your node's address to [node-addresses.yml](./node-addresses.yml) -- Submit a PR with this genesis file and node address so that it is available to other validators +- Submit a PR with this genesis file, staking amount file and node address so that it is available to other validators diff --git a/docs/run-validator.md b/docs/run-validator.md index 8b00c2d..3e36182 100644 --- a/docs/run-validator.md +++ b/docs/run-validator.md @@ -33,7 +33,10 @@ ```bash # Path to the genesis file published by the first validator - genesis_file: "~/cerc/laconicd-stack/genesis/mainnet-genesis.json" + genesis_file: "~/cerc/laconicd-stack/config/mainnet-genesis.json" + + # Path to the staking amount file published by the first validator + staking_amount_file: "~/cerc/laconicd-stack/config/staking-amount.json" # Set custom moniker for the node cerc_moniker: "LaconicMainnetNode" diff --git a/playbooks/validator/create-validator.yml b/playbooks/validator/create-validator.yml index b2ef1fa..feafe29 100644 --- a/playbooks/validator/create-validator.yml +++ b/playbooks/validator/create-validator.yml @@ -27,4 +27,4 @@ - name: Run create-validator script shell: | - laconic-so deployment --dir {{ data_directory }}/{{ deployment_dir }} exec laconicd "export KEY_NAME={{ key_name }} ~/cerc/laconicd-stack/scripts/create-validator.sh" + laconic-so deployment --dir {{ data_directory }}/{{ deployment_dir }} exec laconicd "KEY_NAME={{ key_name }} /scripts/create-validator.sh" diff --git a/playbooks/validator/run-validator.yml b/playbooks/validator/run-validator.yml index 9a5bd2b..8fcc0a9 100644 --- a/playbooks/validator/run-validator.yml +++ b/playbooks/validator/run-validator.yml @@ -20,8 +20,9 @@ fail: msg: >- Required key files are not defined. - Please set genesis_file in validator-vars.yml. - when: not genesis_file + Please set genesis_file and staking_amount_file in validator-vars.yml. + when: not genesis_file or not staking_amount_file + - name: Fetch laconicd stack shell: laconic-so fetch-stack git.vdb.to/cerc-io/laconicd-stack --git-ssh --pull @@ -63,6 +64,12 @@ state: directory mode: '0755' + - name: Copy staking amount file to laconicd-data tmp directory + copy: + src: "{{ staking_amount_file }}" + dest: "{{data_directory}}/{{ mainnet_deployment_dir }}/data/laconicd-data/tmp/staking-amount.json" + mode: '0644' + - name: Copy genesis file to laconicd-data tmp directory copy: src: "{{ genesis_file }}" diff --git a/playbooks/validator/validator-vars.example.yml b/playbooks/validator/validator-vars.example.yml index 4fa9440..1590078 100644 --- a/playbooks/validator/validator-vars.example.yml +++ b/playbooks/validator/validator-vars.example.yml @@ -2,5 +2,6 @@ cerc_moniker: "LaconicMainnetNode" cerc_chain_id: "laconic-mainnet" min_gas_price: 0.001 cerc_loglevel: "info" -genesis_file: "~/cerc/laconicd-stack/genesis/mainnet-genesis.json" +genesis_file: "~/cerc/laconicd-stack/config/mainnet-genesis.json" +staking_amount_file: "~/cerc/laconicd-stack/config/staking-amount.json" cerc_peers: "" diff --git a/scripts/create-validator.sh b/scripts/create-validator.sh deleted file mode 100755 index 120089b..0000000 --- a/scripts/create-validator.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -set -e - -DENOM=alnt - -NODE_HOME=/root/.laconicd - -staking_amount_file="$NODE_HOME/tmp/staking-amount.json" -if [ ! -f "$staking_amount_file" ]; then - echo "staking-amount.json file not provided, exiting..." - exit 1 -fi - -# Set staking amount -stake_amount=$(jq -r '.common_staking_amount' "$staking_amount_file") - -# Create validator with fixed parameters -laconicd tx staking create-validator \ - --amount $stake_amount$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 diff --git a/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml b/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml index 8c5da69..f0b18c0 100644 --- a/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml +++ b/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml @@ -12,7 +12,7 @@ services: volumes: - laconicd-data:/root/.laconicd - ../config/mainnet-laconicd/run-laconicd.sh:/opt/run-laconicd.sh - - ../../scripts/create-validator.sh:/scripts/create-validator.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 100755 index 0000000..639f7d6 --- /dev/null +++ b/stack-orchestrator/config/mainnet-laconicd/create-validator.sh @@ -0,0 +1,40 @@ +#!/bin/bash +set -e + +DENOM=alnt + +NODE_HOME=/root/.laconicd +KEYRING="test" + +staking_amount_file="$NODE_HOME/tmp/staking-amount.json" +if [ ! -f "$staking_amount_file" ]; then + echo "staking-amount.json file not provided, exiting..." + exit 1 +fi + +# Set staking amount +stake_amount=$(jq -r '.common_staking_amount' "$staking_amount_file") + +# Create validator.json file +validator_json="$NODE_HOME/tmp/validator.json" +cat > "$validator_json" << EOF +{ + "pubkey": $(laconicd tendermint show-validator), + "amount": "${stake_amount}${DENOM}", + "moniker": "${CERC_MONIKER}", + "commission-rate": "0.0", + "commission-max-rate": "0.0", + "commission-max-change-rate": "0.0", + "min-self-delegation": "1" +} +EOF + +# Create validator using the JSON file +laconicd tx staking create-validator "$validator_json" \ + --chain-id "$CERC_CHAIN_ID" \ + --gas auto \ + --gas-adjustment 1.5 \ + --gas-prices $MIN_GAS_PRICE$DENOM \ + --from $KEY_NAME \ + --keyring-backend $KEYRING \ + --yes