Separate scripts for genesis generation using allocations or eth holdings
This commit is contained in:
parent
03ee080dfe
commit
201aa677c7
@ -0,0 +1,70 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Exit on error
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
# Check args
|
||||||
|
if [ "$#" -ne 3 ]; then
|
||||||
|
echo "Usage: $0 <stage0-deployment-dir-absolute> <participant-allocation> <validator-allocation>"
|
||||||
|
echo "Example: $0 /home/user/stage0-deployment 1000000 1000000000000"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
STAGE0_DEPLOYMENT_DIR="$1"
|
||||||
|
PARTICIPANT_ALLOCATION="$2"
|
||||||
|
VALIDATOR_ALLOCATION="$3"
|
||||||
|
STAGE1_GENESIS_DIR=stage1-genesis
|
||||||
|
|
||||||
|
# Create a temporary target directory
|
||||||
|
mkdir -p $STAGE1_GENESIS_DIR
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# Export onboarding module state from stage0 laconicd chain
|
||||||
|
|
||||||
|
onboarding_state_file="$STAGE1_GENESIS_DIR/stage0-onboarding-state.json"
|
||||||
|
docker run -it \
|
||||||
|
-v ${STAGE0_DEPLOYMENT_DIR}/data/laconicd-data:/root/stage0-deployment/.laconicd \
|
||||||
|
cerc/laconicd:local bash -c "laconicd export --home /root/stage0-deployment/.laconicd" \
|
||||||
|
| jq .app_state.onboarding > "$onboarding_state_file"
|
||||||
|
|
||||||
|
stage0_participants=$(cat "$onboarding_state_file" | jq .participants)
|
||||||
|
|
||||||
|
echo "Exported onboarding module state from stage 0 chain"
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# For each participant, using ETH account holdings, figure out balance allocation for stage1
|
||||||
|
stage1_allocations_file="$STAGE1_GENESIS_DIR/stage1-allocations.json"
|
||||||
|
jq -n --argjson participants "$stage0_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"
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# Run a script with cerc/laconicd:local to generate the genesis file
|
||||||
|
# with onboarding module state and given allocations
|
||||||
|
docker run -it \
|
||||||
|
-v ./stage1-genesis:/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 ./stage1-genesis/config/genesis.json $OUTPUT_DIR/genesis.json
|
||||||
|
|
||||||
|
echo "Genesis file for stage1 written to $OUTPUT_DIR/genesis.json"
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
echo "Please remove the temporary data directory: sudo rm -rf stage1-genesis"
|
@ -5,15 +5,13 @@ set -e
|
|||||||
set -u
|
set -u
|
||||||
|
|
||||||
# Check args
|
# Check args
|
||||||
if [ "$#" -ne 3 ]; then
|
if [ "$#" -ne 2 ]; then
|
||||||
echo "Usage: $0 <stage0-deployment-dir-absolute> <participant-allocation> <validator-allocation>"
|
echo "Usage: $0 <stage0-deployment-dir-absolute> <eth-account-holdings-json-file>"
|
||||||
echo "Example: $0 /home/user/stage0-deployment 1000000 1000000000000"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
STAGE0_DEPLOYMENT_DIR="$1"
|
STAGE0_DEPLOYMENT_DIR="$1"
|
||||||
PARTICIPANT_ALLOCATION="$2"
|
ETH_ACCOUNT_HOLDINGS_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
|
||||||
@ -21,6 +19,13 @@ mkdir -p $STAGE1_GENESIS_DIR
|
|||||||
|
|
||||||
# --------
|
# --------
|
||||||
|
|
||||||
|
# ETH account holdings fetched from the bridge node
|
||||||
|
eth_account_holdings=$(cat $ETH_ACCOUNT_HOLDINGS_FILE)
|
||||||
|
|
||||||
|
echo "Fetched Ethereum account holdings"
|
||||||
|
|
||||||
|
# --------
|
||||||
|
|
||||||
# Export onboarding module state from stage0 laconicd chain
|
# Export onboarding module state from stage0 laconicd chain
|
||||||
|
|
||||||
onboarding_state_file="$STAGE1_GENESIS_DIR/stage0-onboarding-state.json"
|
onboarding_state_file="$STAGE1_GENESIS_DIR/stage0-onboarding-state.json"
|
||||||
@ -37,12 +42,15 @@ echo "Exported onboarding module state from stage 0 chain"
|
|||||||
|
|
||||||
# For each participant, using ETH account holdings, figure out balance allocation for stage1
|
# For each participant, using ETH account holdings, figure out balance allocation for stage1
|
||||||
stage1_allocations_file="$STAGE1_GENESIS_DIR/stage1-allocations.json"
|
stage1_allocations_file="$STAGE1_GENESIS_DIR/stage1-allocations.json"
|
||||||
jq -n --argjson participants "$stage0_participants" --arg participant_allocation "$PARTICIPANT_ALLOCATION" --arg validator_allocation "$VALIDATOR_ALLOCATION" '
|
jq -n --argjson holdings "$eth_account_holdings" --argjson participants "$stage0_participants" '
|
||||||
[
|
[
|
||||||
|
$holdings[] |
|
||||||
|
. as $holding |
|
||||||
$participants[] |
|
$participants[] |
|
||||||
|
select((.nitro_address | ascii_downcase) == ($holding.nitro_address | ascii_downcase)) |
|
||||||
{
|
{
|
||||||
cosmos_address: .cosmos_address,
|
cosmos_address: .cosmos_address,
|
||||||
balance: (if .role == "validator" then $validator_allocation else $participant_allocation end)
|
balance: $holding.balance
|
||||||
}
|
}
|
||||||
]' > $stage1_allocations_file
|
]' > $stage1_allocations_file
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user