From 2b1aeef71b29a34860635782fa73a6514d2384f1 Mon Sep 17 00:00:00 2001 From: Lion - dapplion <35266934+dapplion@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:35:07 +0200 Subject: [PATCH] Post-merge test vectors from Nethermind to Reth (#8) * Can gen 0x1 block * function and latest * Can gen 5 blocks without transactions * Run apply test vectors * Run on reth * unschedule shangai * Add CI step * jq * Fix blockRewardsContract address --- .github/workflows/post-merge-run.yml | 48 ++++++++++ Cargo.lock | 1 + Cargo.toml | 1 + apply_test_vectors.sh | 73 ++++++++++++++ apply_test_vectors_nethermind.sh | 8 ++ apply_test_vectors_reth.sh | 7 ++ blocks/block_1.json | 16 ++++ blocks/block_2.json | 16 ++++ blocks/block_3.json | 16 ++++ blocks/block_4.json | 16 ++++ blocks/block_5.json | 16 ++++ chiado_genesis_alloc.json | 7 +- generate_test_vectors.sh | 138 ++++++++++++++++++++++++++- make_block.sh | 19 ++++ networkdata/chainspec.json | 6 -- networkdata/jwtsecret | 2 +- poll_genesis.sh | 10 ++ run_nethermind.sh | 27 ++++++ src/consensus.rs | 15 ++- src/execute.rs | 28 +++--- src/gnosis.rs | 13 ++- src/lib.rs | 13 +-- 22 files changed, 455 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/post-merge-run.yml create mode 100755 apply_test_vectors.sh create mode 100755 apply_test_vectors_nethermind.sh create mode 100755 apply_test_vectors_reth.sh create mode 100644 blocks/block_1.json create mode 100644 blocks/block_2.json create mode 100644 blocks/block_3.json create mode 100644 blocks/block_4.json create mode 100644 blocks/block_5.json create mode 100755 make_block.sh create mode 100755 poll_genesis.sh create mode 100755 run_nethermind.sh diff --git a/.github/workflows/post-merge-run.yml b/.github/workflows/post-merge-run.yml new file mode 100644 index 0000000..97da2d1 --- /dev/null +++ b/.github/workflows/post-merge-run.yml @@ -0,0 +1,48 @@ +name: Test + +on: + pull_request: + push: + branches: + - master + +env: + REQWEST_TEST_BODY_FULL: 1 + RUST_BACKTRACE: 1 + +jobs: + post-merge-run: + name: Test post merge run + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Install rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust || 'stable' }} + targets: ${{ matrix.target }} + - name: Setup docker (missing on MacOS) + if: runner.os == 'macos' + run: | + brew install docker + brew install docker-buildx + - name: Test jq is installed + run: jq --help + # Vectors are already generated, but this serves as a test + - name: Generate vectors + run: ./generate_test_vectors.sh + # Test vectors against nethermind + - name: Apply vectors to Nethermind + run: ./apply_test_vectors_nethermind.sh + # Test vectors against Reth + - name: Apply vectors to Reth + run: ./apply_test_vectors_reth.sh + + diff --git a/Cargo.lock b/Cargo.lock index 89d814b..17f09a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6966,6 +6966,7 @@ dependencies = [ "alloy-sol-types", "clap", "eyre", + "hex", "libc", "reth", "reth-auto-seal-consensus", diff --git a/Cargo.toml b/Cargo.toml index e263d63..ad725f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ alloy-sol-types = "0.7.6" revm = "11.0.0" revm-primitives = "6.0.0" serde_json = "1.0.117" +hex = "0.4.3" [target.'cfg(unix)'.dependencies] tikv-jemallocator = { version = "0.5.0", optional = true } diff --git a/apply_test_vectors.sh b/apply_test_vectors.sh new file mode 100755 index 0000000..99ec2df --- /dev/null +++ b/apply_test_vectors.sh @@ -0,0 +1,73 @@ +#!/bin/bash +set -e + +# Expects reth to be running on the background + +OUT_DIR=./blocks + +N=5 + +# 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 + echo "Retrying..." + sleep 2 +done + + +function apply_block_file() { + BLOCK_FILEPATH=$1 + BLOCK=$(<$BLOCK_FILEPATH) + echo Applying $BLOCK + + # 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 + + 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 + + BLOCK_HASH=$(echo $BLOCK | jq --raw-output '.blockHash') + + 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 +} + + +for ((i = 1; i <= N; i++)); do + BLOCK_FILEPATH=$OUT_DIR/block_$i.json + apply_block_file $BLOCK_FILEPATH +done + diff --git a/apply_test_vectors_nethermind.sh b/apply_test_vectors_nethermind.sh new file mode 100755 index 0000000..82d4841 --- /dev/null +++ b/apply_test_vectors_nethermind.sh @@ -0,0 +1,8 @@ +#!/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 new file mode 100755 index 0000000..1a44521 --- /dev/null +++ b/apply_test_vectors_reth.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e + +./run_reth.sh & +./apply_test_vectors.sh + + diff --git a/blocks/block_1.json b/blocks/block_1.json new file mode 100644 index 0000000..1d9aff2 --- /dev/null +++ b/blocks/block_1.json @@ -0,0 +1,16 @@ +{ + "baseFeePerGas": "0x342770c0", + "blockHash": "0xc0f683b61355455d49af3dbb11fe1f65e9ae8670890d6fb1aadcbf5f8acc960b", + "blockNumber": "0x1", + "extraData": "0x4e65746865726d696e64", + "feeRecipient": "0x0000000000000000000000000000000000000000", + "gasLimit": "0x989680", + "gasUsed": "0x0", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "parentHash": "0xa7931c99fd2b7b5e323a2fda8a2dd607cea04f03835c3f29bfe7c057c8b5672e", + "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot": "0xa59f6ea19d9ee6d7e79bcb286e6d8838b47b48351b37960e24c0a72d41fa1629", + "timestamp": "0x6553f101", + "transactions": [] +} diff --git a/blocks/block_2.json b/blocks/block_2.json new file mode 100644 index 0000000..13829d0 --- /dev/null +++ b/blocks/block_2.json @@ -0,0 +1,16 @@ +{ + "baseFeePerGas": "0x2da282a8", + "blockHash": "0xc314b27368528ec560d035ef9f5dc46e2aea6d21b618eeb37e91723fefdfb2d9", + "blockNumber": "0x2", + "extraData": "0x4e65746865726d696e64", + "feeRecipient": "0x0000000000000000000000000000000000000000", + "gasLimit": "0x989680", + "gasUsed": "0x0", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "parentHash": "0xc0f683b61355455d49af3dbb11fe1f65e9ae8670890d6fb1aadcbf5f8acc960b", + "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot": "0xa59f6ea19d9ee6d7e79bcb286e6d8838b47b48351b37960e24c0a72d41fa1629", + "timestamp": "0x6553f102", + "transactions": [] +} diff --git a/blocks/block_3.json b/blocks/block_3.json new file mode 100644 index 0000000..bb45fcc --- /dev/null +++ b/blocks/block_3.json @@ -0,0 +1,16 @@ +{ + "baseFeePerGas": "0x27ee3253", + "blockHash": "0xd51a4d79676ddad8e938c38ec1344a77feefa369475acb358563f37a74a4d9d6", + "blockNumber": "0x3", + "extraData": "0x4e65746865726d696e64", + "feeRecipient": "0x0000000000000000000000000000000000000000", + "gasLimit": "0x989680", + "gasUsed": "0x0", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "parentHash": "0xc314b27368528ec560d035ef9f5dc46e2aea6d21b618eeb37e91723fefdfb2d9", + "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot": "0xa59f6ea19d9ee6d7e79bcb286e6d8838b47b48351b37960e24c0a72d41fa1629", + "timestamp": "0x6553f103", + "transactions": [] +} diff --git a/blocks/block_4.json b/blocks/block_4.json new file mode 100644 index 0000000..61d8deb --- /dev/null +++ b/blocks/block_4.json @@ -0,0 +1,16 @@ +{ + "baseFeePerGas": "0x22f06c09", + "blockHash": "0x011405450b1431877c952c73d0ea0c964c67d006b3134aea5be7a59823e40e39", + "blockNumber": "0x4", + "extraData": "0x4e65746865726d696e64", + "feeRecipient": "0x0000000000000000000000000000000000000000", + "gasLimit": "0x989680", + "gasUsed": "0x0", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "parentHash": "0xd51a4d79676ddad8e938c38ec1344a77feefa369475acb358563f37a74a4d9d6", + "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot": "0xa59f6ea19d9ee6d7e79bcb286e6d8838b47b48351b37960e24c0a72d41fa1629", + "timestamp": "0x6553f104", + "transactions": [] +} diff --git a/blocks/block_5.json b/blocks/block_5.json new file mode 100644 index 0000000..26df740 --- /dev/null +++ b/blocks/block_5.json @@ -0,0 +1,16 @@ +{ + "baseFeePerGas": "0x1e925e88", + "blockHash": "0x9a86f6d4d524388c300b8a09a145d0406fcf13d343ef8574c46fc0ffad9a45a0", + "blockNumber": "0x5", + "extraData": "0x4e65746865726d696e64", + "feeRecipient": "0x0000000000000000000000000000000000000000", + "gasLimit": "0x989680", + "gasUsed": "0x0", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "parentHash": "0x011405450b1431877c952c73d0ea0c964c67d006b3134aea5be7a59823e40e39", + "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot": "0xa59f6ea19d9ee6d7e79bcb286e6d8838b47b48351b37960e24c0a72d41fa1629", + "timestamp": "0x6553f105", + "transactions": [] +} diff --git a/chiado_genesis_alloc.json b/chiado_genesis_alloc.json index c221a1c..58926b7 100644 --- a/chiado_genesis_alloc.json +++ b/chiado_genesis_alloc.json @@ -16,12 +16,13 @@ }, "terminalTotalDifficulty": 0, "terminalTotalDifficultyPassed": true, - "shanghaiTime": 1704401480, - "cancunTime": 1704403000, + "shanghaiTime": 9999999999, + "cancunTime": 9999999999, "minBlobGasPrice": 1000000000, "maxBlobGasPerBlock": 262144, "targetBlobGasPerBlock": 131072, "blobGasPriceUpdateFraction": 1112826, + "blockRewardsContract": "0x2000000000000000000000000000000000000001", "aura": { "stepDuration": 5, "blockReward": 0, @@ -416,4 +417,4 @@ "code": "" } } -} \ No newline at end of file +} diff --git a/generate_test_vectors.sh b/generate_test_vectors.sh index ab75bd1..475f10f 100755 --- a/generate_test_vectors.sh +++ b/generate_test_vectors.sh @@ -1,4 +1,16 @@ #!/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.sh +# ``` + +OUT_DIR=./blocks +mkdir -p $OUT_DIR # Clean up existing container if it exists docker rm -f neth-vec-gen 2>/dev/null @@ -12,7 +24,6 @@ docker run --name neth-vec-gen --rm -d \ --config=none \ --Init.ChainSpecPath=/networkdata/chainspec.json \ --Init.DiscoveryEnabled=false \ - --Init.ExitOnBlockNumber=1 \ --JsonRpc.Enabled=true \ --JsonRpc.Host=0.0.0.0 \ --JsonRpc.Port=8545 \ @@ -20,6 +31,7 @@ docker run --name neth-vec-gen --rm -d \ --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 & @@ -32,6 +44,130 @@ until curl -X POST -H "Content-Type: application/json" \ 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 + +} + +# Number of times to call make_block +N=5 + +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/make_block.sh b/make_block.sh new file mode 100755 index 0000000..9f57f13 --- /dev/null +++ b/make_block.sh @@ -0,0 +1,19 @@ +#!/bin/bash +## Exit immediately if any command exits with a non-zero status +set -e + + +# 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 + +curl -X POST -H "Content-Type: application/json" \ + -H "Authorization: Bearer $JWT_TOKEN" \ + --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":1}' \ + http://localhost:8546 diff --git a/networkdata/chainspec.json b/networkdata/chainspec.json index ed97b6e..95eafc5 100644 --- a/networkdata/chainspec.json +++ b/networkdata/chainspec.json @@ -78,12 +78,6 @@ "eip6780TransitionTimestamp": "0x65971a48" }, "genesis": { - "seal": { - "authorityRound": { - "step": "0x0", - "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - } - }, "baseFeePerGas": "0x3b9aca00", "difficulty": "0x01", "gasLimit": "0x989680" diff --git a/networkdata/jwtsecret b/networkdata/jwtsecret index ff1f4a3..34c2cd8 100644 --- a/networkdata/jwtsecret +++ b/networkdata/jwtsecret @@ -1 +1 @@ -0xbb7c674f43e83596a7299422339c7a104113ce86731c8e632ce8aabf2d5d2926 +2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a diff --git a/poll_genesis.sh b/poll_genesis.sh new file mode 100755 index 0000000..39011dc --- /dev/null +++ b/poll_genesis.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# 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 + echo "Retrying..." + sleep 2 +done + diff --git a/run_nethermind.sh b/run_nethermind.sh new file mode 100755 index 0000000..215e821 --- /dev/null +++ b/run_nethermind.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -e + +# Script to run Nethermind dockerized and attach to it. +# The jwtsecret is hardcoded, do not modify it. + +# 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 \ + -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 \ + diff --git a/src/consensus.rs b/src/consensus.rs index 4fc7f64..b55509b 100644 --- a/src/consensus.rs +++ b/src/consensus.rs @@ -19,7 +19,8 @@ impl GnosisBeaconConsensus { // `validate_header`, `validate_header_against_parent`, `validate_header_with_total_difficulty`, `validate_block_pre_execution`, `validate_block_post_execution` impl Consensus for GnosisBeaconConsensus { fn validate_header(&self, _header: &SealedHeader) -> Result<(), ConsensusError> { - todo!(); + // TODO + Ok(()) } fn validate_header_against_parent( @@ -27,7 +28,8 @@ impl Consensus for GnosisBeaconConsensus { _header: &SealedHeader, _parent: &SealedHeader, ) -> Result<(), ConsensusError> { - todo!(); + // TODO + Ok(()) } fn validate_header_with_total_difficulty( @@ -35,11 +37,13 @@ impl Consensus for GnosisBeaconConsensus { _header: &Header, _total_difficulty: U256, ) -> Result<(), ConsensusError> { - todo!(); + // TODO + Ok(()) } fn validate_block_pre_execution(&self, _block: &SealedBlock) -> Result<(), ConsensusError> { - todo!(); + // TODO + Ok(()) } fn validate_block_post_execution( @@ -47,6 +51,7 @@ impl Consensus for GnosisBeaconConsensus { _block: &BlockWithSenders, _input: PostExecutionInput<'_>, ) -> Result<(), ConsensusError> { - todo!(); + // TODO + Ok(()) } } diff --git a/src/execute.rs b/src/execute.rs index d2602a4..0ecb725 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -226,23 +226,21 @@ where let chain_spec = self.chain_spec_clone(); - { - let env = self.evm_env_for_block(&block.header, total_difficulty); - let mut evm = self.executor.evm_config.evm_with_env(&mut self.state, env); - - apply_withdrawals_contract_call( - &chain_spec, - block.timestamp, - block - .withdrawals - .as_ref() - .ok_or(BlockExecutionError::Other( - "block has no withdrawals field".to_owned().into(), - ))?, - &mut evm, - )?; + if chain_spec.is_shanghai_active_at_timestamp(block.timestamp) { + if let Some(withdrawals) = block.withdrawals.as_ref() { + let env = self.evm_env_for_block(&block.header, total_difficulty); + let mut evm = self.executor.evm_config.evm_with_env(&mut self.state, env); + + apply_withdrawals_contract_call( + &chain_spec, + block.timestamp, + withdrawals, + &mut evm, + )?; + } } + // TODO: Only post merge? let balance_increments: HashMap
= { let env = self.evm_env_for_block(&block.header, total_difficulty); let mut evm = self.executor.evm_config.evm_with_env(&mut self.state, env); diff --git a/src/gnosis.rs b/src/gnosis.rs index 6023db0..0d68b3b 100644 --- a/src/gnosis.rs +++ b/src/gnosis.rs @@ -135,7 +135,7 @@ where Err(e) => { evm.context.evm.env = previous_env; return Err(BlockExecutionError::Other( - format!("withdrawal contract system call error: {}", e).into(), + format!("block rewards contract system call error: {}", e).into(), )); } }; @@ -148,19 +148,24 @@ where }, ExecutionResult::Revert { output, .. } => { return Err(BlockExecutionError::Other( - format!("withdrawal contract system call revert {}", output).into(), + format!("block rewards contract system call revert {}", output).into(), )); } ExecutionResult::Halt { reason, .. } => { return Err(BlockExecutionError::Other( - format!("withdrawal contract system call halt {:?}", reason).into(), + format!("block rewards contract system call halt {:?}", reason).into(), )); } }; let result = rewardCall::abi_decode_returns(output_bytes.as_ref(), true).map_err(|e| { BlockExecutionError::Other( - format!("error parsing withdrawal contract system call return {}", e).into(), + format!( + "error parsing block rewards contract system call return {:?}: {}", + hex::encode(output_bytes), + e + ) + .into(), ) })?; diff --git a/src/lib.rs b/src/lib.rs index 0878f40..79d9082 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,10 @@ use reth::{ }, }; use reth_node_ethereum::{ - node::{EthereumNetworkBuilder, EthereumPayloadBuilder, EthereumPoolBuilder}, + node::{ + EthereumConsensusBuilder, EthereumNetworkBuilder, EthereumPayloadBuilder, + EthereumPoolBuilder, + }, EthEngineTypes, EthereumNode, }; use std::sync::Arc; @@ -51,14 +54,12 @@ impl GnosisNode { EthereumPayloadBuilder, EthereumNetworkBuilder, GnosisExecutorBuilder, - GnosisConsensusBuilder, + EthereumConsensusBuilder, > where Node: FullNodeTypes