From 76bf5a3c5d5063137010860711e1796da516efa3 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Thu, 13 Apr 2023 18:09:37 +0530 Subject: [PATCH 1/9] Use mounted volumes for data in geth nodes --- app/data/compose/docker-compose-fixturenet-eth.yml | 8 ++++++++ .../container-build/cerc-fixturenet-eth-geth/Dockerfile | 2 +- .../genesis/accounts/import_keys.sh | 2 +- .../container-build/cerc-fixturenet-eth-geth/run-el.sh | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/data/compose/docker-compose-fixturenet-eth.yml b/app/data/compose/docker-compose-fixturenet-eth.yml index 508543e4..238ca38e 100644 --- a/app/data/compose/docker-compose-fixturenet-eth.yml +++ b/app/data/compose/docker-compose-fixturenet-eth.yml @@ -8,6 +8,8 @@ services: environment: RUN_BOOTNODE: "true" image: cerc/fixturenet-eth-geth:local + volumes: + - bootnode_geth_data:/root/ethdata ports: - "9898" - "30303" @@ -26,6 +28,7 @@ services: image: cerc/fixturenet-eth-geth:local volumes: - fixturenet_geth_accounts:/opt/testnet/build/el + - fixturenet_eth_geth_1_data:/root/ethdata healthcheck: test: ["CMD", "nc", "-v", "localhost", "8545"] interval: 30s @@ -52,6 +55,8 @@ services: image: cerc/fixturenet-eth-geth:local depends_on: - fixturenet-eth-bootnode-geth + volumes: + - fixturenet_eth_geth_2_data:/root/ethdata fixturenet-eth-bootnode-lighthouse: hostname: fixturenet-eth-bootnode-lighthouse @@ -106,3 +111,6 @@ services: volumes: fixturenet_geth_accounts: + bootnode_geth_data: + fixturenet_eth_geth_1_data: + fixturenet_eth_geth_2_data: diff --git a/app/data/container-build/cerc-fixturenet-eth-geth/Dockerfile b/app/data/container-build/cerc-fixturenet-eth-geth/Dockerfile index 51dbbcd4..63c3c0a7 100644 --- a/app/data/container-build/cerc-fixturenet-eth-geth/Dockerfile +++ b/app/data/container-build/cerc-fixturenet-eth-geth/Dockerfile @@ -22,6 +22,6 @@ COPY run-el.sh /opt/testnet/run.sh RUN cd /opt/testnet && make genesis-el COPY --from=geth /usr/local/bin/geth /usr/local/bin/ -RUN geth init /opt/testnet/build/el/geth.json && rm -f ~/.ethereum/geth/nodekey +RUN geth --datadir ~/ethdata init /opt/testnet/build/el/geth.json && rm -f ~/ethdata/geth/nodekey ENTRYPOINT ["/opt/testnet/run.sh"] diff --git a/app/data/container-build/cerc-fixturenet-eth-geth/genesis/accounts/import_keys.sh b/app/data/container-build/cerc-fixturenet-eth-geth/genesis/accounts/import_keys.sh index 719b9f59..e8dce0ea 100755 --- a/app/data/container-build/cerc-fixturenet-eth-geth/genesis/accounts/import_keys.sh +++ b/app/data/container-build/cerc-fixturenet-eth-geth/genesis/accounts/import_keys.sh @@ -12,6 +12,6 @@ for line in `cat ../build/el/accounts.csv`; do echo "" echo "$ADDRESS" - geth account import --password .pw.$$ .key.$$ + geth account import --datadir=~/ethdata --password .pw.$$ .key.$$ rm -f .pw.$$ .key.$$ done 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 12e59462..eca702e4 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 @@ -13,7 +13,7 @@ cd /opt/testnet/build/el python3 -m http.server 9898 & cd $HOME_DIR -START_CMD="geth" +START_CMD="geth --datadir=~/ethdata" if [ "true" == "$CERC_REMOTE_DEBUG" ] && [ -x "/usr/local/bin/dlv" ]; then START_CMD="/usr/local/bin/dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /usr/local/bin/geth --continue --" fi @@ -28,7 +28,7 @@ if [ "true" == "$RUN_BOOTNODE" ]; then else cd /opt/testnet/accounts ./import_keys.sh - + echo -n "$JWT" > /opt/testnet/build/el/jwtsecret if [ "$CERC_RUN_STATEDIFF" == "detect" ] && [ -n "$CERC_STATEDIFF_DB_HOST" ]; then -- 2.45.2 From 71cce4233ce596bd5b96ef998eeab93b40e6ef0b Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Fri, 14 Apr 2023 13:06:54 +0530 Subject: [PATCH 2/9] Use mounted volumes for data in lighthouse nodes --- .../compose/docker-compose-fixturenet-eth.yml | 9 +++++++++ .../genesis/cl/bootnode.sh | 17 ++++++++++++----- .../cerc-fixturenet-eth-lighthouse/run-cl.sh | 3 ++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/data/compose/docker-compose-fixturenet-eth.yml b/app/data/compose/docker-compose-fixturenet-eth.yml index 238ca38e..940c1a8e 100644 --- a/app/data/compose/docker-compose-fixturenet-eth.yml +++ b/app/data/compose/docker-compose-fixturenet-eth.yml @@ -63,6 +63,8 @@ services: environment: RUN_BOOTNODE: "true" image: cerc/fixturenet-eth-lighthouse:local + volumes: + - fixturenet_eth_bootnode_data:/opt/testnet/build/cl/bootnode fixturenet-eth-lighthouse-1: hostname: fixturenet-eth-lighthouse-1 @@ -79,6 +81,8 @@ services: ETH1_ENDPOINT: "http://fixturenet-eth-geth-1:8545" EXECUTION_ENDPOINT: "http://fixturenet-eth-geth-1:8551" image: cerc/fixturenet-eth-lighthouse:local + volumes: + - fixturenet_eth_lighthouse_1_data:/opt/testnet/build/cl/node_1 depends_on: fixturenet-eth-bootnode-lighthouse: condition: service_started @@ -103,6 +107,8 @@ services: EXECUTION_ENDPOINT: "http://fixturenet-eth-geth-2:8551" LIGHTHOUSE_GENESIS_STATE_URL: "http://fixturenet-eth-lighthouse-1:8001/eth/v2/debug/beacon/states/0" image: cerc/fixturenet-eth-lighthouse:local + volumes: + - fixturenet_eth_lighthouse_2_data:/opt/testnet/build/cl/node_2 depends_on: fixturenet-eth-bootnode-lighthouse: condition: service_started @@ -114,3 +120,6 @@ volumes: bootnode_geth_data: fixturenet_eth_geth_1_data: fixturenet_eth_geth_2_data: + fixturenet_eth_bootnode_data: + fixturenet_eth_lighthouse_1_data: + fixturenet_eth_lighthouse_2_data: diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh index f6f5cc73..e6970650 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh @@ -21,14 +21,21 @@ if [ ! -f "$DATADIR/bootnode/enr.dat" ]; then --udp-port $BOOTNODE_PORT \ --tcp-port $BOOTNODE_PORT \ --genesis-fork-version $GENESIS_FORK_VERSION \ - --output-dir $DATADIR/bootnode + --output-dir $DATADIR/bootnode-temp - bootnode_enr=`cat $DATADIR/bootnode/enr.dat` - echo "- $bootnode_enr" > $TESTNET_DIR/boot_enr.yaml - - echo "Generated bootnode enr and written to $TESTNET_DIR/boot_enr.yaml" + # Output ENR to a temp dir and mv as "lcli generate-bootnode-enr" will not overwrite an empty dir (mounted volume) + mv $DATADIR/bootnode-temp/* $DATADIR/bootnode + rm -r $DATADIR/bootnode-temp + + echo "Generated bootnode enr" +else + echo "Found existing bootnode enr" fi +bootnode_enr=`cat $DATADIR/bootnode/enr.dat` +echo "- $bootnode_enr" > $TESTNET_DIR/boot_enr.yaml +echo "Written bootnode enr to $TESTNET_DIR/boot_enr.yaml" + exec lighthouse boot_node \ --testnet-dir $TESTNET_DIR \ --port $BOOTNODE_PORT \ diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh index ee5fc55c..25b2268c 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ "true" == "$RUN_BOOTNODE" ]; then +if [ "true" == "$RUN_BOOTNODE" ]; then cd /opt/testnet/build/cl python3 -m http.server 3000 & @@ -25,6 +25,7 @@ else cd /opt/testnet/cl if [ -z "$LIGHTHOUSE_GENESIS_STATE_URL" ]; then + # TODO Avoid on a restart ./reset_genesis_time.sh else while [ 1 -eq 1 ]; do -- 2.45.2 From 612b6be676053b83345e840ff753b81176469a7c Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Fri, 14 Apr 2023 15:04:51 +0530 Subject: [PATCH 3/9] Avoid resetting genesis time in a lighthouse node on restart --- .../cerc-fixturenet-eth-lighthouse/run-cl.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh index 25b2268c..13e137fb 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh @@ -25,8 +25,12 @@ else cd /opt/testnet/cl if [ -z "$LIGHTHOUSE_GENESIS_STATE_URL" ]; then - # TODO Avoid on a restart - ./reset_genesis_time.sh + # Check if beacon node data exists to avoid resetting genesis time on a restart + if [ -d /opt/testnet/build/cl/node_"$NODE_NUMBER"/beacon ]; then + echo "Skipping genesis time reset" + else + ./reset_genesis_time.sh + fi else while [ 1 -eq 1 ]; do echo "Waiting on Genesis time ..." -- 2.45.2 From 384ca94fd6727068073528a72c70c39c8799e4ca Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Fri, 14 Apr 2023 19:19:20 +0530 Subject: [PATCH 4/9] Mount parent datadir for lighthouse nodes --- app/data/compose/docker-compose-fixturenet-eth.yml | 12 ++++++------ .../genesis/cl/bootnode.sh | 1 + .../genesis/cl/reset_genesis_time.sh | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/data/compose/docker-compose-fixturenet-eth.yml b/app/data/compose/docker-compose-fixturenet-eth.yml index 940c1a8e..2024cacb 100644 --- a/app/data/compose/docker-compose-fixturenet-eth.yml +++ b/app/data/compose/docker-compose-fixturenet-eth.yml @@ -9,7 +9,7 @@ services: RUN_BOOTNODE: "true" image: cerc/fixturenet-eth-geth:local volumes: - - bootnode_geth_data:/root/ethdata + - fixturenet_eth_bootnode_geth_data:/root/ethdata ports: - "9898" - "30303" @@ -64,7 +64,7 @@ services: RUN_BOOTNODE: "true" image: cerc/fixturenet-eth-lighthouse:local volumes: - - fixturenet_eth_bootnode_data:/opt/testnet/build/cl/bootnode + - fixturenet_eth_bootnode_lighthouse_data:/opt/testnet/build/cl fixturenet-eth-lighthouse-1: hostname: fixturenet-eth-lighthouse-1 @@ -82,7 +82,7 @@ services: EXECUTION_ENDPOINT: "http://fixturenet-eth-geth-1:8551" image: cerc/fixturenet-eth-lighthouse:local volumes: - - fixturenet_eth_lighthouse_1_data:/opt/testnet/build/cl/node_1 + - fixturenet_eth_lighthouse_1_data:/opt/testnet/build/cl depends_on: fixturenet-eth-bootnode-lighthouse: condition: service_started @@ -108,7 +108,7 @@ services: LIGHTHOUSE_GENESIS_STATE_URL: "http://fixturenet-eth-lighthouse-1:8001/eth/v2/debug/beacon/states/0" image: cerc/fixturenet-eth-lighthouse:local volumes: - - fixturenet_eth_lighthouse_2_data:/opt/testnet/build/cl/node_2 + - fixturenet_eth_lighthouse_2_data:/opt/testnet/build/cl depends_on: fixturenet-eth-bootnode-lighthouse: condition: service_started @@ -117,9 +117,9 @@ services: volumes: fixturenet_geth_accounts: - bootnode_geth_data: + fixturenet_eth_bootnode_geth_data: fixturenet_eth_geth_1_data: fixturenet_eth_geth_2_data: - fixturenet_eth_bootnode_data: + fixturenet_eth_bootnode_lighthouse_data: fixturenet_eth_lighthouse_1_data: fixturenet_eth_lighthouse_2_data: diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh index e6970650..7563371c 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh @@ -24,6 +24,7 @@ if [ ! -f "$DATADIR/bootnode/enr.dat" ]; then --output-dir $DATADIR/bootnode-temp # Output ENR to a temp dir and mv as "lcli generate-bootnode-enr" will not overwrite an empty dir (mounted volume) + mkdir -p $DATADIR/bootnode mv $DATADIR/bootnode-temp/* $DATADIR/bootnode rm -r $DATADIR/bootnode-temp diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/reset_genesis_time.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/reset_genesis_time.sh index a8cc2e2b..f21a8ee0 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/reset_genesis_time.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/reset_genesis_time.sh @@ -16,4 +16,4 @@ lcli \ $TESTNET_DIR/genesis.ssz \ $NOW -echo "Reset genesis time to now ($NOW)" +echo "Reset genesis time to ($NOW)" -- 2.45.2 From 6e93ab4eb029ecfd395ff1ccc5a3c4e29a960b0b Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Tue, 18 Apr 2023 12:23:06 +0530 Subject: [PATCH 5/9] Trap signals on shutdown and clean up in lighthouse nodes --- .../cerc-fixturenet-eth-geth/run-el.sh | 4 +++- .../genesis/cl/beacon_node.sh | 2 +- .../genesis/cl/validator_client.sh | 2 +- .../cerc-fixturenet-eth-lighthouse/run-cl.sh | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) 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 eca702e4..aed555ef 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 @@ -13,13 +13,14 @@ cd /opt/testnet/build/el python3 -m http.server 9898 & cd $HOME_DIR -START_CMD="geth --datadir=~/ethdata" +START_CMD="geth" if [ "true" == "$CERC_REMOTE_DEBUG" ] && [ -x "/usr/local/bin/dlv" ]; then START_CMD="/usr/local/bin/dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /usr/local/bin/geth --continue --" fi if [ "true" == "$RUN_BOOTNODE" ]; then $START_CMD \ + --datadir=~/ethdata \ --nodekeyhex="${BOOTNODE_KEY}" \ --nodiscover \ --ipcdisable \ @@ -74,6 +75,7 @@ else fi $START_CMD \ + --datadir=~/ethdata \ --bootnodes="${ENODE}" \ --allow-insecure-unlock \ --http \ diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh index 6fa1d8d4..93207d27 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh @@ -19,9 +19,9 @@ http_port=8001 authrpc_port=8551 exec lighthouse \ - --debug-level $DEBUG_LEVEL \ bn \ $SUBSCRIBE_ALL_SUBNETS \ + --debug-level $DEBUG_LEVEL \ --boot-nodes "$ENR" \ --datadir $data_dir \ --testnet-dir $TESTNET_DIR \ diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/validator_client.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/validator_client.sh index c7f0dba4..30168f80 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/validator_client.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/validator_client.sh @@ -21,9 +21,9 @@ while getopts "pd:" flag; do done exec lighthouse \ - --debug-level $DEBUG_LEVEL \ vc \ $BUILDER_PROPOSALS \ + --debug-level $DEBUG_LEVEL \ --validators-dir $DATADIR/node_$NODE_NUMBER/validators \ --secrets-dir $DATADIR/node_$NODE_NUMBER/secrets \ --testnet-dir $TESTNET_DIR \ diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh index 13e137fb..8e80efbb 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh @@ -58,6 +58,21 @@ else export JWTSECRET="/opt/testnet/build/cl/jwtsecret" echo -n "$JWT" > $JWTSECRET + # See https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script + cleanup() { + echo "Signal received, cleaning up..." + + beacon_node_pid=$(pgrep -o -f 'lighthouse bn') + validator_client_pid=$(pgrep -o -f 'lighthouse vc') + + kill ${beacon_node_pid} + kill ${validator_client_pid} + + wait + echo "Done" + } + trap 'cleanup' SIGINT SIGTERM + ./beacon_node.sh 2>&1 | tee /var/log/lighthouse_bn.log & lpid=$! ./validator_client.sh 2>&1 | tee /var/log/lighthouse_vc.log & -- 2.45.2 From 671979b18fdfe7cdaf2f1fd44fe36ad0d64eaacb Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Tue, 18 Apr 2023 13:39:46 +0530 Subject: [PATCH 6/9] Allow stalled sync in lighthouse beacon nodes --- .../cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh | 3 ++- .../cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh index 93207d27..1f906155 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh @@ -38,4 +38,5 @@ exec lighthouse \ --execution-jwt $JWTSECRET \ --terminal-total-difficulty-override $ETH1_TTD \ --suggested-fee-recipient $SUGGESTED_FEE_RECIPIENT \ - --target-peers $((BN_COUNT - 1)) + --target-peers $((BN_COUNT - 1)) \ + --http-allow-sync-stalled \ diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh index 7563371c..a395f41a 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh @@ -24,7 +24,7 @@ if [ ! -f "$DATADIR/bootnode/enr.dat" ]; then --output-dir $DATADIR/bootnode-temp # Output ENR to a temp dir and mv as "lcli generate-bootnode-enr" will not overwrite an empty dir (mounted volume) - mkdir -p $DATADIR/bootnode + mkdir -p $DATADIR/bootnode mv $DATADIR/bootnode-temp/* $DATADIR/bootnode rm -r $DATADIR/bootnode-temp -- 2.45.2 From df058b6d27f9262bf5ad81aa03b2b496fba7259e Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Tue, 18 Apr 2023 17:56:09 +0530 Subject: [PATCH 7/9] Gracefully shutdown geth nodes --- .../cerc-fixturenet-eth-geth/run-el.sh | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) 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 aed555ef..8477561a 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 @@ -18,6 +18,19 @@ if [ "true" == "$CERC_REMOTE_DEBUG" ] && [ -x "/usr/local/bin/dlv" ]; then START_CMD="/usr/local/bin/dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /usr/local/bin/geth --continue --" fi +cleanup() { + echo "Signal received, cleaning up..." + + # Kill the child process first (CERC_REMOTE_DEBUG=true uses dlv which starts geth as a child) + pkill -P ${geth_pid} + sleep 3 + kill ${geth_pid} + + wait + echo "Done" +} +trap 'cleanup' SIGINT SIGTERM + if [ "true" == "$RUN_BOOTNODE" ]; then $START_CMD \ --datadir=~/ethdata \ @@ -25,7 +38,10 @@ if [ "true" == "$RUN_BOOTNODE" ]; then --nodiscover \ --ipcdisable \ --networkid=${NETWORK_ID} \ - --netrestrict="${NETRESTRICT}" + --netrestrict="${NETRESTRICT}" \ + & + + geth_pid=$! else cd /opt/testnet/accounts ./import_keys.sh @@ -103,5 +119,10 @@ else --metrics.addr="0.0.0.0" \ --verbosity=${CERC_GETH_VERBOSITY:-3} \ --vmodule="${CERC_GETH_VMODULE:-statediff/*=5}" \ - --miner.etherbase="${ETHERBASE}" ${STATEDIFF_OPTS} + --miner.etherbase="${ETHERBASE}" ${STATEDIFF_OPTS} \ + & + + geth_pid=$! fi + +wait $geth_pid -- 2.45.2 From aeff5085ebf126c3f4b7a7eaefdbcee4a900d6cb Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Tue, 18 Apr 2023 19:43:17 +0530 Subject: [PATCH 8/9] Add clean up instructions --- app/data/stacks/fixturenet-eth/README.md | 28 +++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/data/stacks/fixturenet-eth/README.md b/app/data/stacks/fixturenet-eth/README.md index 3aa41dec..95011127 100644 --- a/app/data/stacks/fixturenet-eth/README.md +++ b/app/data/stacks/fixturenet-eth/README.md @@ -3,15 +3,18 @@ Instructions for deploying a local a geth + lighthouse blockchain "fixturenet" for development and testing purposes using laconic-stack-orchestrator (the installation of which is covered [here](https://github.com/cerc-io/stack-orchestrator#user-mode)): ## Clone required repositories + ``` $ laconic-so --stack fixturenet-eth setup-repositories ``` ## Build the fixturenet-eth containers + ``` $ laconic-so --stack fixturenet-eth build-containers ``` -This should create several container images in the local image registry: + +This should create several container images in the local image registry: * cerc/go-ethereum * cerc/lighthouse @@ -19,6 +22,7 @@ This should create several container images in the local image registry: * cerc/fixturenet-eth-lighthouse ## Deploy the stack + ``` $ laconic-so --stack fixturenet-eth deploy up ``` @@ -57,7 +61,7 @@ Several other containers can used with the basic `fixturenet-eth`: * `eth-probe` (captures eth1 tx gossip) * `keycloak` (nginx proxy with keycloak auth for API authentication) * `tx-spammer` (generates and sends automated transactions to the fixturenet) - + It is not necessary to use them all at once, but a complete example follows: ``` @@ -99,4 +103,22 @@ keycloak-db-1 0.0.0.0:55850->5432/tcp keycloak-nginx-1 0.0.0.0:55859->80/tcp migrations-1 tx-spammer-1 -``` \ No newline at end of file +``` + +## Clean up + +Stop all services running in the background: + +```bash +$ laconic-so --stack fixturenet-eth deploy down +``` + +Clear volumes created by this stack: + +```bash +# List all relevant volumes +docker volume ls -q --filter "name=.*fixturenet_eth_bootnode_geth_data|.*fixturenet_eth_bootnode_lighthouse_data|.*fixturenet_eth_geth_1_data|.*fixturenet_eth_geth_2_data|.*fixturenet_eth_lighthouse_1_data|.*fixturenet_eth_lighthouse_2_data|.*fixturenet_geth_accounts" + +# Remove all the listed volumes +docker volume rm $(docker volume ls -q --filter "name=.*fixturenet_eth_bootnode_geth_data|.*fixturenet_eth_bootnode_lighthouse_data|.*fixturenet_eth_geth_1_data|.*fixturenet_eth_geth_2_data|.*fixturenet_eth_lighthouse_1_data|.*fixturenet_eth_lighthouse_2_data|.*fixturenet_geth_accounts") +``` -- 2.45.2 From 6fdad74e1414c1d11363e55726de366ef0c57173 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Wed, 19 Apr 2023 10:24:41 +0530 Subject: [PATCH 9/9] Gracefully shutdown lighthouse boot node --- .../cerc-fixturenet-eth-geth/run-el.sh | 7 ++-- .../cerc-fixturenet-eth-lighthouse/run-cl.sh | 37 +++++++++---------- app/data/stacks/fixturenet-eth/README.md | 4 +- 3 files changed, 23 insertions(+), 25 deletions(-) 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 8477561a..526c76d7 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 @@ -18,13 +18,14 @@ if [ "true" == "$CERC_REMOTE_DEBUG" ] && [ -x "/usr/local/bin/dlv" ]; then START_CMD="/usr/local/bin/dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /usr/local/bin/geth --continue --" fi +# See https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script cleanup() { echo "Signal received, cleaning up..." - # Kill the child process first (CERC_REMOTE_DEBUG=true uses dlv which starts geth as a child) + # Kill the child process first (CERC_REMOTE_DEBUG=true uses dlv which starts geth as a child process) pkill -P ${geth_pid} - sleep 3 - kill ${geth_pid} + sleep 2 + kill $(jobs -p) wait echo "Done" diff --git a/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh b/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh index 8e80efbb..ec0e9aeb 100755 --- a/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh +++ b/app/data/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh @@ -1,12 +1,25 @@ #!/bin/bash +# See https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script +cleanup() { + echo "Signal received, cleaning up..." + kill $(jobs -p) + + wait + echo "Done" +} +trap 'cleanup' SIGINT SIGTERM + if [ "true" == "$RUN_BOOTNODE" ]; then cd /opt/testnet/build/cl python3 -m http.server 3000 & cd /opt/testnet/cl - ./bootnode.sh 2>&1 | tee /var/log/lighthouse_bootnode.log + ./bootnode.sh 2>&1 | tee /var/log/lighthouse_bootnode.log & + bootnode_pid=$! + + wait $bootnode_pid else while [ 1 -eq 1 ]; do echo "Waiting on geth ..." @@ -58,26 +71,10 @@ else export JWTSECRET="/opt/testnet/build/cl/jwtsecret" echo -n "$JWT" > $JWTSECRET - # See https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script - cleanup() { - echo "Signal received, cleaning up..." - - beacon_node_pid=$(pgrep -o -f 'lighthouse bn') - validator_client_pid=$(pgrep -o -f 'lighthouse vc') - - kill ${beacon_node_pid} - kill ${validator_client_pid} - - wait - echo "Done" - } - trap 'cleanup' SIGINT SIGTERM - ./beacon_node.sh 2>&1 | tee /var/log/lighthouse_bn.log & - lpid=$! + beacon_pid=$! ./validator_client.sh 2>&1 | tee /var/log/lighthouse_vc.log & - vpid=$! + validator_pid=$! - wait $lpid $vpid + wait $beacon_pid $validator_pid fi - diff --git a/app/data/stacks/fixturenet-eth/README.md b/app/data/stacks/fixturenet-eth/README.md index 95011127..86404af0 100644 --- a/app/data/stacks/fixturenet-eth/README.md +++ b/app/data/stacks/fixturenet-eth/README.md @@ -117,8 +117,8 @@ Clear volumes created by this stack: ```bash # List all relevant volumes -docker volume ls -q --filter "name=.*fixturenet_eth_bootnode_geth_data|.*fixturenet_eth_bootnode_lighthouse_data|.*fixturenet_eth_geth_1_data|.*fixturenet_eth_geth_2_data|.*fixturenet_eth_lighthouse_1_data|.*fixturenet_eth_lighthouse_2_data|.*fixturenet_geth_accounts" +$ docker volume ls -q --filter "name=.*fixturenet_eth_bootnode_geth_data|.*fixturenet_eth_bootnode_lighthouse_data|.*fixturenet_eth_geth_1_data|.*fixturenet_eth_geth_2_data|.*fixturenet_eth_lighthouse_1_data|.*fixturenet_eth_lighthouse_2_data|.*fixturenet_geth_accounts" # Remove all the listed volumes -docker volume rm $(docker volume ls -q --filter "name=.*fixturenet_eth_bootnode_geth_data|.*fixturenet_eth_bootnode_lighthouse_data|.*fixturenet_eth_geth_1_data|.*fixturenet_eth_geth_2_data|.*fixturenet_eth_lighthouse_1_data|.*fixturenet_eth_lighthouse_2_data|.*fixturenet_geth_accounts") +$ docker volume rm $(docker volume ls -q --filter "name=.*fixturenet_eth_bootnode_geth_data|.*fixturenet_eth_bootnode_lighthouse_data|.*fixturenet_eth_geth_1_data|.*fixturenet_eth_geth_2_data|.*fixturenet_eth_lighthouse_1_data|.*fixturenet_eth_lighthouse_2_data|.*fixturenet_geth_accounts") ``` -- 2.45.2