From f9a2eb2973118b85ba355f004cbabf295c129c64 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Tue, 25 Apr 2023 14:45:12 -0500 Subject: [PATCH 1/3] Add script for exporting ethdb from fixturenet. --- .../cerc-fixturenet-eth-geth/run-el.sh | 6 +++++ .../scripts/status.sh | 26 ++++++++++++++++--- app/data/stacks/fixturenet-eth-tx/README.md | 20 ++++++++++++++ app/data/stacks/fixturenet-eth-tx/stack.yml | 15 +++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 app/data/stacks/fixturenet-eth-tx/README.md create mode 100644 app/data/stacks/fixturenet-eth-tx/stack.yml diff --git a/app/data/container-build/cerc-fixturenet-eth-geth/run-el.sh b/app/data/container-build/cerc-fixturenet-eth-geth/run-el.sh index 526c76d7..edde1ba2 100755 --- a/app/data/container-build/cerc-fixturenet-eth-geth/run-el.sh +++ b/app/data/container-build/cerc-fixturenet-eth-geth/run-el.sh @@ -127,3 +127,9 @@ else fi wait $geth_pid + +if [ "true" == "$CERC_KEEP_RUNNING_AFTER_GETH_EXIT" ]; then + while [ 1 -eq 1 ]; do + sleep 60 + done +fi diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/scripts/status.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/scripts/status.sh index c6e65a68..f6d9d27b 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/scripts/status.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/scripts/status.sh @@ -2,9 +2,10 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi -STATUSES=("geth to generate DAG" "beacon phase0" "beacon altair" "beacon bellatrix pre-merge" "beacon bellatrix merge") -STATUS=0 +MIN_BLOCK_NUM=${1:-${MIN_BLOCK_NUM:-3}} +STATUSES=("geth to generate DAG" "beacon phase0" "beacon altair" "beacon bellatrix pre-merge" "beacon bellatrix merge" "block number $MIN_BLOCK_NUM") +STATUS=0 LIGHTHOUSE_BASE_URL=${LIGHTHOUSE_BASE_URL} GETH_BASE_URL=${GETH_BASE_URL} @@ -13,18 +14,29 @@ GETH_BASE_URL=${GETH_BASE_URL} # or some execution environment-neutral mechanism. if [ -z "$LIGHTHOUSE_BASE_URL" ]; then LIGHTHOUSE_CONTAINER=`docker ps -q -f "name=fixturenet-eth-lighthouse-1-1"` + if [ -z "$LIGHTHOUSE_CONTAINER" ]; then + echo "Lighthouse container not found." 1>&2 + exit 1 + fi LIGHTHOUSE_PORT=`docker port $LIGHTHOUSE_CONTAINER 8001 | cut -d':' -f2` LIGHTHOUSE_BASE_URL="http://localhost:${LIGHTHOUSE_PORT}" fi if [ -z "$GETH_BASE_URL" ]; then GETH_CONTAINER=`docker ps -q -f "name=fixturenet-eth-geth-1-1"` + if [ -z "$GETH_CONTAINER" ]; then + echo "Lighthouse container not found." 1>&2 + exit 1 + fi GETH_PORT=`docker port $GETH_CONTAINER 8545 | cut -d':' -f2` GETH_BASE_URL="http://localhost:${GETH_PORT}" fi +MARKER="." + function inc_status() { echo " done" + MARKEr="." STATUS=$((STATUS + 1)) if [ $STATUS -lt ${#STATUSES[@]} ]; then echo -n "Waiting for ${STATUSES[$STATUS]}..." @@ -34,7 +46,7 @@ function inc_status() { echo -n "Waiting for ${STATUSES[$STATUS]}..." while [ $STATUS -lt ${#STATUSES[@]} ]; do sleep 1 - echo -n "." + echo -n "$MARKER" case $STATUS in 0) result=`wget --no-check-certificate --quiet -O - --method POST --header 'Content-Type: application/json' \ @@ -67,5 +79,13 @@ while [ $STATUS -lt ${#STATUSES[@]} ]; do inc_status fi ;; + 5) + result=`wget --no-check-certificate --quiet -O - "$LIGHTHOUSE_BASE_URL/eth/v2/beacon/blocks/head" | jq -r '.data.message.body.execution_payload.block_number'` + if [ ! -z "$result" ] && [ $result -gt $MIN_BLOCK_NUM ]; then + inc_status + else + MARKER="$result " + fi + ;; esac done diff --git a/app/data/stacks/fixturenet-eth-tx/README.md b/app/data/stacks/fixturenet-eth-tx/README.md new file mode 100644 index 00000000..838ada53 --- /dev/null +++ b/app/data/stacks/fixturenet-eth-tx/README.md @@ -0,0 +1,20 @@ +# fixturenet-eth-tx + +A variation of `fixturenet-eth` that automatically generates transactions using `tx-spammer`. + +See `stacks/fixturenet-eth/README.md` for more information. + +## Containers + +* cerc/go-ethereum +* cerc/lighthouse +* cerc/fixturenet-eth-geth +* cerc/fixturenet-eth-lighthouse +* cerc/tx-spammer + +## Deploy the stack +``` +$ laconic-so --stack fixturenet-eth-tx setup-repositories +$ laconic-so --stack fixturenet-eth-tx build-containers +$ laconic-so --stack fixturenet-eth-tx deploy up +``` diff --git a/app/data/stacks/fixturenet-eth-tx/stack.yml b/app/data/stacks/fixturenet-eth-tx/stack.yml new file mode 100644 index 00000000..0c3b45a3 --- /dev/null +++ b/app/data/stacks/fixturenet-eth-tx/stack.yml @@ -0,0 +1,15 @@ +version: "1.1" +name: fixturenet-eth-tx +decription: "Ethereum Fixturenet w/ tx-spammer" +repos: + - cerc-io/go-ethereum + - cerc-io/tx-spammer +containers: + - cerc/go-ethereum + - cerc/lighthouse + - cerc/fixturenet-eth-geth + - cerc/fixturenet-eth-lighthouse + - cerc/tx-spammer +pods: + - fixturenet-eth + - tx-spammer -- 2.45.2 From 769383dc968a9a1794ae4af7481794e36663b1f7 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Tue, 25 Apr 2023 14:51:59 -0500 Subject: [PATCH 2/3] Update README --- app/data/stacks/fixturenet-eth-tx/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/data/stacks/fixturenet-eth-tx/README.md b/app/data/stacks/fixturenet-eth-tx/README.md index 838ada53..9af9ee3d 100644 --- a/app/data/stacks/fixturenet-eth-tx/README.md +++ b/app/data/stacks/fixturenet-eth-tx/README.md @@ -18,3 +18,20 @@ $ laconic-so --stack fixturenet-eth-tx setup-repositories $ laconic-so --stack fixturenet-eth-tx build-containers $ laconic-so --stack fixturenet-eth-tx deploy up ``` + +## Export the ethdb (optional) + +It is easy to export data from the fixturenet for offline processing of the raw ethdb files (eg, by eth-statediff-service) using the `export-ethdb.sh` script. + +For example: + +``` +❯ app/data/container-build/cerc-fixturenet-eth-lighthouse/scripts/export-ethdb.sh 500 +Waiting for geth to generate DAG.... done +Waiting for beacon phase0.... done +Waiting for beacon altair.... done +Waiting for beacon bellatrix pre-merge.... done +Waiting for beacon bellatrix merge.... done +Waiting for block number 500.... done +Exporting ethdb.... ./ethdb.tgz +``` -- 2.45.2 From 175ba3becaad95e272fc54293b8d3f69a636c543 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Tue, 25 Apr 2023 15:12:22 -0500 Subject: [PATCH 3/3] Script --- .../compose/docker-compose-fixturenet-eth.yml | 2 + .../scripts/export-ethdb.sh | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 app/data/container-build/cerc-fixturenet-eth-lighthouse/scripts/export-ethdb.sh diff --git a/app/data/compose/docker-compose-fixturenet-eth.yml b/app/data/compose/docker-compose-fixturenet-eth.yml index c687b326..59f729b9 100644 --- a/app/data/compose/docker-compose-fixturenet-eth.yml +++ b/app/data/compose/docker-compose-fixturenet-eth.yml @@ -49,6 +49,8 @@ services: timeout: 10s retries: 10 start_period: 3s + environment: + CERC_KEEP_RUNNING_AFTER_GETH_EXIT: "true" env_file: - ../config/fixturenet-eth/fixturenet-eth.env image: cerc/fixturenet-eth-geth:local diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/scripts/export-ethdb.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/scripts/export-ethdb.sh new file mode 100755 index 00000000..77198c61 --- /dev/null +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/scripts/export-ethdb.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +MY_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +GETH_EXPORT_MIN_BLOCK=${1:-${GETH_EXPORT_MIN_BLOCK:-1000}} + +# Wait for block. +${MY_DIR}/status.sh $GETH_EXPORT_MIN_BLOCK +if [ $? -ne 0 ]; then + echo "Unable to export ethdb." 1>&2 + exit 1 +fi + +# Stop geth. +echo -n "Exporting ethdb.... " +GETH_CONTAINER=`docker ps -q -f "name=${CERC_SO_COMPOSE_PROJECT}-fixturenet-eth-geth-2-1"` +if [ -z "$GETH_CONTAINER" ]; then + echo "not found" + exit 1 +fi + +docker exec $GETH_CONTAINER sh -c 'rm -rf /root/tmp && mkdir -p /root/tmp/export' +docker exec $GETH_CONTAINER sh -c 'ln -s /opt/testnet/build/el/geth.json /root/tmp/export/genesis.json && ln -s /root/ethdata /root/tmp/export/' +docker exec $GETH_CONTAINER sh -c 'cat /root/tmp/export/genesis.json | jq ".config" > /root/tmp/export/genesis.config.json' + +# Stop geth and zip up ethdb. +docker exec $GETH_CONTAINER sh -c 'curl -s --location "localhost:8545" --header "Content-Type: application/json" --data "{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"eth_getBlockByNumber\", \"params\": [\"0x0\", false]}" > /root/tmp/export/eth_getBlockByNumber_0x0.json' +docker exec $GETH_CONTAINER sh -c 'curl -s --location "localhost:8545" --header "Content-Type: application/json" --data "{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"eth_blockNumber\", \"params\": []}" > /root/tmp/export/eth_blockNumber.json' +docker exec $GETH_CONTAINER sh -c "killall geth && sleep 2 && tar chzf /root/tmp/ethdb.tgz -C /root/tmp/export ." + +# Copy ethdb to host. +GETH_EXPORT_FILE=${2:-${GETH_EXPORT_FILE:-./ethdb.tgz}} +docker cp $GETH_CONTAINER:/root/tmp/ethdb.tgz $GETH_EXPORT_FILE +echo "$GETH_EXPORT_FILE" +docker exec $GETH_CONTAINER sh -c "rm -rf /root/tmp" + +# Restart the container to get geth back up and running. +docker restart $GETH_CONTAINER >/dev/null -- 2.45.2