Add scripts for onboarding testnet participants from stage 0 to 1 laconicd chain #2

Merged
nabarun merged 4 commits from testnet-onboarding into main 2024-07-16 09:08:10 +00:00
3 changed files with 34 additions and 36 deletions
Showing only changes of commit 5e91f5e40f - Show all commits

View File

@ -1,25 +0,0 @@
#!/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
# Trust locally-trusted development certificates created by mkcert
export NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem"
# 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"

View File

@ -3,47 +3,67 @@
# Exit on error
set -e
# Prerequisite: a json file with ETH accounts holdings
# Prerequisite: nitro-rpc-client package installed globally
# https://github.com/cerc-io/go-nitro/blob/main/packages/nitro-rpc-client/readme.md
# Check if output file is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <stage0-deployment-dir-absolute> <eth-account-holdings-json-file>"
# Check args
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <stage0-deployment-dir-absolute>"
exit 1
fi
STAGE0_DEPLOYMENT_DIR="$1"
ETH_ACCOUNT_HOLDINGS_FILE="$2"
STAGE1_GENESIS_DIR=stage1-genesis
# Create a target directory
# Create a temporary target directory
mkdir -p $STAGE1_GENESIS_DIR
# --------
# Fetch ETH account holdings from the bridge node
# Trust locally-trusted development certificates created by mkcert
export NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem"
# Run the nitro-rpc-client command and process the output with jq
eth_account_holdings=$(nitro-rpc-client get-all-ledger-channels -p 4006 | jq -s '[.[] | {nitro_address: .Balance.Them, balance: .Balance.TheirBalance}]')
echo "Fetched Ethereum account holdings"
# --------
# 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)
echo "Exported onboarding module state from stage 0 chain"
# --------
# 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)) |
select((.nitro_address | ascii_downcase) == ($holding.nitro_address | ascii_downcase)) |
{
cosmos_address: .cosmos_address,
balance: $holding.balance
}
]' > $stage1_allocations_file
echo "Calculated allocations for stage 1 chain"
# --------
# Run a script with cerc/laconic2d:local to generate the genesis file
# with onboarding module state and given allocations
docker run -it \
@ -55,7 +75,10 @@ docker run -it \
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"

View File

@ -2,7 +2,7 @@ version: "1.0"
name: fixturenet-laconicd
description: "A laconicd fixturenet"
repos:
- github.com/deep-stack/laconic2d@testnet-onboarding
- git.vdb.to/cerc-io/laconic2d
containers:
- cerc/laconic2d
pods: