Accept stage1 allocations file as input

This commit is contained in:
Prathamesh Musale 2024-08-19 12:48:15 +05:30
parent a1540bda67
commit 85c2079ca4
2 changed files with 9 additions and 23 deletions

View File

@ -5,15 +5,14 @@ set -e
set -u set -u
# Check args # Check args
if [ "$#" -ne 3 ]; then if [ "$#" -ne 2 ]; then
echo "Usage: $0 <stage1-participants-json> <participant-allocation> <validator-allocation>" echo "Usage: $0 <stage1-participants-json> <stage1-allocations-json>"
echo "Example: $0 ./stage-participants.json 1000000 1000000000000" echo "Example: $0 ./stage-participants.json ./stage1-allocations.json"
exit 1 exit 1
fi fi
STAGE1_PARTICIPANTS_FILE="$1" STAGE1_PARTICIPANTS_FILE="$1"
PARTICIPANT_ALLOCATION="$2" STAGE1_ALLOCATIONS_FILE="$2"
VALIDATOR_ALLOCATION="$3"
STAGE1_GENESIS_DIR=stage1-genesis STAGE1_GENESIS_DIR=stage1-genesis
# Create a temporary target directory # Create a temporary target directory
@ -23,24 +22,11 @@ mkdir -p $STAGE1_GENESIS_DIR
# Copy over the stage1-participants json file for genesis.sh to use # Copy over the stage1-participants json file for genesis.sh to use
cp $STAGE1_PARTICIPANTS_FILE "$STAGE1_GENESIS_DIR/stage1-participants.json" cp $STAGE1_PARTICIPANTS_FILE "$STAGE1_GENESIS_DIR/stage1-participants.json"
echo "Copied over stage1 participants json file to mount dir" 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"
# For each participant, allocate balance on stage1 according to role echo "Copied over stage1 allocations json file to mount dir"
stage1_participants=$(cat "$STAGE1_PARTICIPANTS_FILE")
stage1_allocations_file="$STAGE1_GENESIS_DIR/stage1-allocations.json"
jq -n --argjson participants "$stage1_participants" --arg participant_allocation "$PARTICIPANT_ALLOCATION" --arg validator_allocation "$VALIDATOR_ALLOCATION" '
[
$participants[] |
{
cosmos_address: .cosmos_address,
balance: (if .role == "validator" then $validator_allocation else $participant_allocation end)
}
]' > $stage1_allocations_file
echo "Calculated allocations for stage 1 chain"
# -------- # --------

View File

@ -17,8 +17,7 @@ stage1_genesis_file="$NODE_HOME/config/genesis.json"
laconicd init $STAGE1_MONIKER --chain-id $CHAINID --default-denom alnt laconicd init $STAGE1_MONIKER --chain-id $CHAINID --default-denom alnt
# Update onboarding module state with participants # Update onboarding module state with participants
participants=$(jq -c '.' $stage1_participants_file) jq --argfile p "$stage1_participants_file" '.app_state.onboarding.participants = $p' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file"
jq --argjson p "$participants" '.app_state.onboarding.participants = $p' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file"
# Disable bank module transfers # 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"
@ -31,6 +30,7 @@ jq '.app_state["slashing"]["params"]["signed_blocks_window"]="2400"' "$stage1_ge
jq '.app_state["slashing"]["params"]["min_signed_per_window"]="0.5"' "$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 # Read and assign allocations
echo "Adding genesis accounts with allocations..."
jq -c '.[]' "$stage1_allocations_file" | while IFS= read -r line; do jq -c '.[]' "$stage1_allocations_file" | while IFS= read -r line; do
cosmos_address=$(jq -r '.cosmos_address' <<< "$line") cosmos_address=$(jq -r '.cosmos_address' <<< "$line")
balance=$(jq -r '.balance' <<< "$line") balance=$(jq -r '.balance' <<< "$line")