diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/README.md b/stack-orchestrator/stacks/fixturenet-laconicd/README.md index 3018985..75100ad 100644 --- a/stack-orchestrator/stacks/fixturenet-laconicd/README.md +++ b/stack-orchestrator/stacks/fixturenet-laconicd/README.md @@ -105,13 +105,13 @@ Instructions for running a laconicd fixturenet along with registry CLI and conso # Enable authority auctions (default: false) 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 auctions reveals duration (in secs) (default: 24hrs) + # Authority auctions reveals duration (in secs) (default: 1hr) 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 # Node moniker (default: "localtestnet") diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh new file mode 100755 index 0000000..bb3078c --- /dev/null +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +# Exit on error +set -e +set -u + +CHAINID=${CHAINID:-"laconic-testnet-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 +} + +# Remove existing data but keep keys +laconicd cometbft unsafe-reset-all + +# Remove existing genesis file and gentxs +rm -r $NODE_HOME/config/gentx || true +rm $stage2_genesis_file || true + +# 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.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" + +# 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 diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh new file mode 100755 index 0000000..5acaf81 --- /dev/null +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Exit on error +set -e + +# Prerequisite: stage1 exported state present at $STAGE2_DEPLOYMENT/data/laconicd-data/stage1-state.json + +# Check args +if [ "$#" -lt 2 ]; then + echo "Usage: $0 [node-staking-amount]" + echo "Example: $0 /srv/stage2-deployment laconic-testnet-2 LaconicStage2 os 1000000000000000" + exit 1 +fi + +STAGE2_DEPLOYMENT=$1 +CHAINID=$2 +MONIKER=$3 +KEYRING=$4 +STAKING_AMOUNT=$5 + +# 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=$MONIKER KEYRING=$KEYRING STAKING_AMOUNT=$STAKING_AMOUNT /scripts/generate-stage2-genesis.sh"