hyperledger / besu

An enterprise-grade Java-based, Apache 2.0 licensed Ethereum client https://wiki.hyperledger.org/display/besu
https://www.hyperledger.org/projects/besu
Apache License 2.0
1.52k stars 839 forks source link

Besu increases `gasLimit` when no `--target-gas-limit` is specified #7614

Open phearnot opened 2 months ago

phearnot commented 2 months ago

I'm attempting to limit gas usage in a private network, but Besu seems not to honor gasLimit from genesis config, and instead increases gas limit up to the value configured for sepolia (0x1c9c380). However, the docs for the --target-gas-limit command line option state that

If a value for target-gas-limit is not specified, the block gas limit remains at the value specified in the genesis file.

Steps to reproduce

I'm using the following genesis.json:

{
  "alloc": {},
  "baseFeePerGas": "0x3b9aca00",
  "blobGasUsed": null,
  "coinbase": "0x0000000000000000000000000000000000000000",
  "config": {
    "arrowGlacierBlock": 0,
    "berlinBlock": 0,
    "byzantiumBlock": 0,
    "cancunTime": 0,
    "chainId": 88817,
    "constantinopleBlock": 0,
    "daoForkBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "ethash": {},
    "grayGlacierBlock": 0,
    "homesteadBlock": 0,
    "istanbulBlock": 0,
    "londonBlock": 0,
    "muirGlacierBlock": 0,
    "petersburgBlock": 0,
    "shanghaiTime": 0,
    "terminalTotalDifficulty": 0,
    "terminalTotalDifficultyPassed": true
  },
  "difficulty": "0x0",
  "excessBlobGas": null,
  "extraData": "0x",
  "gasLimit": "0x1000000",
  "gasUsed": "0x0",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "nonce": "0x0",
  "number": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp": "0x660e5e00"
}

I'm starting the docker container with besu 24.8.0:

docker run -v ./genesis-testnet.json:/etc/genesis.json --rm -p 8551:8551 hyperledger/besu:latest --genesis-file=/etc/genesis.json --engine-rpc-enabled --engine-jwt-disabled --engine-host-allowlist='*' --target-gas-limit=16777216

Then I attempt to manually forge the new block:

❯ curl -sd '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":54}'  0:8551 | jq '.result|{hash, gasLimit}'
{
  "hash": "0x697ebb1c00a66913ac23d12b68b71f33e3184c4782fd08084e6d89afd3561d69",
  "gasLimit": "0x1000000"
}

❯ curl -sd '{
  "jsonrpc":"2.0","method":"engine_forkchoiceUpdatedV3","params":[{
  "headBlockHash":"0x697ebb1c00a66913ac23d12b68b71f33e3184c4782fd08084e6d89afd3561d69",
  "safeBlockHash":"0x697ebb1c00a66913ac23d12b68b71f33e3184c4782fd08084e6d89afd3561d69",
  "finalizedBlockHash":"0x697ebb1c00a66913ac23d12b68b71f33e3184c4782fd08084e6d89afd3561d69"
  },{
  "timestamp":"0x66e412d8",
  "prevRandao":"0x1c5f0544ea78e1127df6e8bf1dfbbf32665a16a475c8f77b4463327594825747",
  "suggestedFeeRecipient":"0x6c7d59240748b02d93d70586a99834bd94d0bddb",
  "withdrawals":[],
  "parentBeaconBlockRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"}],"id":1
}'  0:8551 | jq '.result.payloadId'
"0x7172362e07312627"

❯ curl -sd '{"jsonrpc":"2.0","method":"engine_getPayloadV3","params":["0x7172362e07312627"],"id":1}' 0:8551 | jq .result.executionPayload.gasLimit
"0x1003fff"

Note that gas limit has increased from 0x1000000 in genesis to 0x1003fff. Now I add --target-gas-limit=16777216 to the command line and retry:

❯ curl -sd '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":54}'  0:8551 | jq '.result|{hash, gasLimit}'
{
  "hash": "0x697ebb1c00a66913ac23d12b68b71f33e3184c4782fd08084e6d89afd3561d69",
  "gasLimit": "0x1000000"
}
❯ curl -sd '{
  "jsonrpc":"2.0","method":"engine_forkchoiceUpdatedV3","params":[{
  "headBlockHash":"0x697ebb1c00a66913ac23d12b68b71f33e3184c4782fd08084e6d89afd3561d69",
  "safeBlockHash":"0x697ebb1c00a66913ac23d12b68b71f33e3184c4782fd08084e6d89afd3561d69",
  "finalizedBlockHash":"0x697ebb1c00a66913ac23d12b68b71f33e3184c4782fd08084e6d89afd3561d69"
  },{
  "timestamp":"0x66e412ff",
  "prevRandao":"0x1c5f0544ea78e1127df6e8bf1dfbbf32665a16a475c8f77b4463327594825747",
  "suggestedFeeRecipient":"0x6c7d59240748b02d93d70586a99834bd94d0bddb",
  "withdrawals":[],
  "parentBeaconBlockRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"}],"id":1
}'  0:8551 | jq '.result.payloadId'
"0x7172362e07312602"
❯ curl -sd '{"jsonrpc":"2.0","method":"engine_getPayloadV3","params":["0x7172362e07312602"],"id":1}' 0:8551 | jq .result.executionPayload.gasLimit
"0x1000000"

I expect besu to keep gasLimit when no --target-gas-limit is set, but for some reason it does not work as expected.

macfarla commented 1 month ago

I have reproduced the same behaviour as you. The gasLimit in the header increases when target-gas-limit is absent from the cmd line. Next step is to find in the code where this calculation is done.

macfarla commented 1 month ago

unassigning myself as I'm not actively looking at this right now.

actioncoininc commented 1 month ago

*