官术网_书友最值得收藏!

Ethereum gas

An Ethereum transaction can call a smart contract, which can, in turn, call another smart contract and then another, and so on. Thus, an improperly written smart contract may lead to circular calls and result in infinite loops. Stopping a smart contract infinite loop is almost impossible, since thousands of nodes worldwide run the same looping code. To stop the infinite loop, all running nodes need to be shut down within a short time window. Even if one node fails to comply, the infinite loop is still alive. When other nodes are back to the network, the running infinite loop is brought back to these nodes as well. It is a logistical nightmare to coordinate and shut down all nodes worldwide at approximately the same time.

To resolve this issue, the concept of gas was introduced. A vehicle relies on an engine, which depends on gas for energy. If an engine runs out of gas, the vehicle stops. When a transaction is submitted, a requester is required to provide the max gas amount. Each execution step of a smart contract uses a certain amount of gas. An infinite-looping smart contract will eventually lead to the maximum gas amount being used up, and a node will no longer execute the contract. Another advantage of using gas is that it makes hacking prohibitively expensive and, therefore, deters hacking activities.

Gas is a metering unit for measuring consumption just like a kilowatt is the unit for measuring electricity usage. Suppose in a month a family uses 210 KW. Before sending a bill to the family, the utility company first converts 210 KW into US dollars based on a predefined conversion rate. Suppose a unit of KW costs $0.20 USD; the total charge for the month is 0.2 × 210 = $42 USD.

Similarly, gas usage is converted into ether for being charged to a requestor. Ethereum allows a requester to specify the conversion rate when the transaction is submitted. A validator (Ethereum's equivalent to the miner for bitcoin) has the option of giving a preference to transactions with higher rates. If a requester does not specify a rate, EVM uses a default rate, which varies. For example, in 2016, the rate for 1 gas was 0.00001 ETH. In 2018, 1 gas was 0.00000002 ETH.

主站蜘蛛池模板: 梁平县| 阳东县| 崇文区| 子长县| 郯城县| 耒阳市| 武威市| 徐汇区| 宾阳县| 景泰县| 齐河县| 九龙城区| 富阳市| 建德市| 靖江市| 沁源县| 黑河市| 佛坪县| 泸水县| 三门峡市| 兴宁市| 商都县| 锦州市| 呼伦贝尔市| 枣阳市| 新昌县| 拜城县| 佛山市| 兰溪市| 浙江省| 江川县| 治多县| 乌兰浩特市| 五指山市| 饶阳县| 仙居县| 孝昌县| 资中县| 府谷县| 钦州市| 淅川县|