From e0cd4e4fbe2515bdc1815288f1b60bfa9cc761c1 Mon Sep 17 00:00:00 2001 From: debjit Date: Fri, 11 Oct 2024 18:16:59 +0530 Subject: [PATCH 01/20] retry --- scripts/generate_test_vectors_nethermind.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/generate_test_vectors_nethermind.sh b/scripts/generate_test_vectors_nethermind.sh index ad52753..0211e31 100755 --- a/scripts/generate_test_vectors_nethermind.sh +++ b/scripts/generate_test_vectors_nethermind.sh @@ -24,5 +24,22 @@ cleanup() { } trap cleanup EXIT -$DIR/generate_test_vectors.sh +# Function to check if Nethermind is available +check_nethermind_availability() { + until curl -X POST -H "Content-Type: application/json" \ + --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":1}' \ + http://localhost:8545; do + echo "Retrying..." + sleep 2 + done + echo "Nethermind is available" + return 0 +} + +# Wait for Nethermind to become available +while ! check_nethermind_availability; do + sleep 2 +done +# Generate test vectors +$DIR/generate_test_vectors.sh \ No newline at end of file From 4493821498a3f7f56a476b4fce13df8ab2662efc Mon Sep 17 00:00:00 2001 From: debjit Date: Fri, 11 Oct 2024 18:30:21 +0530 Subject: [PATCH 02/20] retry function moved inside script --- scripts/generate_test_vectors.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index 0a37782..f168348 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -17,11 +17,21 @@ mkdir -p $OUT_DIR # Retry the curl command until it succeeds -until curl -X POST -H "Content-Type: application/json" \ - --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":1}' \ - http://localhost:8545; do +# Function to check if Nethermind is available +check_nethermind_availability() { + until curl -X POST -H "Content-Type: application/json" \ + --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":1}' \ + http://localhost:8545; do echo "Retrying..." sleep 2 + done + echo "Nethermind is available" + return 0 +} + +# Wait for Nethermind to become available +while ! check_nethermind_availability; do + sleep 2 done BLOCK_COUNTER=0 From 84c9302ff2ff95a6554ef0da109da72e51dd0c6b Mon Sep 17 00:00:00 2001 From: debjit Date: Fri, 11 Oct 2024 18:36:12 +0530 Subject: [PATCH 03/20] . --- .github/workflows/{test.yml => test.yml.hold} | 0 scripts/generate_test_vectors.sh | 2 +- scripts/generate_test_vectors_nethermind.sh | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{test.yml => test.yml.hold} (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml.hold similarity index 100% rename from .github/workflows/test.yml rename to .github/workflows/test.yml.hold diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index f168348..47b1fa8 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -26,7 +26,7 @@ check_nethermind_availability() { sleep 2 done echo "Nethermind is available" - return 0 + # return 0 } # Wait for Nethermind to become available diff --git a/scripts/generate_test_vectors_nethermind.sh b/scripts/generate_test_vectors_nethermind.sh index 0211e31..67d2f69 100755 --- a/scripts/generate_test_vectors_nethermind.sh +++ b/scripts/generate_test_vectors_nethermind.sh @@ -33,7 +33,7 @@ check_nethermind_availability() { sleep 2 done echo "Nethermind is available" - return 0 + # return 0 } # Wait for Nethermind to become available From 87b233cdab3384a2a3b527668d6787cffc41dda2 Mon Sep 17 00:00:00 2001 From: debjit Date: Fri, 11 Oct 2024 18:39:29 +0530 Subject: [PATCH 04/20] debug --- scripts/generate_test_vectors.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index 47b1fa8..2ef0516 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -29,11 +29,15 @@ check_nethermind_availability() { # return 0 } +echo "Waiting for Nethermind to become available..." + # Wait for Nethermind to become available while ! check_nethermind_availability; do sleep 2 done +echo "Nethermind is available" + BLOCK_COUNTER=0 function make_block() { @@ -156,6 +160,7 @@ function make_block() { N=5 for ((i = 1; i <= N; i++)); do + echo "Making block $i" make_block done From df25689190ff78d2c344a6b6c062e31cb9201e52 Mon Sep 17 00:00:00 2001 From: debjit Date: Fri, 11 Oct 2024 18:46:18 +0530 Subject: [PATCH 05/20] sleep --- scripts/generate_test_vectors.sh | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index 2ef0516..6a5791f 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -39,17 +39,33 @@ done echo "Nethermind is available" BLOCK_COUNTER=0 +MAX_RETRIES=3 function make_block() { ((BLOCK_COUNTER++)) + RETRIES=0 + + while [ $RETRIES -lt $MAX_RETRIES ]; do + HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ + --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' \ + http://localhost:8545) + + # Extract block hash and proceed if it's valid + HEAD_BLOCK_HASH=$(echo $HEAD_BLOCK | jq --raw-output '.result.hash') + if [ "$HEAD_BLOCK_HASH" != "null" ]; then + echo "HEAD_BLOCK_HASH=$HEAD_BLOCK_HASH" + break + fi + + echo "Failed to get head block, retrying... ($RETRIES/$MAX_RETRIES)" + RETRIES=$((RETRIES + 1)) + sleep 2 + done - HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ - --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' \ - http://localhost:8545) - - # --raw-output remove the double quotes - HEAD_BLOCK_HASH=$(echo $HEAD_BLOCK | jq --raw-output '.result.hash') - echo HEAD_BLOCK_HASH=$HEAD_BLOCK_HASH + if [ $RETRIES -ge $MAX_RETRIES ]; then + echo "Failed to retrieve head block after $MAX_RETRIES attempts, exiting." + exit 1 + fi # The ASCII representation of `2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a` JWT_SECRET="********************************" @@ -161,6 +177,7 @@ N=5 for ((i = 1; i <= N; i++)); do echo "Making block $i" + sleep 2 make_block done From a6ba6acbf775e46db413dcefa4fc60d4e6c5ddfa Mon Sep 17 00:00:00 2001 From: debjit Date: Fri, 11 Oct 2024 18:51:37 +0530 Subject: [PATCH 06/20] next test --- .github/workflows/post-merge-run.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/post-merge-run.yml b/.github/workflows/post-merge-run.yml index c1f6ebe..0c18e31 100644 --- a/.github/workflows/post-merge-run.yml +++ b/.github/workflows/post-merge-run.yml @@ -36,8 +36,8 @@ jobs: - name: Test jq is installed run: jq --help # Vectors are already generated, but this serves as a test - - name: Generate vectors - run: bash ./scripts/generate_test_vectors_nethermind.sh + # - name: Generate vectors + # run: bash ./scripts/generate_test_vectors_nethermind.sh # Test vectors against nethermind - name: Apply vectors to Nethermind run: bash ./scripts/apply_test_vectors_nethermind.sh From 4c938b016fb853381a28eb99d5bcbe51f0271bbc Mon Sep 17 00:00:00 2001 From: debjit Date: Fri, 11 Oct 2024 18:54:37 +0530 Subject: [PATCH 07/20] jwt --- .github/workflows/post-merge-run.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/post-merge-run.yml b/.github/workflows/post-merge-run.yml index 0c18e31..611ed81 100644 --- a/.github/workflows/post-merge-run.yml +++ b/.github/workflows/post-merge-run.yml @@ -39,6 +39,8 @@ jobs: # - name: Generate vectors # run: bash ./scripts/generate_test_vectors_nethermind.sh # Test vectors against nethermind + - name: Install jwt and add to path + run: cargo install jwt-cli && export PATH=$HOME/.cargo/bin:$PATH - name: Apply vectors to Nethermind run: bash ./scripts/apply_test_vectors_nethermind.sh # Test vectors against Reth From 2ebb301d77c1dd90fed21beaed0ec2c5b15bb719 Mon Sep 17 00:00:00 2001 From: debjit Date: Fri, 11 Oct 2024 19:32:58 +0530 Subject: [PATCH 08/20] tmp dir change --- scripts/run_reth.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/run_reth.sh b/scripts/run_reth.sh index e141973..ef540aa 100755 --- a/scripts/run_reth.sh +++ b/scripts/run_reth.sh @@ -4,6 +4,8 @@ # # reth genesis from https://github.com/ethpandaops/ethereum-genesis-generator/blob/a4b6733ea9d47b2b2ec497f5212f0265b83fb601/apps/el-gen/genesis_geth.py#L34 +# if TMPDIR is empty, use /tmp +TMPDIR=${TMPDIR:-/tmp} DATA_DIR=$TMPDIR/reth_test # Ensure no data from previous tests rm -rf $DATA_DIR From 09d21bc86691a4d1a62bbd790500c637b2fb1587 Mon Sep 17 00:00:00 2001 From: debjit Date: Fri, 11 Oct 2024 20:34:32 +0530 Subject: [PATCH 09/20] ci final fix minus generation --- scripts/apply_test_vectors.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/apply_test_vectors.sh b/scripts/apply_test_vectors.sh index 972e966..c3a426b 100755 --- a/scripts/apply_test_vectors.sh +++ b/scripts/apply_test_vectors.sh @@ -66,6 +66,13 @@ function apply_block_file() { http://localhost:8546 \ ) echo engine_forkchoiceUpdatedV1 set new block as head RESPONSE $RESPONSE + + PAYLOAD_STATUS=$(echo $RESPONSE | jq --raw-output '.result.payloadStatus.status') + # If the status is not "VALID", exit the script with a non-zero code to make CI fail + if [ "$STATUS" != "VALID" ]; then + echo "Error: Payload status is $STATUS, failing CI." + exit 1 + fi } From 444badbb237804d9f45997512fc3d411e31d3ee5 Mon Sep 17 00:00:00 2001 From: debjit Date: Fri, 11 Oct 2024 21:39:00 +0530 Subject: [PATCH 10/20] debug --- scripts/apply_test_vectors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/apply_test_vectors.sh b/scripts/apply_test_vectors.sh index c3a426b..08ce197 100755 --- a/scripts/apply_test_vectors.sh +++ b/scripts/apply_test_vectors.sh @@ -69,7 +69,7 @@ function apply_block_file() { PAYLOAD_STATUS=$(echo $RESPONSE | jq --raw-output '.result.payloadStatus.status') # If the status is not "VALID", exit the script with a non-zero code to make CI fail - if [ "$STATUS" != "VALID" ]; then + if [ "$PAYLOAD_STATUS" != "VALID" ]; then echo "Error: Payload status is $STATUS, failing CI." exit 1 fi From 08ff5c11f309c4b2341361a01880ec80252096d9 Mon Sep 17 00:00:00 2001 From: debjit Date: Fri, 11 Oct 2024 21:43:56 +0530 Subject: [PATCH 11/20] jwt fix --- .github/workflows/post-merge-run.yml | 4 ++-- scripts/generate_test_vectors.sh | 35 ++++++---------------------- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/.github/workflows/post-merge-run.yml b/.github/workflows/post-merge-run.yml index 611ed81..de97c63 100644 --- a/.github/workflows/post-merge-run.yml +++ b/.github/workflows/post-merge-run.yml @@ -36,8 +36,8 @@ jobs: - name: Test jq is installed run: jq --help # Vectors are already generated, but this serves as a test - # - name: Generate vectors - # run: bash ./scripts/generate_test_vectors_nethermind.sh + - name: Generate vectors + run: bash ./scripts/generate_test_vectors_nethermind.sh # Test vectors against nethermind - name: Install jwt and add to path run: cargo install jwt-cli && export PATH=$HOME/.cargo/bin:$PATH diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index 6a5791f..a789734 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -29,43 +29,23 @@ check_nethermind_availability() { # return 0 } -echo "Waiting for Nethermind to become available..." - # Wait for Nethermind to become available while ! check_nethermind_availability; do sleep 2 done -echo "Nethermind is available" - BLOCK_COUNTER=0 -MAX_RETRIES=3 function make_block() { ((BLOCK_COUNTER++)) - RETRIES=0 - - while [ $RETRIES -lt $MAX_RETRIES ]; do - HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ - --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' \ - http://localhost:8545) - - # Extract block hash and proceed if it's valid - HEAD_BLOCK_HASH=$(echo $HEAD_BLOCK | jq --raw-output '.result.hash') - if [ "$HEAD_BLOCK_HASH" != "null" ]; then - echo "HEAD_BLOCK_HASH=$HEAD_BLOCK_HASH" - break - fi - - echo "Failed to get head block, retrying... ($RETRIES/$MAX_RETRIES)" - RETRIES=$((RETRIES + 1)) - sleep 2 - done - if [ $RETRIES -ge $MAX_RETRIES ]; then - echo "Failed to retrieve head block after $MAX_RETRIES attempts, exiting." - exit 1 - fi + HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ + --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' \ + http://localhost:8545) + + # --raw-output remove the double quotes + HEAD_BLOCK_HASH=$(echo $HEAD_BLOCK | jq --raw-output '.result.hash') + echo HEAD_BLOCK_HASH=$HEAD_BLOCK_HASH # The ASCII representation of `2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a` JWT_SECRET="********************************" @@ -177,7 +157,6 @@ N=5 for ((i = 1; i <= N; i++)); do echo "Making block $i" - sleep 2 make_block done From 6d0012cb51955b253f3df863d11a18ade6addfa8 Mon Sep 17 00:00:00 2001 From: debjit Date: Sun, 13 Oct 2024 12:40:39 +0530 Subject: [PATCH 12/20] first block --- scripts/generate_test_vectors.sh | 259 +++++++++++++++---------------- 1 file changed, 125 insertions(+), 134 deletions(-) diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index a789734..5e6a29b 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -15,148 +15,139 @@ DIR="$(dirname "$0")" OUT_DIR=$DIR/blocks mkdir -p $OUT_DIR - # Retry the curl command until it succeeds -# Function to check if Nethermind is available -check_nethermind_availability() { - until curl -X POST -H "Content-Type: application/json" \ - --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":1}' \ - http://localhost:8545; do +until curl -X POST -H "Content-Type: application/json" \ + --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":1}' \ + http://localhost:8545; do echo "Retrying..." sleep 2 - done - echo "Nethermind is available" - # return 0 -} - -# Wait for Nethermind to become available -while ! check_nethermind_availability; do - sleep 2 done BLOCK_COUNTER=0 -function make_block() { - ((BLOCK_COUNTER++)) - - HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ - --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' \ - http://localhost:8545) - - # --raw-output remove the double quotes - HEAD_BLOCK_HASH=$(echo $HEAD_BLOCK | jq --raw-output '.result.hash') - echo HEAD_BLOCK_HASH=$HEAD_BLOCK_HASH - - # The ASCII representation of `2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a` - JWT_SECRET="********************************" - # Generate a JWT token using the secret key - # jwt is this CLI tool https://github.com/mike-engel/jwt-cli/tree/main - # iat is appended automatically - JWT_TOKEN=$(jwt encode --alg HS256 --secret "$JWT_SECRET") - echo JWT_TOKEN: $JWT_TOKEN - - TIMESTAMP=$((1700000000 + BLOCK_COUNTER)) - - # Request to produce block on current head - - RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ - -H "Authorization: Bearer $JWT_TOKEN" \ - --data "{ - \"jsonrpc\":\"2.0\", - \"method\":\"engine_forkchoiceUpdatedV1\", - \"params\":[ - { - \"headBlockHash\": \"$HEAD_BLOCK_HASH\", - \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", - \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" - }, - { - \"timestamp\": $TIMESTAMP, - \"prevRandao\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", - \"suggestedFeeRecipient\": \"0x0000000000000000000000000000000000000000\" - } - ], - \"id\":1 - }" \ - http://localhost:8546 \ - ) - echo engine_forkchoiceUpdatedV1 trigger block production RESPONSE $RESPONSE - - PAYLOAD_ID=$(echo $RESPONSE | jq --raw-output '.result.payloadId') - echo PAYLOAD_ID=$PAYLOAD_ID - - # Fetch producing block by payload ID - - RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ - -H "Authorization: Bearer $JWT_TOKEN" \ - --data "{ - \"jsonrpc\":\"2.0\", - \"method\":\"engine_getPayloadV1\", - \"params\":[ - \"$PAYLOAD_ID\" - ], - \"id\":1 - }" \ - http://localhost:8546 \ - ) - echo engine_getPayloadV1 RESPONSE $RESPONSE - - BLOCK=$(echo $RESPONSE | jq '.result') - # BLOCK_NUMBER_HEX = 0x1, 0x2, etc - BLOCK_NUMBER_HEX_PREFIX=$(echo $BLOCK | jq --raw-output '.blockNumber') - BLOCK_NUMBER_HEX=${BLOCK_NUMBER_HEX_PREFIX#"0x"} - BLOCK_NUMBER=$((16#$BLOCK_NUMBER_HEX)) - BLOCK_HASH=$(echo $BLOCK | jq --raw-output '.blockHash') - - # persist the block as test-vector - - echo $BLOCK | jq '.' > $OUT_DIR/block_$BLOCK_NUMBER_HEX.json - - # send the new block as payload - - RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ - -H "Authorization: Bearer $JWT_TOKEN" \ - --data "{ - \"jsonrpc\":\"2.0\", - \"method\":\"engine_newPayloadV1\", - \"params\":[ - $BLOCK - ], - \"id\":1 - }" \ - http://localhost:8546 \ - ) - echo engine_newPayloadV1 with new block RESPONSE $RESPONSE - - - # set the block as head - - RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ - -H "Authorization: Bearer $JWT_TOKEN" \ - --data "{ - \"jsonrpc\":\"2.0\", - \"method\":\"engine_forkchoiceUpdatedV1\", - \"params\":[ - { - \"headBlockHash\": \"$BLOCK_HASH\", - \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", - \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" - }, - null - ], - \"id\":1 - }" \ - http://localhost:8546 \ - ) - echo engine_forkchoiceUpdatedV1 set new block as head RESPONSE $RESPONSE - -} +# function make_block() { + +# increment block counter +((BLOCK_COUNTER++)) + +HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ + --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' \ + http://localhost:8545) + +# --raw-output remove the double quotes +HEAD_BLOCK_HASH=$(echo $HEAD_BLOCK | jq --raw-output '.result.hash') +echo HEAD_BLOCK_HASH=$HEAD_BLOCK_HASH + +# The ASCII representation of `2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a` +JWT_SECRET="********************************" +# Generate a JWT token using the secret key +# jwt is this CLI tool https://github.com/mike-engel/jwt-cli/tree/main +# iat is appended automatically +JWT_TOKEN=$(jwt encode --alg HS256 --secret "$JWT_SECRET") +echo JWT_TOKEN: $JWT_TOKEN + +TIMESTAMP=$((1700000000 + BLOCK_COUNTER)) + +# Request to produce block on current head + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_forkchoiceUpdatedV1\", + \"params\":[ + { + \"headBlockHash\": \"$HEAD_BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + { + \"timestamp\": $TIMESTAMP, + \"prevRandao\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"suggestedFeeRecipient\": \"0x0000000000000000000000000000000000000000\" + } + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_forkchoiceUpdatedV1 trigger block production RESPONSE $RESPONSE + +PAYLOAD_ID=$(echo $RESPONSE | jq --raw-output '.result.payloadId') +echo PAYLOAD_ID=$PAYLOAD_ID + +# Fetch producing block by payload ID + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_getPayloadV1\", + \"params\":[ + \"$PAYLOAD_ID\" + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_getPayloadV1 RESPONSE $RESPONSE + +BLOCK=$(echo $RESPONSE | jq '.result') +# BLOCK_NUMBER_HEX = 0x1, 0x2, etc +BLOCK_NUMBER_HEX_PREFIX=$(echo $BLOCK | jq --raw-output '.blockNumber') +BLOCK_NUMBER_HEX=${BLOCK_NUMBER_HEX_PREFIX#"0x"} +BLOCK_NUMBER=$((16#$BLOCK_NUMBER_HEX)) +BLOCK_HASH=$(echo $BLOCK | jq --raw-output '.blockHash') + +# persist the block as test-vector + +echo $BLOCK | jq '.' > $OUT_DIR/block_$BLOCK_NUMBER_HEX.json + +# send the new block as payload + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_newPayloadV1\", + \"params\":[ + $BLOCK + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_newPayloadV1 with new block RESPONSE $RESPONSE + + +# set the block as head + +RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_forkchoiceUpdatedV1\", + \"params\":[ + { + \"headBlockHash\": \"$BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + null + ], + \"id\":1 + }" \ + http://localhost:8546 \ +) +echo engine_forkchoiceUpdatedV1 set new block as head RESPONSE $RESPONSE + +# } # Number of times to call make_block -N=5 +# N=5 -for ((i = 1; i <= N; i++)); do - echo "Making block $i" - make_block -done +# for ((i = 1; i <= N; i++)); do +# echo "Making block $i" +# make_block +# done From f6216533999e47e905a77761c593fbf57a745937 Mon Sep 17 00:00:00 2001 From: debjit Date: Sun, 13 Oct 2024 12:50:48 +0530 Subject: [PATCH 13/20] format --- scripts/generate_test_vectors.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index 5e6a29b..5588035 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -31,8 +31,17 @@ BLOCK_COUNTER=0 ((BLOCK_COUNTER++)) HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ - --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' \ - http://localhost:8545) + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"eth_getBlockByNumber\", + \"params\":[ + \"latest\", + false + ], + \"id\":1 + }" \ + http://localhost:8545 \ +) # --raw-output remove the double quotes HEAD_BLOCK_HASH=$(echo $HEAD_BLOCK | jq --raw-output '.result.hash') From 36e18df794b00ffaed31a08a118f302aedce28c4 Mon Sep 17 00:00:00 2001 From: debjit Date: Sun, 13 Oct 2024 12:57:34 +0530 Subject: [PATCH 14/20] fix --- scripts/generate_test_vectors.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index 5588035..ccab47b 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -23,6 +23,8 @@ until curl -X POST -H "Content-Type: application/json" \ sleep 2 done +echo "Nethermind is available" + BLOCK_COUNTER=0 # function make_block() { @@ -30,6 +32,8 @@ BLOCK_COUNTER=0 # increment block counter ((BLOCK_COUNTER++)) +echo "Making block $BLOCK_COUNTER" + HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ --data "{ \"jsonrpc\":\"2.0\", From d2439585e95efeb2be693a6407e01fa4bffee832 Mon Sep 17 00:00:00 2001 From: debjit Date: Sun, 13 Oct 2024 13:02:23 +0530 Subject: [PATCH 15/20] debug --- scripts/generate_test_vectors.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index ccab47b..76dc071 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -25,12 +25,12 @@ done echo "Nethermind is available" -BLOCK_COUNTER=0 +declare -i BLOCK_COUNTER=0 -# function make_block() { +function make_block() { # increment block counter -((BLOCK_COUNTER++)) +BLOCK_COUNTER=$((BLOCK_COUNTER + 1)) echo "Making block $BLOCK_COUNTER" @@ -154,13 +154,13 @@ RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ ) echo engine_forkchoiceUpdatedV1 set new block as head RESPONSE $RESPONSE -# } +} # Number of times to call make_block -# N=5 +N=5 -# for ((i = 1; i <= N; i++)); do -# echo "Making block $i" -# make_block -# done +for ((i = 1; i <= N; i++)); do + echo "Making block $i" + make_block +done From 44838b6a51e2c6c9424f6e1b878e2b353fe2b0f1 Mon Sep 17 00:00:00 2001 From: debjit Date: Sun, 13 Oct 2024 13:06:07 +0530 Subject: [PATCH 16/20] final changes --- .github/workflows/post-merge-run.yml | 4 +- scripts/generate_test_vectors.sh | 249 ++++++++++---------- scripts/generate_test_vectors_nethermind.sh | 17 -- 3 files changed, 126 insertions(+), 144 deletions(-) diff --git a/.github/workflows/post-merge-run.yml b/.github/workflows/post-merge-run.yml index de97c63..36c4d74 100644 --- a/.github/workflows/post-merge-run.yml +++ b/.github/workflows/post-merge-run.yml @@ -35,12 +35,12 @@ jobs: brew install docker-buildx - name: Test jq is installed run: jq --help + - name: Install jwt and add to path + run: cargo install jwt-cli && export PATH=$HOME/.cargo/bin:$PATH # Vectors are already generated, but this serves as a test - name: Generate vectors run: bash ./scripts/generate_test_vectors_nethermind.sh # Test vectors against nethermind - - name: Install jwt and add to path - run: cargo install jwt-cli && export PATH=$HOME/.cargo/bin:$PATH - name: Apply vectors to Nethermind run: bash ./scripts/apply_test_vectors_nethermind.sh # Test vectors against Reth diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index 76dc071..60b8084 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -29,131 +29,130 @@ declare -i BLOCK_COUNTER=0 function make_block() { -# increment block counter -BLOCK_COUNTER=$((BLOCK_COUNTER + 1)) - -echo "Making block $BLOCK_COUNTER" - -HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ - --data "{ - \"jsonrpc\":\"2.0\", - \"method\":\"eth_getBlockByNumber\", - \"params\":[ - \"latest\", - false - ], - \"id\":1 - }" \ - http://localhost:8545 \ -) - -# --raw-output remove the double quotes -HEAD_BLOCK_HASH=$(echo $HEAD_BLOCK | jq --raw-output '.result.hash') -echo HEAD_BLOCK_HASH=$HEAD_BLOCK_HASH - -# The ASCII representation of `2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a` -JWT_SECRET="********************************" -# Generate a JWT token using the secret key -# jwt is this CLI tool https://github.com/mike-engel/jwt-cli/tree/main -# iat is appended automatically -JWT_TOKEN=$(jwt encode --alg HS256 --secret "$JWT_SECRET") -echo JWT_TOKEN: $JWT_TOKEN - -TIMESTAMP=$((1700000000 + BLOCK_COUNTER)) - -# Request to produce block on current head - -RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ - -H "Authorization: Bearer $JWT_TOKEN" \ - --data "{ - \"jsonrpc\":\"2.0\", - \"method\":\"engine_forkchoiceUpdatedV1\", - \"params\":[ - { - \"headBlockHash\": \"$HEAD_BLOCK_HASH\", - \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", - \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" - }, - { - \"timestamp\": $TIMESTAMP, - \"prevRandao\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", - \"suggestedFeeRecipient\": \"0x0000000000000000000000000000000000000000\" - } - ], - \"id\":1 - }" \ - http://localhost:8546 \ -) -echo engine_forkchoiceUpdatedV1 trigger block production RESPONSE $RESPONSE - -PAYLOAD_ID=$(echo $RESPONSE | jq --raw-output '.result.payloadId') -echo PAYLOAD_ID=$PAYLOAD_ID - -# Fetch producing block by payload ID - -RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ - -H "Authorization: Bearer $JWT_TOKEN" \ - --data "{ - \"jsonrpc\":\"2.0\", - \"method\":\"engine_getPayloadV1\", - \"params\":[ - \"$PAYLOAD_ID\" - ], - \"id\":1 - }" \ - http://localhost:8546 \ -) -echo engine_getPayloadV1 RESPONSE $RESPONSE - -BLOCK=$(echo $RESPONSE | jq '.result') -# BLOCK_NUMBER_HEX = 0x1, 0x2, etc -BLOCK_NUMBER_HEX_PREFIX=$(echo $BLOCK | jq --raw-output '.blockNumber') -BLOCK_NUMBER_HEX=${BLOCK_NUMBER_HEX_PREFIX#"0x"} -BLOCK_NUMBER=$((16#$BLOCK_NUMBER_HEX)) -BLOCK_HASH=$(echo $BLOCK | jq --raw-output '.blockHash') - -# persist the block as test-vector - -echo $BLOCK | jq '.' > $OUT_DIR/block_$BLOCK_NUMBER_HEX.json - -# send the new block as payload - -RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ - -H "Authorization: Bearer $JWT_TOKEN" \ - --data "{ - \"jsonrpc\":\"2.0\", - \"method\":\"engine_newPayloadV1\", - \"params\":[ - $BLOCK - ], - \"id\":1 - }" \ - http://localhost:8546 \ -) -echo engine_newPayloadV1 with new block RESPONSE $RESPONSE - - -# set the block as head - -RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ - -H "Authorization: Bearer $JWT_TOKEN" \ - --data "{ - \"jsonrpc\":\"2.0\", - \"method\":\"engine_forkchoiceUpdatedV1\", - \"params\":[ - { - \"headBlockHash\": \"$BLOCK_HASH\", - \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", - \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" - }, - null - ], - \"id\":1 - }" \ - http://localhost:8546 \ -) -echo engine_forkchoiceUpdatedV1 set new block as head RESPONSE $RESPONSE - + # increment block counter + BLOCK_COUNTER=$((BLOCK_COUNTER + 1)) + + echo "Making block $BLOCK_COUNTER" + + HEAD_BLOCK=$(curl -X POST -H "Content-Type: application/json" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"eth_getBlockByNumber\", + \"params\":[ + \"latest\", + false + ], + \"id\":1 + }" \ + http://localhost:8545 \ + ) + + # --raw-output remove the double quotes + HEAD_BLOCK_HASH=$(echo $HEAD_BLOCK | jq --raw-output '.result.hash') + echo HEAD_BLOCK_HASH=$HEAD_BLOCK_HASH + + # The ASCII representation of `2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a` + JWT_SECRET="********************************" + # Generate a JWT token using the secret key + # jwt is this CLI tool https://github.com/mike-engel/jwt-cli/tree/main + # iat is appended automatically + JWT_TOKEN=$(jwt encode --alg HS256 --secret "$JWT_SECRET") + echo JWT_TOKEN: $JWT_TOKEN + + TIMESTAMP=$((1700000000 + BLOCK_COUNTER)) + + # Request to produce block on current head + + RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_forkchoiceUpdatedV1\", + \"params\":[ + { + \"headBlockHash\": \"$HEAD_BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + { + \"timestamp\": $TIMESTAMP, + \"prevRandao\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"suggestedFeeRecipient\": \"0x0000000000000000000000000000000000000000\" + } + ], + \"id\":1 + }" \ + http://localhost:8546 \ + ) + echo engine_forkchoiceUpdatedV1 trigger block production RESPONSE $RESPONSE + + PAYLOAD_ID=$(echo $RESPONSE | jq --raw-output '.result.payloadId') + echo PAYLOAD_ID=$PAYLOAD_ID + + # Fetch producing block by payload ID + + RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_getPayloadV1\", + \"params\":[ + \"$PAYLOAD_ID\" + ], + \"id\":1 + }" \ + http://localhost:8546 \ + ) + echo engine_getPayloadV1 RESPONSE $RESPONSE + + BLOCK=$(echo $RESPONSE | jq '.result') + # BLOCK_NUMBER_HEX = 0x1, 0x2, etc + BLOCK_NUMBER_HEX_PREFIX=$(echo $BLOCK | jq --raw-output '.blockNumber') + BLOCK_NUMBER_HEX=${BLOCK_NUMBER_HEX_PREFIX#"0x"} + BLOCK_NUMBER=$((16#$BLOCK_NUMBER_HEX)) + BLOCK_HASH=$(echo $BLOCK | jq --raw-output '.blockHash') + + # persist the block as test-vector + + echo $BLOCK | jq '.' > $OUT_DIR/block_$BLOCK_NUMBER_HEX.json + + # send the new block as payload + + RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_newPayloadV1\", + \"params\":[ + $BLOCK + ], + \"id\":1 + }" \ + http://localhost:8546 \ + ) + echo engine_newPayloadV1 with new block RESPONSE $RESPONSE + + + # set the block as head + + RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data "{ + \"jsonrpc\":\"2.0\", + \"method\":\"engine_forkchoiceUpdatedV1\", + \"params\":[ + { + \"headBlockHash\": \"$BLOCK_HASH\", + \"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", + \"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\" + }, + null + ], + \"id\":1 + }" \ + http://localhost:8546 \ + ) + echo engine_forkchoiceUpdatedV1 set new block as head RESPONSE $RESPONSE } # Number of times to call make_block diff --git a/scripts/generate_test_vectors_nethermind.sh b/scripts/generate_test_vectors_nethermind.sh index 67d2f69..496bccc 100755 --- a/scripts/generate_test_vectors_nethermind.sh +++ b/scripts/generate_test_vectors_nethermind.sh @@ -24,22 +24,5 @@ cleanup() { } trap cleanup EXIT -# Function to check if Nethermind is available -check_nethermind_availability() { - until curl -X POST -H "Content-Type: application/json" \ - --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":1}' \ - http://localhost:8545; do - echo "Retrying..." - sleep 2 - done - echo "Nethermind is available" - # return 0 -} - -# Wait for Nethermind to become available -while ! check_nethermind_availability; do - sleep 2 -done - # Generate test vectors $DIR/generate_test_vectors.sh \ No newline at end of file From c91580cd16ef373913d94cb537c53e019862cc78 Mon Sep 17 00:00:00 2001 From: debjit Date: Sun, 13 Oct 2024 13:13:46 +0530 Subject: [PATCH 17/20] bugfix --- scripts/apply_test_vectors.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/apply_test_vectors.sh b/scripts/apply_test_vectors.sh index 08ce197..2805b8c 100755 --- a/scripts/apply_test_vectors.sh +++ b/scripts/apply_test_vectors.sh @@ -68,9 +68,10 @@ function apply_block_file() { echo engine_forkchoiceUpdatedV1 set new block as head RESPONSE $RESPONSE PAYLOAD_STATUS=$(echo $RESPONSE | jq --raw-output '.result.payloadStatus.status') + echo PAYLOAD_STATUS: $PAYLOAD_STATUS # If the status is not "VALID", exit the script with a non-zero code to make CI fail if [ "$PAYLOAD_STATUS" != "VALID" ]; then - echo "Error: Payload status is $STATUS, failing CI." + echo "Error: Payload status is $PAYLOAD_STATUS, failing CI." exit 1 fi } From 6311a7d8370b09753c8cb7c5fca31c02a3a38681 Mon Sep 17 00:00:00 2001 From: debjit Date: Sun, 13 Oct 2024 13:15:52 +0530 Subject: [PATCH 18/20] cleanup --- .github/workflows/{test.yml.hold => test.yml} | 0 scripts/generate_test_vectors.sh | 1 - scripts/generate_test_vectors_nethermind.sh | 3 +-- 3 files changed, 1 insertion(+), 3 deletions(-) rename .github/workflows/{test.yml.hold => test.yml} (100%) diff --git a/.github/workflows/test.yml.hold b/.github/workflows/test.yml similarity index 100% rename from .github/workflows/test.yml.hold rename to .github/workflows/test.yml diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index 60b8084..92a2882 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -117,7 +117,6 @@ function make_block() { echo $BLOCK | jq '.' > $OUT_DIR/block_$BLOCK_NUMBER_HEX.json # send the new block as payload - RESPONSE=$(curl -X POST -H "Content-Type: application/json" \ -H "Authorization: Bearer $JWT_TOKEN" \ --data "{ diff --git a/scripts/generate_test_vectors_nethermind.sh b/scripts/generate_test_vectors_nethermind.sh index 496bccc..627f43f 100755 --- a/scripts/generate_test_vectors_nethermind.sh +++ b/scripts/generate_test_vectors_nethermind.sh @@ -24,5 +24,4 @@ cleanup() { } trap cleanup EXIT -# Generate test vectors -$DIR/generate_test_vectors.sh \ No newline at end of file +$DIR/generate_test_vectors.sh From 89ce491c7a6367962881b04d9582f4fcb6932351 Mon Sep 17 00:00:00 2001 From: debjit Date: Wed, 16 Oct 2024 20:10:45 +0530 Subject: [PATCH 19/20] revert to see --- scripts/generate_test_vectors.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index 92a2882..a83b4f2 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -25,12 +25,12 @@ done echo "Nethermind is available" -declare -i BLOCK_COUNTER=0 +BLOCK_COUNTER=0 function make_block() { # increment block counter - BLOCK_COUNTER=$((BLOCK_COUNTER + 1)) + ((BLOCK_COUNTER + 1)) echo "Making block $BLOCK_COUNTER" From e5ae4a522a68fbe21a0bbc9e19d60dfae745c9d7 Mon Sep 17 00:00:00 2001 From: debjit Date: Wed, 16 Oct 2024 20:13:48 +0530 Subject: [PATCH 20/20] . --- scripts/generate_test_vectors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_test_vectors.sh b/scripts/generate_test_vectors.sh index a83b4f2..372d9ea 100755 --- a/scripts/generate_test_vectors.sh +++ b/scripts/generate_test_vectors.sh @@ -30,7 +30,7 @@ BLOCK_COUNTER=0 function make_block() { # increment block counter - ((BLOCK_COUNTER + 1)) + ((BLOCK_COUNTER++)) echo "Making block $BLOCK_COUNTER"