From 20b00afa56deb316f88c8c7eac808f03f74d026c Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Mon, 19 May 2025 14:50:11 +0530 Subject: [PATCH] Update create validator playbook to be able to use it in a new machine --- .../first-validator-vars.example.yml | 5 +- .../first-validator/run-first-validator.yml | 74 ------------------- playbooks/validator/create-validator.yml | 54 +++++++++++++- .../mainnet-laconicd/create-validator.sh | 6 ++ 4 files changed, 60 insertions(+), 79 deletions(-) delete mode 100644 playbooks/first-validator/run-first-validator.yml diff --git a/playbooks/first-validator/first-validator-vars.example.yml b/playbooks/first-validator/first-validator-vars.example.yml index 5df97ac..5e6c724 100644 --- a/playbooks/first-validator/first-validator-vars.example.yml +++ b/playbooks/first-validator/first-validator-vars.example.yml @@ -1,7 +1,4 @@ +# Variables used by generate-genesis.yml cerc_moniker: "LaconicMainnetNode" cerc_chain_id: "laconic-mainnet" -min_gas_price: 0.001 -cerc_loglevel: "info" key_name: "laconic-validator" -genesis_file: "" -staking_amount_file: "" diff --git a/playbooks/first-validator/run-first-validator.yml b/playbooks/first-validator/run-first-validator.yml deleted file mode 100644 index 514c3fe..0000000 --- a/playbooks/first-validator/run-first-validator.yml +++ /dev/null @@ -1,74 +0,0 @@ ---- -- name: Run mainnet validator node - hosts: localhost - vars_files: - - first-validator-vars.yml - vars: - data_directory: "{{ lookup('env', 'DATA_DIRECTORY') }}" - mainnet_deployment_dir: "{{ lookup('env', 'MAINNET_DEPLOYMENT_DIR') }}" - spec_file: "{{data_directory}}/laconicd-spec.yml" - spec_template: "./templates/specs/spec-template.yml.j2" - 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 required key files are not defined - fail: - msg: >- - Required key files are not defined. - Please set genesis_file in first-validator-vars.yml. - when: not genesis_file - - - name: Fetch laconicd stack - shell: laconic-so fetch-stack git.vdb.to/cerc-io/laconicd-stack --git-ssh --pull - - - name: Setup required repositories - shell: > - laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd - setup-repositories --git-ssh --pull - - - name: Build container images - shell: | - laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd build-containers --force-rebuild - - - name: Create deployment spec file - shell: | - laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd deploy init --output {{ spec_file }} - - - name: Replace network section in spec_file - shell: > - yq eval '(.network) = load("{{ spec_template }}").network' -i {{ spec_file }} - - - 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 }} - - - name: Create config.env - copy: - dest: "{{data_directory}}/{{ mainnet_deployment_dir }}/config.env" - content: | - CERC_MONIKER: "{{ cerc_moniker }}" - CERC_CHAIN_ID: "{{ cerc_chain_id }}" - MIN_GAS_PRICE: "{{ min_gas_price }}" - CERC_LOGLEVEL: "{{ cerc_loglevel }}" - mode: '0777' - - - name: Ensure tmp directory exists inside laconicd-data - file: - path: "{{data_directory}}/{{ mainnet_deployment_dir }}/data/laconicd-data/tmp" - state: directory - mode: '0755' - - - 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' - - - name: Run validator node - shell: | - laconic-so deployment --dir {{data_directory}}/{{ mainnet_deployment_dir }} start diff --git a/playbooks/validator/create-validator.yml b/playbooks/validator/create-validator.yml index 85317e5..1effa55 100644 --- a/playbooks/validator/create-validator.yml +++ b/playbooks/validator/create-validator.yml @@ -4,7 +4,9 @@ vars: data_directory: "{{ lookup('env', 'DATA_DIRECTORY') }}" deployment_dir: "{{ lookup('env', 'MAINNET_DEPLOYMENT_DIR') }}" + spec_file: "{{data_directory}}/laconicd-validator-spec.yml" key_name: "{{ lookup('env', 'KEY_NAME') }}" + node_url: "{{ lookup('env', 'NODE_URL') }}" tasks: - name: Fail if DATA_DIRECTORY or MAINNET_DEPLOYMENT_DIR env vars are not set fail: @@ -13,6 +15,56 @@ 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 required key files are not defined + fail: + msg: >- + Required key files are not defined. + 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 + + - name: Setup required repositories + shell: > + laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd + setup-repositories --git-ssh --pull + + - name: Build container images + shell: | + laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd build-containers + + - name: Create deployment spec file + shell: | + laconic-so --stack ~/cerc/laconicd-stack/stack-orchestrator/stacks/mainnet-laconicd deploy init --output {{ spec_file }} + + - 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 }} + + - name: Create config.env + copy: + dest: "{{data_directory}}/{{ mainnet_deployment_dir }}/config.env" + content: | + CERC_MONIKER: "{{ cerc_moniker }}" + CERC_CHAIN_ID: "{{ cerc_chain_id }}" + CERC_PEERS: "{{ cerc_peers }}" + MIN_GAS_PRICE: "{{ min_gas_price }}" + CERC_LOGLEVEL: "{{ cerc_loglevel }}" + mode: '0777' + + - name: Ensure tmp directory exists inside laconicd-data + file: + path: "{{data_directory}}/{{ mainnet_deployment_dir }}/data/laconicd-data/tmp" + 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: Prompt for validator private key vars: private_key_prompt: "Please enter your validator private key: " @@ -32,4 +84,4 @@ - name: Run create-validator script shell: | - laconic-so deployment --dir {{ data_directory }}/{{ deployment_dir }} exec laconicd "KEY_NAME={{ key_name }} /scripts/create-validator.sh" + laconic-so deployment --dir {{ data_directory }}/{{ deployment_dir }} exec laconicd "KEY_NAME={{ key_name }} NODE_URL={{ node_url }} /scripts/create-validator.sh" diff --git a/stack-orchestrator/config/mainnet-laconicd/create-validator.sh b/stack-orchestrator/config/mainnet-laconicd/create-validator.sh index e9c04aa..597706b 100755 --- a/stack-orchestrator/config/mainnet-laconicd/create-validator.sh +++ b/stack-orchestrator/config/mainnet-laconicd/create-validator.sh @@ -22,6 +22,11 @@ if [ -z "$CERC_MONIKER" ]; then exit 1 fi +if [ -z "$NODE_URL" ]; then + echo "NODE_URL environment variable not set, exiting..." + exit 1 +fi + # Set staking amount stake_amount=$(jq -r '.common_staking_amount' "$staking_amount_file") @@ -47,4 +52,5 @@ laconicd tx staking create-validator "$validator_json" \ --gas-prices $MIN_GAS_PRICE$DENOM \ --from $KEY_NAME \ --keyring-backend $KEYRING \ + --node $NODE_URL \ --yes