From f28e95fb339914a7b0ed80b04f9ab9c2178779ae Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 19 Aug 2024 09:57:54 +0000 Subject: [PATCH] Add a script to generate stage1 genesis file from given participants and allocations (#14) Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675) Reviewed-on: https://git.vdb.to/cerc-io/fixturenet-laconicd-stack/pulls/14 Co-authored-by: Prathamesh Musale Co-committed-by: Prathamesh Musale --- .../generate-stage1-genesis-from-json.sh | 50 +++++++++++++++++++ .../fixturenet-laconicd/scripts/genesis.sh | 13 +++-- 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100755 stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis-from-json.sh diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis-from-json.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis-from-json.sh new file mode 100755 index 0000000..d9f4ff2 --- /dev/null +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis-from-json.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Exit on error +set -e +set -u + +# Check args +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + echo "Example: $0 ./stage-participants.json ./stage1-allocations.json" + exit 1 +fi + +STAGE1_PARTICIPANTS_FILE="$1" +STAGE1_ALLOCATIONS_FILE="$2" +STAGE1_GENESIS_DIR=stage1-genesis + +# Create a temporary target directory +mkdir -p $STAGE1_GENESIS_DIR + +# -------- + +# Copy over the stage1-participants json file for genesis.sh to use +cp $STAGE1_PARTICIPANTS_FILE "$STAGE1_GENESIS_DIR/stage1-participants.json" +echo "Copied over stage1 participants json file to mount dir" + +# Copy over the stage1-participants json file for genesis.sh to use +cp $STAGE1_ALLOCATIONS_FILE "$STAGE1_GENESIS_DIR/stage1-allocations.json" +echo "Copied over stage1 allocations json file to mount dir" + +# -------- + +# Run a script with cerc/laconicd:local to generate the genesis file +# with onboarding module state and given allocations +docker run -it \ + -v ./$STAGE1_GENESIS_DIR:/root/.laconicd \ + -v ./scripts:/scripts \ + cerc/laconicd:local bash -c "/scripts/genesis.sh" + +# Copy over the genesis file to output folder +OUTPUT_DIR=output +mkdir -p $OUTPUT_DIR +cp ./$STAGE1_GENESIS_DIR/config/genesis.json $OUTPUT_DIR/genesis.json + +echo "Genesis file for stage1 written to $OUTPUT_DIR/genesis.json" + +# -------- + +# Clean up +echo "Please remove the temporary data directory: sudo rm -rf $STAGE1_GENESIS_DIR" diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/genesis.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/genesis.sh index 3b3756a..7ebaccb 100755 --- a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/genesis.sh +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/genesis.sh @@ -17,13 +17,20 @@ stage1_genesis_file="$NODE_HOME/config/genesis.json" laconicd init $STAGE1_MONIKER --chain-id $CHAINID --default-denom alnt # Update onboarding module state with participants -participants=$(jq -c '.' $stage1_participants_file) -jq --argjson p "$participants" '.app_state.onboarding.participants = $p' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file" +jq --argfile p "$stage1_participants_file" '.app_state.onboarding.participants = $p' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file" # Disable bank module transfers -jq '.app_state["bank"]["params"]["default_send_enabled"]=false' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file" +# jq '.app_state["bank"]["params"]["default_send_enabled"]=false' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file" + +# Update staking module params +jq '.app_state["staking"]["params"]["max_validators"]=100' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file" + +# Update slashing module params +jq '.app_state["slashing"]["params"]["signed_blocks_window"]="2400"' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file" +jq '.app_state["slashing"]["params"]["min_signed_per_window"]="0.5"' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file" # Read and assign allocations +echo "Adding genesis accounts with allocations..." jq -c '.[]' "$stage1_allocations_file" | while IFS= read -r line; do cosmos_address=$(jq -r '.cosmos_address' <<< "$line") balance=$(jq -r '.balance' <<< "$line")