From 5e91f5e40f786a55e4dae4320c2f61231c0bc15e Mon Sep 17 00:00:00 2001 From: neerajvijay1997 <111040298+neerajvijay1997@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:02:45 +0530 Subject: [PATCH] Use nitro rpc client binary in genesis generation script (#4) * Update script to use nitro rpc client binary * Integrate fetching ETH account holdings in the genesis generation script * Update laconic2d repo source * Change ethereum_address to nitro_address in genesis generation script --------- Co-authored-by: Prathamesh Musale --- .../scripts/fetch-account-holdings.sh | 25 ----------- .../scripts/generate-stage1-genesis.sh | 43 ++++++++++++++----- .../stacks/fixturenet-laconicd/stack.yml | 2 +- 3 files changed, 34 insertions(+), 36 deletions(-) delete mode 100755 stack-orchestrator/stacks/fixturenet-laconicd/scripts/fetch-account-holdings.sh diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/fetch-account-holdings.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/fetch-account-holdings.sh deleted file mode 100755 index f3d2596..0000000 --- a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/fetch-account-holdings.sh +++ /dev/null @@ -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 " - 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" diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis.sh b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis.sh index 15f3fc2..5e220d7 100755 --- a/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis.sh +++ b/stack-orchestrator/stacks/fixturenet-laconicd/scripts/generate-stage1-genesis.sh @@ -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 " +# Check args +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " 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" diff --git a/stack-orchestrator/stacks/fixturenet-laconicd/stack.yml b/stack-orchestrator/stacks/fixturenet-laconicd/stack.yml index 59610af..85c2ba1 100644 --- a/stack-orchestrator/stacks/fixturenet-laconicd/stack.yml +++ b/stack-orchestrator/stacks/fixturenet-laconicd/stack.yml @@ -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: