Add scripts to initialize stage2 testnet #16

Merged
nabarun merged 4 commits from pm-stage2-scripts into main 2024-10-24 07:23:33 +00:00
4 changed files with 126 additions and 3 deletions
Showing only changes of commit 125131d56d - Show all commits

View File

@ -105,13 +105,13 @@ Instructions for running a laconicd fixturenet along with registry CLI and conso
# Enable authority auctions (default: false) # Enable authority auctions (default: false)
AUTHORITY_AUCTION_ENABLED=true AUTHORITY_AUCTION_ENABLED=true
# Authority auctions commits duration (in secs) (default: 24hrs) # Authority auctions commits duration (in secs) (default: 1hr)
AUTHORITY_AUCTION_COMMITS_DURATION=3600 AUTHORITY_AUCTION_COMMITS_DURATION=3600
# Authority auctions reveals duration (in secs) (default: 24hrs) # Authority auctions reveals duration (in secs) (default: 1hr)
AUTHORITY_AUCTION_REVEALS_DURATION=3600 AUTHORITY_AUCTION_REVEALS_DURATION=3600
# Authority grace period (set bond to authority within this) (in secs) (default: 2 * 24hrs) # Authority grace period (set bond to authority within this) (in secs) (default: 2 * 1hr)
AUTHORITY_GRACE_PERIOD=7200 AUTHORITY_GRACE_PERIOD=7200
# Node moniker (default: "localtestnet") # Node moniker (default: "localtestnet")

View File

@ -0,0 +1,19 @@
#!/bin/bash
# Exit on error
set -e
set -u
# Run in docker container with mounted stage1 data
NODE_HOME="$HOME/.laconicd"
stage1_state="$NODE_HOME/stage1-state.json"
# Export state
laconicd export | jq > $stage1_state
# Remove data but keep keys
laconicd cometbft unsafe-reset-all
rm -r $NODE_HOME/config/gentx
rm $NODE_HOME/config/genesis.json

View File

@ -0,0 +1,77 @@
#!/bin/bash
# Exit on error
set -e
set -u
CHAINID=${CHAINID:-"laconic_9000-2"}
STAGE2_MONIKER=${MONIKER:-"localtestnet-stage-2"}
NODE_HOME="$HOME/.laconicd"
# Existing key
KEY="alice"
KEYRING=${KEYRING:-"test"}
DENOM=${DENOM:-"alnt"}
STAKING_AMOUNT=${STAKING_AMOUNT:-"1000000000000000"}
stage1_state="$NODE_HOME/stage1-state.json"
stage2_genesis_file="$NODE_HOME/config/genesis.json"
remove_module_accounts () {
bonded_tokens_pool_address=$(jq -r '.app_state.auth.accounts[] | select(.name == "bonded_tokens_pool") | .base_account.address' $stage2_genesis_file)
bonded_tokens_pool_balance=$(jq -r --arg ADDRESS "$bonded_tokens_pool_address" '( .app_state.bank.balances[]? | select(.address == $ADDRESS) | .coins[]? | select(.denom == "alnt") | .amount ) // "0"' $stage2_genesis_file)
not_bonded_tokens_pool_address=$(jq -r '.app_state.auth.accounts[] | select(.name == "not_bonded_tokens_pool") | .base_account.address' $stage2_genesis_file)
not_bonded_tokens_pool_balance=$(jq -r --arg ADDRESS "$not_bonded_tokens_pool_address" '( .app_state.bank.balances[]? | select(.address == $ADDRESS) | .coins[]? | select(.denom == "alnt") | .amount ) // "0"' $stage2_genesis_file)
distribution_address=$(jq -r '.app_state.auth.accounts[] | select(.name == "distribution") | .base_account.address' $stage2_genesis_file)
distribution_balance=$(jq -r --arg ADDRESS "$distribution_address" '( .app_state.bank.balances[]? | select(.address == $ADDRESS) | .coins[]? | select(.denom == "alnt") | .amount ) // "0"' $stage2_genesis_file)
# Remove the entry from auth.accounts
jq "del(.app_state.auth.accounts[] | select(.base_account.address == \"$bonded_tokens_pool_address\"))" $stage2_genesis_file > tmp.$$.json && mv tmp.$$.json $stage2_genesis_file
jq "del(.app_state.auth.accounts[] | select(.base_account.address == \"$not_bonded_tokens_pool_address\"))" $stage2_genesis_file > tmp.$$.json && mv tmp.$$.json $stage2_genesis_file
jq "del(.app_state.auth.accounts[] | select(.base_account.address == \"$distribution_address\"))" $stage2_genesis_file > tmp.$$.json && mv tmp.$$.json $stage2_genesis_file
# Remove the entry from bank.balances
jq "del(.app_state.bank.balances[] | select(.address == \"$bonded_tokens_pool_address\"))" $stage2_genesis_file > tmp.$$.json && mv tmp.$$.json $stage2_genesis_file
jq "del(.app_state.bank.balances[] | select(.address == \"$not_bonded_tokens_pool_address\"))" $stage2_genesis_file > tmp.$$.json && mv tmp.$$.json $stage2_genesis_file
jq "del(.app_state.bank.balances[] | select(.address == \"$distribution_address\"))" $stage2_genesis_file > tmp.$$.json && mv tmp.$$.json $stage2_genesis_file
# Subtract the balance from bank supply
bank_supply=$(jq -r '(.app_state.bank.supply[] | select(.denom == "alnt") | .amount)' $stage2_genesis_file)
new_supply=$(echo "$bank_supply - $bonded_tokens_pool_balance - $not_bonded_tokens_pool_balance - $distribution_balance" | bc)
# Update genesis file with the new amount
jq --arg NEW_SUPPLY "$new_supply" '(.app_state.bank.supply[] | select(.denom == "alnt") | .amount) |= $NEW_SUPPLY' $stage2_genesis_file > tmp.$$.json && mv tmp.$$.json $stage2_genesis_file
}
# Initialize node with given chain id and moniker
laconicd config set client chain-id $CHAINID
laconicd init $STAGE2_MONIKER --chain-id $CHAINID --default-denom alnt
# Import required module state
jq --slurpfile nested $stage1_state '.app_state.auth = $nested[0].app_state.auth' "$stage2_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage2_genesis_file"
jq --slurpfile nested $stage1_state '.app_state.auction = $nested[0].app_state.auction' "$stage2_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage2_genesis_file"
jq --slurpfile nested $stage1_state '.app_state.bank = $nested[0].app_state.bank' "$stage2_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage2_genesis_file"
jq --slurpfile nested $stage1_state '.app_state.bond = $nested[0].app_state.bond' "$stage2_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage2_genesis_file"
jq --slurpfile nested $stage1_state '.app_state.onboarding = $nested[0].app_state.onboarding' "$stage2_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage2_genesis_file"
jq --slurpfile nested $stage1_state '.app_state.registry = $nested[0].app_state.registry' "$stage2_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage2_genesis_file"
# Remove bonded_tokens_pool, not_bonded_tokens_pool distribution module accounts as we're skipping their state
remove_module_accounts
# Set all account sequences to 0
jq '(.app_state.auth.accounts[] | select(has("sequence")) | .sequence) = "0"' "$stage2_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage2_genesis_file"
# Allow multiple node connections from same IP
sed -i 's/allow_duplicate_ip.*$/allow_duplicate_ip = true/' $HOME/.laconicd/config/config.toml
# Sign genesis transaction
# 10^15 alnt
laconicd genesis gentx $KEY $STAKING_AMOUNT$DENOM --keyring-backend $KEYRING --chain-id $CHAINID
# Collect genesis txs
laconicd genesis collect-gentxs
# Run this to ensure everything worked and that the genesis file is setup correctly
laconicd genesis validate

View File

@ -0,0 +1,27 @@
#!/bin/bash
# Exit on error
set -e
# Check args
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <stage2-deployment-dir> <stage2-chain-id> [node-staking-amount]"
echo "Example: $0 /srv/stage2-deployment laconic_9000-2 1000000000000000"
exit 1
fi
STAGE2_DEPLOYMENT=$1
CHAINID=$2
STAKING_AMOUNT=$3
# Export state from current data
docker run -it \
-v $STAGE2_DEPLOYMENT/data/laconicd-data:/root/.laconicd \
-v ./scripts:/scripts \
cerc/laconicd-stage1:local bash -c "/scripts/export-state.sh"
# Generate genesis file for state2 chain and init node
docker run -it \
-v $STAGE2_DEPLOYMENT/data/laconicd-data:/root/.laconicd \
-v ./scripts:/scripts \
cerc/laconicd:local bash -c "CHAINID=$CHAINID MONIKER=LaconicStage2 STAKING_AMOUNT=$STAKING_AMOUNT /scripts/generate-stage2-genesis.sh"