From 162b77bb6719cca9108626bfc2dd33a3a842e0c5 Mon Sep 17 00:00:00 2001 From: dapplion <35266934+dapplion@users.noreply.github.com> Date: Sat, 28 Sep 2024 14:00:59 +0200 Subject: [PATCH 1/3] Clean up scripts --- apply_test_vectors_nethermind.sh | 8 ----- apply_test_vectors_reth.sh | 7 ---- .../apply_test_vectors.sh | 5 ++- scripts/apply_test_vectors_nethermind.sh | 20 +++++++++++ scripts/apply_test_vectors_reth.sh | 19 +++++++++++ {blocks => scripts/blocks}/block_1.json | 0 {blocks => scripts/blocks}/block_2.json | 0 {blocks => scripts/blocks}/block_3.json | 0 {blocks => scripts/blocks}/block_4.json | 0 {blocks => scripts/blocks}/block_5.json | 0 .../chiado_allocs_gballet.txt | 0 .../chiado_genesis_alloc.json | 0 .../chiado_genesis_marek.json | 0 .../generate_chiado_genesis.py | 0 .../generate_test_vectors.sh | 33 +++---------------- scripts/generate_test_vectors_nethermind.sh | 28 ++++++++++++++++ scripts/generate_test_vectors_reth.sh | 26 +++++++++++++++ make_block.sh => scripts/make_block.sh | 0 .../networkdata}/chainspec.json | 0 .../networkdata}/jwtsecret | 0 .../networkdata}/reth_genesis.json | 0 poll_genesis.sh => scripts/poll_genesis.sh | 0 .../run_nethermind.sh | 7 ++-- run_reth.sh => scripts/run_reth.sh | 7 ++-- 24 files changed, 112 insertions(+), 48 deletions(-) delete mode 100755 apply_test_vectors_nethermind.sh delete mode 100755 apply_test_vectors_reth.sh rename apply_test_vectors.sh => scripts/apply_test_vectors.sh (96%) create mode 100755 scripts/apply_test_vectors_nethermind.sh create mode 100755 scripts/apply_test_vectors_reth.sh rename {blocks => scripts/blocks}/block_1.json (100%) rename {blocks => scripts/blocks}/block_2.json (100%) rename {blocks => scripts/blocks}/block_3.json (100%) rename {blocks => scripts/blocks}/block_4.json (100%) rename {blocks => scripts/blocks}/block_5.json (100%) rename chiado_allocs_gballet.txt => scripts/chiado_allocs_gballet.txt (100%) rename chiado_genesis_alloc.json => scripts/chiado_genesis_alloc.json (100%) rename chiado_genesis_marek.json => scripts/chiado_genesis_marek.json (100%) rename generate_chiado_genesis.py => scripts/generate_chiado_genesis.py (100%) mode change 100644 => 100755 rename generate_test_vectors.sh => scripts/generate_test_vectors.sh (83%) create mode 100755 scripts/generate_test_vectors_nethermind.sh create mode 100755 scripts/generate_test_vectors_reth.sh rename make_block.sh => scripts/make_block.sh (100%) rename {networkdata => scripts/networkdata}/chainspec.json (100%) rename {networkdata => scripts/networkdata}/jwtsecret (100%) rename {networkdata => scripts/networkdata}/reth_genesis.json (100%) rename poll_genesis.sh => scripts/poll_genesis.sh (100%) rename run_nethermind.sh => scripts/run_nethermind.sh (86%) rename run_reth.sh => scripts/run_reth.sh (83%) diff --git a/apply_test_vectors_nethermind.sh b/apply_test_vectors_nethermind.sh deleted file mode 100755 index 82d4841..0000000 --- a/apply_test_vectors_nethermind.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -./run_nethermind.sh & -./apply_test_vectors.sh -# TODO more resilient shutdown -docker rm -f neth-vec-gen 2>/dev/null - diff --git a/apply_test_vectors_reth.sh b/apply_test_vectors_reth.sh deleted file mode 100755 index 1a44521..0000000 --- a/apply_test_vectors_reth.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -e - -./run_reth.sh & -./apply_test_vectors.sh - - diff --git a/apply_test_vectors.sh b/scripts/apply_test_vectors.sh similarity index 96% rename from apply_test_vectors.sh rename to scripts/apply_test_vectors.sh index 99ec2df..972e966 100755 --- a/apply_test_vectors.sh +++ b/scripts/apply_test_vectors.sh @@ -3,7 +3,10 @@ set -e # Expects reth to be running on the background -OUT_DIR=./blocks +# Script's directory +DIR="$(dirname "$0")" + +OUT_DIR=$DIR/blocks N=5 diff --git a/scripts/apply_test_vectors_nethermind.sh b/scripts/apply_test_vectors_nethermind.sh new file mode 100755 index 0000000..4eed479 --- /dev/null +++ b/scripts/apply_test_vectors_nethermind.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +# Script's directory +DIR="$(dirname "$0")" + +$DIR/run_nethermind.sh & +BG_PID=$! + +# Set the trap to call cleanup +cleanup() { + echo "Stopping node process (PID: $BG_PID)..." + kill $BG_PID 2>/dev/null || true + # Also force clean the docker container, killing the attached process is not enough + docker rm -f neth-vec-gen 2>/dev/null || true +} +trap cleanup EXIT + +$DIR/apply_test_vectors.sh + diff --git a/scripts/apply_test_vectors_reth.sh b/scripts/apply_test_vectors_reth.sh new file mode 100755 index 0000000..443f6cf --- /dev/null +++ b/scripts/apply_test_vectors_reth.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +# Script's directory +DIR="$(dirname "$0")" + +$DIR/run_reth.sh & +BG_PID=$! + +# Set the trap to call cleanup if an error occurs +cleanup() { + echo "Stopping node process (PID: $BG_PID)..." + kill $BG_PID 2>/dev/null || true +} +trap cleanup EXIT + +$DIR/apply_test_vectors.sh + + diff --git a/blocks/block_1.json b/scripts/blocks/block_1.json similarity index 100% rename from blocks/block_1.json rename to scripts/blocks/block_1.json diff --git a/blocks/block_2.json b/scripts/blocks/block_2.json similarity index 100% rename from blocks/block_2.json rename to scripts/blocks/block_2.json diff --git a/blocks/block_3.json b/scripts/blocks/block_3.json similarity index 100% rename from blocks/block_3.json rename to scripts/blocks/block_3.json diff --git a/blocks/block_4.json b/scripts/blocks/block_4.json similarity index 100% rename from blocks/block_4.json rename to scripts/blocks/block_4.json diff --git a/blocks/block_5.json b/scripts/blocks/block_5.json similarity index 100% rename from blocks/block_5.json rename to scripts/blocks/block_5.json diff --git a/chiado_allocs_gballet.txt b/scripts/chiado_allocs_gballet.txt similarity index 100% rename from chiado_allocs_gballet.txt rename to scripts/chiado_allocs_gballet.txt diff --git a/chiado_genesis_alloc.json b/scripts/chiado_genesis_alloc.json similarity index 100% rename from chiado_genesis_alloc.json rename to scripts/chiado_genesis_alloc.json diff --git a/chiado_genesis_marek.json b/scripts/chiado_genesis_marek.json similarity index 100% rename from chiado_genesis_marek.json rename to scripts/chiado_genesis_marek.json diff --git a/generate_chiado_genesis.py b/scripts/generate_chiado_genesis.py old mode 100644 new mode 100755 similarity index 100% rename from generate_chiado_genesis.py rename to scripts/generate_chiado_genesis.py diff --git a/generate_test_vectors.sh b/scripts/generate_test_vectors.sh similarity index 83% rename from generate_test_vectors.sh rename to scripts/generate_test_vectors.sh index 475f10f..0a37782 100755 --- a/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -# Script to generate test vectors from Nethermind. It connects to the engine API of Nethermid to produce +# Script to generate test vectors for a running client. It connects to the engine API at :8546 to produce # blocks on the genesis block and stores them in $OUT_DIR. The jwtsecret is hardcoded, do not modify it. # To run just do: # @@ -9,32 +9,12 @@ set -e # ./generate_test_vectors.sh # ``` -OUT_DIR=./blocks +# Script's directory +DIR="$(dirname "$0")" + +OUT_DIR=$DIR/blocks mkdir -p $OUT_DIR -# Clean up existing container if it exists -docker rm -f neth-vec-gen 2>/dev/null - -# Start the container in the background -docker run --name neth-vec-gen --rm -d \ - -v $PWD/networkdata:/networkdata \ - -p 8545:8545 \ - -p 8546:8546 \ - nethermind/nethermind \ - --config=none \ - --Init.ChainSpecPath=/networkdata/chainspec.json \ - --Init.DiscoveryEnabled=false \ - --JsonRpc.Enabled=true \ - --JsonRpc.Host=0.0.0.0 \ - --JsonRpc.Port=8545 \ - --JsonRpc.EngineHost=0.0.0.0 \ - --JsonRpc.EnginePort=8546 \ - --JsonRpc.JwtSecretFile=/networkdata/jwtsecret \ - --TraceStore.Enabled=true - # --Init.ExitOnBlockNumber=4 \ - -# Capture the logs in the background -docker logs -f neth-vec-gen & # Retry the curl command until it succeeds until curl -X POST -H "Content-Type: application/json" \ @@ -169,6 +149,3 @@ for ((i = 1; i <= N; i++)); do make_block done -# Clean up container -docker rm -f neth-vec-gen 2>/dev/null - diff --git a/scripts/generate_test_vectors_nethermind.sh b/scripts/generate_test_vectors_nethermind.sh new file mode 100755 index 0000000..ad52753 --- /dev/null +++ b/scripts/generate_test_vectors_nethermind.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -e + +# Script to generate test vectors from Nethermind. It connects to the engine API of Nethermid to produce +# blocks on the genesis block and stores them in $OUT_DIR. The jwtsecret is hardcoded, do not modify it. +# To run just do: +# +# ``` +# ./generate_test_vectors_nethermind.sh +# ``` + +# Script's directory +DIR="$(dirname "$0")" + +$DIR/run_nethermind.sh & +BG_PID=$! + +# Set the trap to call cleanup +cleanup() { + echo "Stopping node process (PID: $BG_PID)..." + kill $BG_PID 2>/dev/null || true + # Also force clean the docker container, killing the attached process is not enough + docker rm -f neth-vec-gen 2>/dev/null || true +} +trap cleanup EXIT + +$DIR/generate_test_vectors.sh + diff --git a/scripts/generate_test_vectors_reth.sh b/scripts/generate_test_vectors_reth.sh new file mode 100755 index 0000000..906adfd --- /dev/null +++ b/scripts/generate_test_vectors_reth.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +# Script to generate test vectors from Reth. It connects to the engine API of Reth to produce +# blocks on the genesis block and stores them in $OUT_DIR. The jwtsecret is hardcoded, do not modify it. +# To run just do: +# +# ``` +# ./generate_test_vectors_reth.sh +# ``` + +# Script's directory +DIR="$(dirname "$0")" + +$DIR/run_reth.sh & +BG_PID=$! + +# Set the trap to call cleanup if an error occurs +cleanup() { + echo "Stopping node process (PID: $BG_PID)..." + kill $BG_PID 2>/dev/null || true +} +trap cleanup EXIT + +$DIR/generate_test_vectors.sh + diff --git a/make_block.sh b/scripts/make_block.sh similarity index 100% rename from make_block.sh rename to scripts/make_block.sh diff --git a/networkdata/chainspec.json b/scripts/networkdata/chainspec.json similarity index 100% rename from networkdata/chainspec.json rename to scripts/networkdata/chainspec.json diff --git a/networkdata/jwtsecret b/scripts/networkdata/jwtsecret similarity index 100% rename from networkdata/jwtsecret rename to scripts/networkdata/jwtsecret diff --git a/networkdata/reth_genesis.json b/scripts/networkdata/reth_genesis.json similarity index 100% rename from networkdata/reth_genesis.json rename to scripts/networkdata/reth_genesis.json diff --git a/poll_genesis.sh b/scripts/poll_genesis.sh similarity index 100% rename from poll_genesis.sh rename to scripts/poll_genesis.sh diff --git a/run_nethermind.sh b/scripts/run_nethermind.sh similarity index 86% rename from run_nethermind.sh rename to scripts/run_nethermind.sh index 215e821..b881486 100755 --- a/run_nethermind.sh +++ b/scripts/run_nethermind.sh @@ -4,12 +4,15 @@ set -e # Script to run Nethermind dockerized and attach to it. # The jwtsecret is hardcoded, do not modify it. +# Script's directory +DIR="$(dirname "$0")" + # Clean up existing container if it exists docker rm -f neth-vec-gen 2>/dev/null -# Start the container in the background +# Start the container docker run --name neth-vec-gen --rm \ - -v $PWD/networkdata:/networkdata \ + -v $DIR/networkdata:/networkdata \ -p 8545:8545 \ -p 8546:8546 \ nethermind/nethermind \ diff --git a/run_reth.sh b/scripts/run_reth.sh similarity index 83% rename from run_reth.sh rename to scripts/run_reth.sh index 16d1947..e141973 100755 --- a/run_reth.sh +++ b/scripts/run_reth.sh @@ -8,11 +8,14 @@ DATA_DIR=$TMPDIR/reth_test # Ensure no data from previous tests rm -rf $DATA_DIR +# Script's directory +DIR="$(dirname "$0")" + # $PWD/target/release/reth \ cargo run -- \ node \ -vvvv \ - --chain=$PWD/chiado_genesis_alloc.json \ + --chain=$DIR/chiado_genesis_alloc.json \ --datadir=$DATA_DIR \ --http \ --http.port=8545 \ @@ -20,7 +23,7 @@ cargo run -- \ --http.corsdomain='*' \ --http.api=admin,net,eth,web3,debug,trace \ --authrpc.port=8546 \ - --authrpc.jwtsecret=$PWD/networkdata/jwtsecret \ + --authrpc.jwtsecret=$DIR/networkdata/jwtsecret \ --authrpc.addr=0.0.0.0 \ --port=0 \ --disable-discovery From d48780cd10ec0b0aba79a0adcab3394c6c9534b9 Mon Sep 17 00:00:00 2001 From: dapplion <35266934+dapplion@users.noreply.github.com> Date: Sat, 28 Sep 2024 14:05:09 +0200 Subject: [PATCH 2/3] Update workflow paths --- .github/workflows/post-merge-run.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/post-merge-run.yml b/.github/workflows/post-merge-run.yml index 97da2d1..6dd25f4 100644 --- a/.github/workflows/post-merge-run.yml +++ b/.github/workflows/post-merge-run.yml @@ -37,12 +37,12 @@ jobs: run: jq --help # Vectors are already generated, but this serves as a test - name: Generate vectors - run: ./generate_test_vectors.sh + run: ./scripts/generate_test_vectors_nethermind.sh # Test vectors against nethermind - name: Apply vectors to Nethermind - run: ./apply_test_vectors_nethermind.sh + run: ./scripts/apply_test_vectors_nethermind.sh # Test vectors against Reth - name: Apply vectors to Reth - run: ./apply_test_vectors_reth.sh + run: ./scripts/apply_test_vectors_reth.sh From 4b7c4bea39e67cf4560c4ec4e73746bd544ef3dc Mon Sep 17 00:00:00 2001 From: dapplion <35266934+dapplion@users.noreply.github.com> Date: Sat, 28 Sep 2024 14:12:25 +0200 Subject: [PATCH 3/3] Run with bash: --- .github/workflows/post-merge-run.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/post-merge-run.yml b/.github/workflows/post-merge-run.yml index 6dd25f4..c1f6ebe 100644 --- a/.github/workflows/post-merge-run.yml +++ b/.github/workflows/post-merge-run.yml @@ -37,12 +37,12 @@ jobs: run: jq --help # Vectors are already generated, but this serves as a test - name: Generate vectors - run: ./scripts/generate_test_vectors_nethermind.sh + run: bash ./scripts/generate_test_vectors_nethermind.sh # Test vectors against nethermind - name: Apply vectors to Nethermind - run: ./scripts/apply_test_vectors_nethermind.sh + run: bash ./scripts/apply_test_vectors_nethermind.sh # Test vectors against Reth - name: Apply vectors to Reth - run: ./scripts/apply_test_vectors_reth.sh + run: bash ./scripts/apply_test_vectors_reth.sh