Skip to content

Commit

Permalink
Can gen 5 blocks without transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Aug 2, 2024
1 parent 794271d commit 60f62bd
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 8 deletions.
16 changes: 16 additions & 0 deletions block_0x1.json
Original file line number Diff line number Diff line change
@@ -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": []
}
16 changes: 16 additions & 0 deletions block_0x2.json
Original file line number Diff line number Diff line change
@@ -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": []
}
16 changes: 16 additions & 0 deletions block_0x3.json
Original file line number Diff line number Diff line change
@@ -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": []
}
16 changes: 16 additions & 0 deletions block_0x4.json
Original file line number Diff line number Diff line change
@@ -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": []
}
16 changes: 16 additions & 0 deletions block_0x5.json
Original file line number Diff line number Diff line change
@@ -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": []
}
75 changes: 67 additions & 8 deletions generate_test_vectors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ 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 \
--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 &
Expand All @@ -34,14 +34,18 @@ until curl -X POST -H "Content-Type: application/json" \
sleep 2
done

BLOCK_COUNTER=0

function make_block() {
GENESIS_BLOCK=$(curl -X POST -H "Content-Type: application/json" \
((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
GENESIS_HASH=$(echo $GENESIS_BLOCK | jq --raw-output '.result.hash')
echo GENESIS_HASH=$GENESIS_HASH
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="********************************"
Expand All @@ -53,6 +57,8 @@ function make_block() {

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" \
Expand All @@ -62,12 +68,12 @@ function make_block() {
\"method\":\"engine_forkchoiceUpdatedV1\",
\"params\":[
{
\"headBlockHash\": \"$GENESIS_HASH\",
\"headBlockHash\": \"$HEAD_BLOCK_HASH\",
\"safeBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\",
\"finalizedBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\"
},
{
\"timestamp\": 1700000000,
\"timestamp\": $TIMESTAMP,
\"prevRandao\": \"0x0000000000000000000000000000000000000000000000000000000000000000\",
\"suggestedFeeRecipient\": \"0x0000000000000000000000000000000000000000\"
}
Expand All @@ -76,7 +82,7 @@ function make_block() {
}" \
http://localhost:8546 \
)
echo engine_forkchoiceUpdatedV1 RESPONSE $RESPONSE
echo engine_forkchoiceUpdatedV1 trigger block production RESPONSE $RESPONSE

PAYLOAD_ID=$(echo $RESPONSE | jq --raw-output '.result.payloadId')
echo PAYLOAD_ID=$PAYLOAD_ID
Expand All @@ -96,9 +102,62 @@ function make_block() {
http://localhost:8546 \
)
echo engine_getPayloadV1 RESPONSE $RESPONSE

BLOCK=$(echo $RESPONSE | jq '.result')
# BLOCK_NUMBER_HEX = 0x1, 0x2, etc
BLOCK_NUMBER_HEX=$(echo $BLOCK | jq --raw-output '.blockNumber')
BLOCK_HASH=$(echo $BLOCK | jq --raw-output '.blockHash')

# persist the block as test-vector

echo $BLOCK | jq '.' > 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

}

make_block
# 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
Expand Down

0 comments on commit 60f62bd

Please sign in to comment.