# Explanation of Geth's Command Line option: targetgaslimit?

I have been trying to figure out what the targetgaslimit parameter does exactly for Geth, in the context of Private Blockchains.

I have seen the following explanation but it never helped me: "Target gas limit sets the artificial target gas floor for the blocks to mine (default: 4712388)".

Could someone provide another explanation please? I've searched but couldn't find any good ones online?

Disclaimer: I'm assuming an understanding of what gas is.

The gas limit is the maximum amount of gas that could be spent during an Ethereum transaction. This number is not fixed--early on in the Ethereum days, the gas limit was much lower than it is today.

There is a calculation that Ethereum nodes do to adjust the gas limit after each transaction, based on the usage in the current block. Per the documentation in the code: https://github.com/ethereum/go-ethereum/blob/e29c2e43640445e743bb69ab48d6c862d3e964d9/core/block_validator.go#L108

    strategy: gasLimit of block-to-mine is set based on parent's
gasUsed value.  if parentGasUsed > parentGasLimit * (2/3) then we
increase it, otherwise lower it (or leave it unchanged if it's right
at that usage) the amount increased/decreased depends on how far away
from parentGasLimit * (2/3) parentGasUsed is.


While this technically answers your question, it still leaves open the question of why: the gas limit is there to protect the network from scripts running rampant. The way it does this is look a the current usage and call use that as a baseline.

In private blockchains, you aren't exposed to as much risk (presumably you know of all the actors in your network) and you might not necessarily have a baseline. Additionally, you may want to have a much larger gas limit than the value you'd get by calculating based on current use. This flag allows you to do so.

targetgaslimit is the gas limit for each block. For example, if you set it to 8,000,000 (the current value on the mainnet right now), a miner would be able to accept as many transactions as they can whose total gasLimit sums to <= 8,000,000.

Miners have the ability to adjust this value over time depending on the state of the network. For example, Vitalik suggested to miners to run --targetgaslimit 2000000 during a period last year due to spam attacks (raising the targetgaslimit would have likely allowed more legitimate transactions through).

Be wary when using this though, as Péter Szilágyi points out here, "the limit can only change with a certain amoutn between blocks. If the change is larger, the block is not accepted." You may run into issues such as this that are hard to debug on your private chain.