Add scripts to generate genesis file for mainnet

This commit is contained in:
Prathamesh Musale 2025-05-13 17:39:09 +05:30
parent 404951bda7
commit afd2082f6e
2 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1,51 @@
#!/bin/bash
# Exit on error
set -e
set -u
# Check args
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <testnet-deployment-dir-absolute>"
exit 1
fi
TESTNET_DEPLOYMENT_DIR="$1"
MAINNET_GENESIS_DIR=mainnet-genesis
# Create a temporary target directory
mkdir -p $MAINNET_GENESIS_DIR
# --------
# Export state from testnet chain
# Use cerc/laconicd-testnet:local image for testnet laconicd build
testnet_state_file="$MAINNET_GENESIS_DIR/testnet-state.json"
docker run -it \
-v ${TESTNET_DEPLOYMENT_DIR}/data/laconicd-data:/root/testnet-deployment/.laconicd \
cerc/laconicd-testnet:local bash -c "laconicd export --home /root/testnet-deployment/.laconicd" \
| jq .app_state.onboarding > "$testnet_state_file"
echo "Exported state from testnet"
# --------
# Run a script with cerc/laconicd:local to generate the genesis file
# with onboarding module state and given allocations
docker run -it \
-v ./$MAINNET_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 ./$MAINNET_GENESIS_DIR/config/genesis.json $OUTPUT_DIR/genesis.json
echo "Genesis file for mainnet written to $OUTPUT_DIR/genesis.json"
# --------
# Clean up
echo "Please remove the temporary data directory: sudo rm -rf $MAINNET_GENESIS_DIR"

28
scripts/genesis.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/bash
# Exit on error
set -e
set -u
# Note: Needs to be run in a docker container with image cerc/laconicd:local
CHAINID=${CHAINID:-"laconic-mainnet"}
MONIKER=${MONIKER:-"mainnet-node"}
NODE_HOME="/root/.laconicd"
testnet_state_file="$NODE_HOME/testnet-state.json"
mainnet_genesis_file="$NODE_HOME/config/genesis.json"
laconicd config set client chain-id $CHAINID
laconicd init $MONIKER --chain-id $CHAINID --default-denom alnt
# Import required state
jq --slurpfile nested $testnet_state_file '.app_state.auth = $nested[0].app_state' "$mainnet_genesis_file" > tmp.$$.json && mv tmp.$$.json "$mainnet_genesis_file"
jq --slurpfile nested $testnet_state_file '.consensus.auth = $nested[0].consensus' "$mainnet_genesis_file" > tmp.$$.json && mv tmp.$$.json "$mainnet_genesis_file"
# Update any module params if required here
# TODO: Perform alps allocations
# Ensure that resulting genesis file is valid
laconicd genesis validate