What is the function of Gas Limit parameter in Ethereum? Is it involved in mining or something else?
-
Related: ethereum.stackexchange.com/questions/8572/… and bitcoin.stackexchange.com/questions/41503/…– ethCommented Sep 8, 2016 at 2:16
-
4I'm voting to close this question as off-topic because it is not bitcoin related and would be better covered on the ethereum stackexchange– G. MaxwellCommented Jan 26, 2019 at 20:16
-
I'm voting to leave this question open. While this question does belong in the ethereum stack exchange now, it is too old to migrate. Additionally it was on topic at the time of asking as, AFAICT, the ethereum stack exchange did not exist yet.– Ava Chow ♦Commented Jan 29, 2019 at 4:32
2 Answers
In Ethereum, gas is a measure of computational effort. To each operation, a fixed amount of gas is assigned (e.g. adding two numbers costs 3 gas, calculating a hash costs 30 gas, sending a transaction costs 21000 gas [1]).
Since computation is expensive (mind that it has to be done by every full node in the network), excessive consumption of gas needs to be discouraged. Therefore, each unit of gas must be paid for (in Ether) by the sender of the transaction that triggered the computation.
Unfortunately, it is often not easy and in general even impossible to know in advance how much gas a transaction will need eventually. Therefore, transactions have a gas limit field to specify the maximum amount of gas the sender is willing to buy. If the gas used exceeds this limit during execution, processing is stopped. The sender still has to pay for the performed computation, but they are protected from running completely out of funds.
The transaction gas limit also protects full nodes from attackers, who could, without a gas limit, make them execute effective infinity loops. If such a transaction would take longer than one block to process, it could never be included in a block, and, thus, the attacker wouldn't need to pay for it. [2]
Additionally, blocks, too, have a field called gas limit. It defines the maximum amount of gas all transactions in the whole block combined are allowed to consume. Similar to the maximum block size in Bitcoin (measured in bytes), its purpose is to keep block propagation and processing time low, thereby allowing for a sufficiently decentralized network. In contrast to Bitcoin, it is however not a constant. Instead, miners have the option to increase or decrease it every block by a certain factor. [3]
- [1] See the Yellow Paper for a breakdown of operations and the respective gas costs (Appendices G and H)
- [2] https://github.com/ethereum/wiki/wiki/Design-Rationale#gas-and-fees
- [3] See the Yellow Paper Equations 40 to 42 for the exact rules
-
1
-
Computation is very cheap, regardless of how many nodes are in the network. The computations that occur on Ethereum would still cost an aggregate of pennies over all nodes. What's expensive is time spent not mining the block. A block hits every 15 seconds, so if a miner wastes 5 seconds computing someone's function, he now has 5 fewer seconds to guess the correct nonce. The price of the rest of nodes computing the answer to catch up with the blockchain is irrelevant, since they're forced to do that anyway. Commented Nov 18, 2018 at 1:54
The current gas limit can be checked on the network stats page.
It's currently 3,141,592 (pi million). The gas limit per block is not fixed, though. The number of contract calls and standard transactions is limited by the gas limit, which is 1.2x of the exponential moving average. So there's only so much gas that can be expended per block, even though it can grow, of course.
Note that each call to the contract to the caller cost an amount of Ether defined by (gas sent to contract)*(price of gas as defined by caller)
so sending 10 thousend transactions per block could end up quite a pricey endeavour.