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: #14
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
Prathamesh Musale 2024-08-19 09:57:54 +00:00 committed by nabarun
parent 77decda197
commit f28e95fb33
2 changed files with 60 additions and 3 deletions

View File

@ -0,0 +1,50 @@
#!/bin/bash
# Exit on error
set -e
set -u
# Check args
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <stage1-participants-json> <stage1-allocations-json>"
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"

View File

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