From 9bb5aa0befb583b3737f7f5074a340a63cd6a342 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Mon, 19 May 2025 19:35:17 +0530 Subject: [PATCH] Update playbook, scripts and readme to use public key while creating gentx --- docs/run-first-validator.md | 106 +++++++++++++----- .../generate-genesis-vars.example.yml | 3 +- .../generate-genesis/generate-genesis.yml | 11 +- playbooks/validator/run-validator.yml | 8 +- .../validator/validator-vars.example.yml | 1 + .../docker-compose-mainnet-laconicd.yml | 3 +- .../create-and-collect-gentx.sh | 7 +- .../config/mainnet-laconicd/run-laconicd.sh | 9 +- 8 files changed, 113 insertions(+), 35 deletions(-) diff --git a/docs/run-first-validator.md b/docs/run-first-validator.md index bf68a95..24969fa 100644 --- a/docs/run-first-validator.md +++ b/docs/run-first-validator.md @@ -5,6 +5,63 @@ - [ansible](playbooks/README.md#ansible-installation) - [laconic-so](https://github.com/cerc-io/stack-orchestrator/?tab=readme-ov-file#install) +## Setup Validator Node + +- Run these steps in a machine where the mainnet node is to be run + +- Fetch the stack: + + ```bash + laconic-so fetch-stack git.vdb.to/cerc-io/laconicd-stack --git-ssh --pull + ``` + + This command clones the entire repository into the `~/cerc` folder + +- Copy the example variables file: + + ```bash + cp ~/cerc/laconicd-stack/playbooks/validator/validator-vars.example.yml ~/cerc/laconicd-stack/playbooks/validator/validator-vars.yml + ``` + +- Update `~/cerc/laconicd-stack/playbooks/validator/validator-vars.yml` with required values: + + ```bash + # Set custom moniker for the node + cerc_moniker: "" + + # Set is_setup to true + is_setup: true + ``` + + - Keep rest of the values empty + +- Export the data directory and mainnet deployment directory as environment variables: + + ```bash + # Parent directory where the deployment directory will live + export DATA_DIRECTORY= + + # Set mainnet deployment directory + # for eg: mainnet-laconicd-deployment + export MAINNET_DEPLOYMENT_DIR= + ``` + +- Run ansible playbook to set up your validator node: + + ```bash + ansible-playbook -i localhost, -c local ~/cerc/laconicd-stack/playbooks/validator/run-validator.yml + ``` + +- Get the public key of your node: + + ```bash + docker run -it \ + -v ./$MAINNET_DEPLOYMENT_DIR/data/laconicd-data:/root/.laconicd \ + cerc/laconicd:local bash -c "laconicd tendermint show-validator" + ``` + + NOTE: This public key is required in next step to generate the genesis file + ## Generate mainnet genesis file - Get your private key from testnet deployment: @@ -13,7 +70,7 @@ laconic-so deployment --dir exec laconicd "laconicd keys export --unarmored-hex --unsafe" ``` - NOTE: Store this key securely as it is needed in later steps + NOTE: Store this private key securely as it is needed in later steps - Stop the node for SAPO testnet: @@ -35,12 +92,6 @@ - The file will be generated in `/export/testnet-state.json` -- If mainnet node is to be setup in a new machine, fetch the stack again: - - ```bash - laconic-so fetch-stack git.vdb.to/cerc-io/laconicd-stack --git-ssh --pull - ``` - - Copy over the exported `testnet-state.json` file to target machine - Copy over the LPS lockup distribution `distribution.json` file to target machine @@ -51,6 +102,13 @@ export EXPORTED_STATE_PATH= export LPS_DISTRIBUTION_PATH= export EARLY_SUPPORTS_ACC_ADDR= + + # Parent directory where the deployment directory will live + export DATA_DIRECTORY= + + # Set mainnet deployment directory + # for eg: mainnet-laconicd-deployment + export MAINNET_DEPLOYMENT_DIR= ``` - Copy the example variables file: @@ -59,6 +117,16 @@ cp ~/cerc/laconicd-stack/playbooks/generate-genesis/generate-genesis-vars.example.yml ~/cerc/laconicd-stack/playbooks/generate-genesis/generate-genesis-vars.yml ``` +- Edit `~/cerc/laconicd-stack/playbooks/generate-genesis/generate-genesis-vars.yml` with required values: + + ```bash + # Set same moniker as set above + cerc_moniker: "" + + # Use the public key exported in previous step (make sure to wrap it with single quotes ['']) + validator_pub_key: '' + ``` + - Run playbook to use exported state for generating mainnet genesis: ```bash @@ -82,30 +150,16 @@ ## Run node -- Run these steps in a separate machine where the mainnet node is to be run - -- Fetch the stack: - - ```bash - laconic-so fetch-stack git.vdb.to/cerc-io/laconicd-stack --git-ssh --pull - ``` - - This command clones the entire repository into the `~/cerc` folder - -- Copy the example variables file: - - ```bash - cp ~/cerc/laconicd-stack/playbooks/validator/validator-vars.example.yml ~/cerc/laconicd-stack/playbooks/validator/validator-vars.yml - ``` +- Run these steps in a machine where the mainnet node is setup - Update `~/cerc/laconicd-stack/playbooks/validator/validator-vars.yml` with required values: ```bash - # Set custom moniker for the node - cerc_moniker: "" - # Set path to genesis file genesis_file: "" + + # Set is_setup to false + is_setup: false ``` - Keep rest of the values empty @@ -121,7 +175,7 @@ export MAINNET_DEPLOYMENT_DIR= ``` -- Run ansible playbook to set up and start your validator node: +- Run ansible playbook to start your validator node: ```bash ansible-playbook -i localhost, -c local ~/cerc/laconicd-stack/playbooks/validator/run-validator.yml diff --git a/playbooks/generate-genesis/generate-genesis-vars.example.yml b/playbooks/generate-genesis/generate-genesis-vars.example.yml index 5e6c724..76228e2 100644 --- a/playbooks/generate-genesis/generate-genesis-vars.example.yml +++ b/playbooks/generate-genesis/generate-genesis-vars.example.yml @@ -1,4 +1,5 @@ # Variables used by generate-genesis.yml -cerc_moniker: "LaconicMainnetNode" +cerc_moniker: "" cerc_chain_id: "laconic-mainnet" key_name: "laconic-validator" +validator_pub_key: "" diff --git a/playbooks/generate-genesis/generate-genesis.yml b/playbooks/generate-genesis/generate-genesis.yml index ea09faf..954f4a8 100644 --- a/playbooks/generate-genesis/generate-genesis.yml +++ b/playbooks/generate-genesis/generate-genesis.yml @@ -71,13 +71,13 @@ - name: Copy staking amount file to laconicd-data tmp directory copy: - src: "output/staking-amount.json" + src: "{{ lookup('env', 'PWD') }}/output/staking-amount.json" 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: "output/genesis.json" + src: "{{ lookup('env', 'PWD') }}/output/genesis.json" dest: "{{data_directory}}/{{ mainnet_deployment_dir }}/data/laconicd-data/tmp/genesis.json" mode: '0644' @@ -103,11 +103,14 @@ -e "KEY_NAME={{ key_name }}" \ -e "CERC_MONIKER={{ cerc_moniker }}" \ -e "CERC_CHAIN_ID={{ cerc_chain_id }}" \ + -e "VALIDATOR_PUB_KEY={{ validator_pub_key | to_json }}" \ cerc/laconicd:local bash -c "/scripts/create-and-collect-gentx.sh" - name: Update genesis file in output - shell: | - cp {{data_directory}}/{{ mainnet_deployment_dir }}/data/laconicd-data/config/genesis.json output/genesis.json + copy: + src: "{{data_directory}}/{{ mainnet_deployment_dir }}/data/laconicd-data/config/genesis.json" + dest: "{{ lookup('env', 'PWD') }}/output/genesis.json" + mode: '0644' - name: Clear tmp directory file: diff --git a/playbooks/validator/run-validator.yml b/playbooks/validator/run-validator.yml index eb404a4..8a00141 100644 --- a/playbooks/validator/run-validator.yml +++ b/playbooks/validator/run-validator.yml @@ -21,7 +21,7 @@ msg: >- Required key files are not defined. Please set genesis_file in validator-vars.yml. - when: not genesis_file + when: not genesis_file and not is_setup - name: Fetch laconicd stack shell: laconic-so fetch-stack git.vdb.to/cerc-io/laconicd-stack --git-ssh --pull @@ -38,14 +38,17 @@ - name: Create deployment spec file shell: | laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd deploy init --output {{ spec_file }} + when: is_setup - name: Replace network section in spec_file shell: > yq eval '(.network) = load("{{ spec_template }}").network' -i {{ spec_file }} + when: is_setup - name: Create deployment from spec file shell: | laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd deploy create --spec-file {{ spec_file }} --deployment-dir {{data_directory}}/{{ mainnet_deployment_dir }} + when: is_setup - name: Create config.env copy: @@ -56,6 +59,7 @@ CERC_PEERS: "{{ cerc_peers }}" MIN_GAS_PRICE: "{{ min_gas_price }}" CERC_LOGLEVEL: "{{ cerc_loglevel }}" + IS_SETUP: "{{ is_setup }}" mode: '0777' - name: Ensure tmp directory exists inside laconicd-data @@ -63,12 +67,14 @@ path: "{{data_directory}}/{{ mainnet_deployment_dir }}/data/laconicd-data/tmp" state: directory mode: '0755' + when: not is_setup - name: Copy genesis file to laconicd-data tmp directory copy: src: "{{ genesis_file }}" dest: "{{data_directory}}/{{ mainnet_deployment_dir }}/data/laconicd-data/tmp/genesis.json" mode: '0644' + when: not is_setup - name: Run validator node shell: | diff --git a/playbooks/validator/validator-vars.example.yml b/playbooks/validator/validator-vars.example.yml index d75731b..e454ac8 100644 --- a/playbooks/validator/validator-vars.example.yml +++ b/playbooks/validator/validator-vars.example.yml @@ -1,6 +1,7 @@ cerc_chain_id: "laconic-mainnet" min_gas_price: 0.001 cerc_loglevel: "info" +is_setup: false cerc_moniker: "" genesis_file: "" staking_amount_file: "" diff --git a/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml b/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml index f0b18c0..6b90588 100644 --- a/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml +++ b/stack-orchestrator/compose/docker-compose-mainnet-laconicd.yml @@ -1,6 +1,6 @@ services: laconicd: - restart: unless-stopped + restart: on-failure image: cerc/laconicd:local command: ["bash", "-c", "/opt/run-laconicd.sh"] environment: @@ -9,6 +9,7 @@ services: CERC_PEERS: ${CERC_PEERS} MIN_GAS_PRICE: ${MIN_GAS_PRICE:-0.001} CERC_LOGLEVEL: ${CERC_LOGLEVEL:-info} + IS_SETUP: ${IS_SETUP:-false} volumes: - laconicd-data:/root/.laconicd - ../config/mainnet-laconicd/run-laconicd.sh:/opt/run-laconicd.sh diff --git a/stack-orchestrator/config/mainnet-laconicd/create-and-collect-gentx.sh b/stack-orchestrator/config/mainnet-laconicd/create-and-collect-gentx.sh index b41f37c..5562047 100755 --- a/stack-orchestrator/config/mainnet-laconicd/create-and-collect-gentx.sh +++ b/stack-orchestrator/config/mainnet-laconicd/create-and-collect-gentx.sh @@ -22,6 +22,11 @@ if [ -z "$KEY_NAME" ]; then exit 1 fi +if [ -z "$VALIDATOR_PUB_KEY" ]; then + echo "VALIDATOR_PUB_KEY environment variable not set, exiting..." + exit 1 +fi + input_genesis_file=$NODE_HOME/tmp/genesis.json if [ ! -f ${input_genesis_file} ]; then echo "Genesis file not provided, exiting..." @@ -64,7 +69,7 @@ fi stake_amount=$(jq -r '.common_staking_amount' "$staking_amount_file") # Create gentx with staked amount equal to allocated balance -laconicd genesis gentx $KEY_NAME $stake_amount$DENOM --chain-id $CHAIN_ID --keyring-backend $KEYRING +laconicd genesis gentx $KEY_NAME $stake_amount$DENOM --chain-id $CHAIN_ID --keyring-backend $KEYRING --pubkey "$VALIDATOR_PUB_KEY" # Collect the gentx and validate laconicd genesis collect-gentxs diff --git a/stack-orchestrator/config/mainnet-laconicd/run-laconicd.sh b/stack-orchestrator/config/mainnet-laconicd/run-laconicd.sh index 7051bea..0ed22a4 100755 --- a/stack-orchestrator/config/mainnet-laconicd/run-laconicd.sh +++ b/stack-orchestrator/config/mainnet-laconicd/run-laconicd.sh @@ -9,7 +9,7 @@ set -e NODE_HOME=/root/.laconicd input_genesis_file=$NODE_HOME/tmp/genesis.json -if [ ! -f ${input_genesis_file} ]; then +if [ ! -f ${input_genesis_file} && [ "$IS_SETUP" = "False" ] ]; then echo "Genesis file not provided, exiting..." exit 1 fi @@ -33,6 +33,13 @@ else echo "Node data dir $NODE_HOME/data already exists, skipping initialization..." fi +echo "IS_SETUP: $IS_SETUP" + +if [ "$IS_SETUP" = "True" ]; then + echo "IS_SETUP is true, skipping genesis file setup..." + exit 0 +fi + # Use provided config files cp $input_genesis_file $NODE_HOME/config/genesis.json