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

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.

主站蜘蛛池模板: 天台县| 嵊州市| 鞍山市| 叶城县| 甘谷县| 济阳县| 昭通市| 沽源县| 门头沟区| 松滋市| 巴青县| 桃园市| 永济市| 顺昌县| 琼结县| 天柱县| 曲水县| 东阿县| 菏泽市| 榆社县| 舞钢市| 乐平市| 黄石市| 都匀市| 蕲春县| 察哈| 辰溪县| 沁水县| 建瓯市| 唐河县| 法库县| 镇康县| 靖宇县| 慈利县| 平果县| 韶山市| 磐安县| 兴宁市| 新和县| 阳江市| 延川县|