Add scripts to generate a genesis file with allocations for enrolled participants (#2)
* Add script to generate validators using bridge node data * Modify script to convert bridge node output to json array * Add script to get address balance mapping from bridge node output * Modify script to generate cosmos address to balance map * Add scripts to generate genesis file with allocations * Take deployment dir and eth account holdings file as inputs * Add .gitignore --------- Co-authored-by: Shreerang Kale <shreerangkale@gmail.com>
This commit is contained in:
parent
9e9bd3019f
commit
06fedd6a03
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
stage0-spec.yml
|
||||||
|
stage0-deployment
|
||||||
|
stage1-spec.yml
|
||||||
|
stage1-deployment
|
||||||
|
|
||||||
|
stage1-genesis
|
||||||
|
output
|
@ -82,7 +82,7 @@ Instructions for running a laconicd fixturenet along with registry CLI and conso
|
|||||||
cp fixturenet-laconicd-deployment/deployment.yml laconic-console-deployment/deployment.yml
|
cp fixturenet-laconicd-deployment/deployment.yml laconic-console-deployment/deployment.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
* (Optional) Copy over the genesis file (`.json`) containing the onboarding module state with funded participants to data directory in deployment (`fixturenet-laconicd-deployment/data/genesis-config`):
|
* (Optional) Copy over an existing genesis file (`.json`) to data directory in deployment (`fixturenet-laconicd-deployment/data/genesis-config`):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Example
|
# Example
|
||||||
@ -97,6 +97,7 @@ Instructions for running a laconicd fixturenet along with registry CLI and conso
|
|||||||
# Optional
|
# Optional
|
||||||
|
|
||||||
# Set to true to enable adding participants functionality of the onboarding module
|
# Set to true to enable adding participants functionality of the onboarding module
|
||||||
|
# (default: false)
|
||||||
ONBOARDING_ENABLED=
|
ONBOARDING_ENABLED=
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Exit on error
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Note: Needs to be run in the go-nitro repository
|
||||||
|
# Example usage:
|
||||||
|
# In go-nitro
|
||||||
|
# /home/user/fixturenet-laconicd-stack/stack-orchestrator/stacks/fixturenet-laconicd/scripts/fetch-account-holdings.sh eth-account-holdings.json
|
||||||
|
|
||||||
|
# Check if output file is provided
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: $0 <output_file>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
OUTPUT_FILE=$1
|
||||||
|
|
||||||
|
# Run the nitro-rpc-client command and process the output with jq
|
||||||
|
npm exec -c "nitro-rpc-client get-all-ledger-channels -p 4006" | jq -s '[.[] | {ethereum_address: .Balance.Them, balance: .Balance.TheirBalance}]' > "$OUTPUT_FILE"
|
||||||
|
|
||||||
|
echo "Ethereum account holdings exported to $OUTPUT_FILE"
|
@ -0,0 +1,61 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Exit on error
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Prerequisite: a json file with ETH accounts holdings
|
||||||
|
|
||||||
|
# Check if output file is provided
|
||||||
|
if [ "$#" -ne 2 ]; then
|
||||||
|
echo "Usage: $0 <stage0-deployment-dir-absolute> <eth-account-holdings-json-file>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
STAGE0_DEPLOYMENT_DIR="$1"
|
||||||
|
ETH_ACCOUNT_HOLDINGS_FILE="$2"
|
||||||
|
|
||||||
|
STAGE1_GENESIS_DIR=stage1-genesis
|
||||||
|
|
||||||
|
# Create a 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/laconic2d:local bash -c "laconicd export --home /root/stage0-deployment/.laconicd" \
|
||||||
|
| jq .app_state.onboarding > "$onboarding_state_file"
|
||||||
|
|
||||||
|
eth_account_holdings=$(cat "$ETH_ACCOUNT_HOLDINGS_FILE")
|
||||||
|
stage0_participants=$(cat "$onboarding_state_file" | jq .participants)
|
||||||
|
|
||||||
|
# For each participant, using ETH account holdings, figure out balance allocation for stage1
|
||||||
|
# TODO Check what happens if participant is missing
|
||||||
|
stage1_allocations_file="$STAGE1_GENESIS_DIR/stage1-allocations.json"
|
||||||
|
jq -n --argjson holdings "$eth_account_holdings" --argjson participants "$stage0_participants" '
|
||||||
|
[
|
||||||
|
$holdings[] |
|
||||||
|
. as $holding |
|
||||||
|
$participants[] |
|
||||||
|
select((.ethereum_address | ascii_downcase) == ($holding.ethereum_address | ascii_downcase)) |
|
||||||
|
{
|
||||||
|
cosmos_address: .cosmos_address,
|
||||||
|
balance: $holding.balance
|
||||||
|
}
|
||||||
|
]' > $stage1_allocations_file
|
||||||
|
|
||||||
|
# Run a script with cerc/laconic2d: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/laconic2d: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"
|
32
stack-orchestrator/stacks/fixturenet-laconicd/scripts/genesis.sh
Executable file
32
stack-orchestrator/stacks/fixturenet-laconicd/scripts/genesis.sh
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Exit on error
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Note: Needs to be run in a docker container with image cerc/laconic2d:local
|
||||||
|
|
||||||
|
CHAINID="laconic_9000-1"
|
||||||
|
STAGE1_MONIKER=localtestnet-stage-1
|
||||||
|
NODE_HOME="/root/.laconicd"
|
||||||
|
|
||||||
|
onboarding_state_file="$NODE_HOME/stage0-onboarding-state.json"
|
||||||
|
stage1_allocations_file="$NODE_HOME/stage1-allocations.json"
|
||||||
|
stage1_genesis_file="$NODE_HOME/config/genesis.json"
|
||||||
|
|
||||||
|
laconicd init $STAGE1_MONIKER --chain-id $CHAINID --default-denom photon
|
||||||
|
|
||||||
|
# Update onboarding module state with participants from stage0
|
||||||
|
participants=$(jq -c '.participants' $onboarding_state_file)
|
||||||
|
jq --argjson p "$participants" '.app_state.onboarding.participants = $p' "$stage1_genesis_file" > tmp.$$.json && mv tmp.$$.json "$stage1_genesis_file"
|
||||||
|
|
||||||
|
# Read and assign allocations
|
||||||
|
jq -c '.[]' "$stage1_allocations_file" | while IFS= read -r line; do
|
||||||
|
cosmos_address=$(jq -r '.cosmos_address' <<< "$line")
|
||||||
|
balance=$(jq -r '.balance' <<< "$line")
|
||||||
|
|
||||||
|
# Add a genesis account for participant's laconic address with required balance
|
||||||
|
laconicd genesis add-genesis-account $cosmos_address ${balance}photon
|
||||||
|
done
|
||||||
|
|
||||||
|
# Ensure that resulting genesis file is valid
|
||||||
|
laconicd genesis validate
|
Loading…
Reference in New Issue
Block a user