From 125131d56d2c26facc07f59749a1bbe70a5ee2ed Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Thu, 17 Oct 2024 12:15:27 +0530 Subject: [PATCH 1/4] Add scripts to initialize stage2 testnet --- .../stacks/fixturenet-laconicd/README.md | 6 +- .../scripts/export-state.sh | 19 +++++ .../scripts/generate-stage2-genesis.sh | 77 +++++++++++++++++++ .../scripts/initialize-stage2.sh | 27 +++++++ 4 files changed, 126 insertions(+), 3 deletions(-) create mode 100755 stack-orchestrator/stacks/fixturenet-laconicd/scripts/export-state.sh create mode 100755 stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh create mode 100755 stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh 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/export-state.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/export-state.sh new file mode 100755 index 0000000..279d56d --- /dev/null +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/export-state.sh @@ -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 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..340d864 --- /dev/null +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh @@ -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 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..d4fadfd --- /dev/null +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Exit on error +set -e + +# Check args +if [ "$#" -lt 2 ]; then + echo "Usage: $0 [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" -- 2.45.2 From 8b53e8a6490218dfbd7d97972fa9bbef955f2a1e Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 18 Oct 2024 09:26:04 +0530 Subject: [PATCH 2/4] Use pre-existing exported stage1 state and skip auction module state --- .../scripts/export-state.sh | 19 ------------------- .../scripts/generate-stage2-genesis.sh | 8 +++++++- .../scripts/initialize-stage2.sh | 18 ++++++++---------- 3 files changed, 15 insertions(+), 30 deletions(-) delete mode 100755 stack-orchestrator/stacks/fixturenet-laconicd/scripts/export-state.sh diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/export-state.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/export-state.sh deleted file mode 100755 index 279d56d..0000000 --- a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/export-state.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/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 diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh index 340d864..e7b3aa2 100755 --- a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh @@ -45,13 +45,19 @@ remove_module_accounts () { 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.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" diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh index d4fadfd..401af73 100755 --- a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh @@ -3,25 +3,23 @@ # 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_9000-2 1000000000000000" + echo "Usage: $0 [node-staking-amount]" + echo "Example: $0 /srv/stage2-deployment laconic_9000-2 LaconicStage2 os 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" +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=LaconicStage2 STAKING_AMOUNT=$STAKING_AMOUNT /scripts/generate-stage2-genesis.sh" + cerc/laconicd:local bash -c "CHAINID=$CHAINID MONIKER=$MONIKER KEYRING=$KEYRING STAKING_AMOUNT=$STAKING_AMOUNT /scripts/generate-stage2-genesis.sh" -- 2.45.2 From 1820444954104b8c656e09369af140ff9481994b Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 21 Oct 2024 19:12:25 +0530 Subject: [PATCH 3/4] Update stage2 init script to disallow duplicate IP connections --- .../fixturenet-laconicd/scripts/generate-stage2-genesis.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh index e7b3aa2..43adcbd 100755 --- a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh @@ -69,9 +69,6 @@ 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 -- 2.45.2 From 40f6ce2a1465144eb605a958c3decd7760d50bda Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Tue, 22 Oct 2024 13:42:17 +0530 Subject: [PATCH 4/4] Update stage2 chain id --- .../fixturenet-laconicd/scripts/generate-stage2-genesis.sh | 2 +- .../stacks/fixturenet-laconicd/scripts/initialize-stage2.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh index 43adcbd..bb3078c 100755 --- a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage2-genesis.sh @@ -4,7 +4,7 @@ set -e set -u -CHAINID=${CHAINID:-"laconic_9000-2"} +CHAINID=${CHAINID:-"laconic-testnet-2"} STAGE2_MONIKER=${MONIKER:-"localtestnet-stage-2"} NODE_HOME="$HOME/.laconicd" diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh index 401af73..5acaf81 100755 --- a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/initialize-stage2.sh @@ -8,7 +8,7 @@ set -e # Check args if [ "$#" -lt 2 ]; then echo "Usage: $0 [node-staking-amount]" - echo "Example: $0 /srv/stage2-deployment laconic_9000-2 LaconicStage2 os 1000000000000000" + echo "Example: $0 /srv/stage2-deployment laconic-testnet-2 LaconicStage2 os 1000000000000000" exit 1 fi -- 2.45.2