最近看到一个把gas解释的不错的帖子,所以就翻译过来了。翻译辛苦,请勿转载。
I saw a good post explaining Gas recently, so I translated it. It's hard to translate. Please don't reprint it.
Gas是一种特别的单位用于Ethereum(以太坊)里,它用来衡量一个行为或者一系列行为有多少“工作量”,简单可以理解为是手续交易手续费的一种计量单位。
Gas is a special unit used in Etheeum (the Tai Chamber) to measure the “workload” of an act or a series of acts, which can simply be understood as a unit of measurement of transaction fees.
例如:
For example:
计算一个Keccak256加密哈希值,Ethereum平台上的交易或合同执行的每个操作都需要一定数量的gas,每次计算散列时将需要30个gas,加上每256位的6个gas的成本 数据被散列。与需要较少计算资源的操作相比,越多计算资源的操作需要更多的gas成本。
Calculates an encryption value of Kecak256, requires a certain amount of gas for each transaction or contract execution on the Etheum platform, and 30 gass for each hash, plus 6 gass for every 256-digit has been scattered. The greater the cost of calculating resource operations is the greater the need for less resource-based operations.
Gas确保一个交易支付了适当的费用给以太网络,它显得非常重要。 执行的每个操作(或合同执行)交易都要求支付其相应的费用,这样才能确保网络不会因为进行大量密集的工作而陷入僵局。
It is important that Gas ensure that a transaction pays an appropriate fee to the Ether network. Every transaction executed (or contract execution) requires that its corresponding costs be paid, in order to ensure that the network is not deadlocked by extensive and intensive work.
这是一个不同于比特币交易费用的策略,比特币交易费用仅基于交易的千字节大小。 由于Ethereum允许运行任意复杂的计算机代码,所以很短的代码实际上可以导致大量的计算工作正在完成。 因此,直接衡量工作非常重要,而不是仅仅根据交易或合同的长度选择费用。
This is a strategy that differs from the Bitcoin transaction cost, which is based only on the transaction’s 1,000-bit size. As Etherum allows for the operation of any complex computer code, a very short code can actually lead to a lot of computing being done.
那么如果gas基本上是一笔交易的手续费,那么该怎么支付呢?
So if Gas is basically a transaction fee, how should it be paid?
这里有个有个很难理解的地方,虽然gas是可以被衡量的单位,但gas没有任何实际的标记(token)。也就是说,你不能拥有1000个gas,gas只存在于Ethereum虚拟机的内部,作为执行多少工作的计算数量。关于gas的实际支付场景中,交易手续费以一定数量的ether 作为支付,Ethereum网络中的内置机制(token)中,矿工挖矿生成区块的奖励。
Here's a hard place to understand: while Gas is a measurable unit, Gas has no physical tag (token). That is, you can't have 1,000 gass, which is only inside the Etheeum virtual machine, as a calculation of the number of jobs to be performed. In the case of Gas, transaction fees are paid at a certain amount of each, and in the Token mechanism of the Etheeum network, miners create blocks.
初看这个会觉得有点奇怪。 为何不直接在以太网络中计算出手续费?
It's a little strange to look at this at first. Why don't you just calculate the fees in the Ether network?
答案是,以太网络,如比特币,拥有快速变化市场价格!但计算成本不会因为以太网络币价的变化而上涨或下降。 所以将计算的价格与以太币token的价格分开是有帮助的,每次币价市场走动时,操作的成本都不必改变。
The answer is that the Ethernet, like Bitcoin, has fast-changing market prices! But costing does not rise or fall because of changes in the price of the e-net.
这里的术语有点混乱。在EVM(以太网络虚拟机)的运行有gas消耗,但gas本身也拥有一个的gas的价格。 每个交易指定了gas价格(每一单位的gas价值多少ether),允许让市场来决定ether价格与计算操作成本之间的关系(以gas计量)。这是两者的组合,总gas数量乘以gas单位价格,这就是总交易所需要支付的费用。
There is some confusion about the terms here. The EVM operates with gas consumption, but gas itself has a gas price.
理解这个区别很重要,因为它会让最初学习者了解有关的Ethereum交易感到困惑:
Understanding this distinction is important because it confuses the initial learners with the relevant Etherum transaction:
“您的交易中出现的gas与您的交易之间存在差异,没有足够高的费用来支持交易(out of gas)”。
“There is a difference between the gas that appears in your transaction and your transaction, and there is not enough cost to support the transaction (out of gas)” .
如果我在交易中设置的gas价格太低,没有人会接纳我的交易作为优先运行。矿工基本不会愿意将你的交易打包进区块里。如果我提供了一个大家可接受的gas价格,然而我的交易产生如此多的计算工作,gas的成本费用超过了我附加的费用,这个gas是已“花费”了得,没有办法收回。矿工将停止处理交易,还原这个交易所做的任何更改,但仍将其作为“交易失败”包含在块中,收取费用你支付的费用。
If I set the gas price in the deal too low, no one would accept my deal as a priority. Miners would hardly be willing to package your deal into a block. If I provided an acceptable gas price, but my deal produced so much calculation, the cost of Gas was more than I would charge, and the gas was already “costed” and could not be recovered. The miners would stop processing the transaction, repossess any changes made to the transaction, but they would still include it as a “trade failure” in the block, charge you a fee.
这可能看起来很苛刻,但是当您意识到矿工的真正工作正在执行计算时,您可以看到他们将永远不会获得这些资源。所以只有你支付了费用,他们做了他们应做的任务这样才会是公平的,尽管是你的设计不当,导致没有支付足够的gas。
This may seem harsh, but when you realize that the real work of the miners is being calculated, you can see that they will never have access to these resources. So it is fair that they do what they are supposed to do only if you pay for it, even if it is not your design that results in not paying enough gas.
提供太高的费用也不同于提供太多的ether。 如果你设定了非常高的gas价格,您所需要只是简单几个操作,就为其支付大量的ether,就像在比特币中设置一个超高的交易费用一样。 你的任务一定会在最优先考虑队列前,但是你的钱已经被支付了。
If you set a very high gas price, all you need is a few simple operations, paying a lot for each of them, just like setting a super-high transaction cost in bitcoin. Your mission must be at the top of the list, but your money has already been paid.
但是,如果您提供正常的gas价格,并且只要附加的ether比您交易消耗的gas所需的更多,那么以太网络将会把超额费用将退还给您。 矿工只收取你们实际工作的费用。您可以将gas价格视为矿工的小时工资,gas成本作为工作时间。
However, if you provide a normal gas price, and if you attach more than the gas that you consume from your transaction, then you will be refunded the excess fee on the Ethernet.
有很多其他的gas的细节,但目前我们还是解释最基础的。gas是使Ethereum网络的复杂计算“网络安全”的关键机制,因为任何失去控制的程序只会工作持续到最后请求他们的任务执行。 当钱停止支付时,矿工们将会停止工作。
There are a lot of other gas details, but we still have the most basic explanation. Gas is the key mechanism for making Etheum’s complex calculation of “cyber security” because any loss of control only lasts until they are finally asked to do their job.
你设计的程序中犯的错误,只会影响付费使用它的人。其余的网络不能因为你的错误而遭受性能问题。 当性能问题消耗你的所有ether币时,他们将简单地得到一个 big payday! 没有这个关键技术,通用块链的想法是完全不可能的。
The mistakes you design only affect those who pay for them. The rest of the network cannot suffer performance problems because of your mistakes. When performance problems consume all of your money, they simply get a big payday! Without this key technology, the idea of a universal chain is completely impossible.
简单而言:
gas是计算费用的方式。
不过,这些费用仍然是以ether计算,这与gas不同。
gas成本是工作量,如劳动时数,而gas价格就像您为完成工作付出的小时工资。 两者的组合决定了您的总交易费用。
如果您的gas价格太低,没有人会处理您的交易。
如果您的gas价格不错,但交易的gas成本超过预算,交易失败,但仍然被打包进区块,劳动者工作了,您不会获得退款。
这样确保没有任何东西永远运行,而且人们会对他们运行的代码注意一点。 它使矿工和用户都能安全避免错误的代码!
Simple:
gas is the way to calculate costs.
These costs, however, are still calculated in each other, which is different from Gas.
gas costs are workloads, such as hours of work, while gas prices are just like the hourly wage you pay to do your job.
The combination of the two determines your total transaction costs.
If your gas prices are too low, no one will handle your transaction.
If your gas costs are good, but the transaction costs exceed the budget, the transaction fails, but they are packed into blocks and the workers work, you won't get refunds.
(翻译辛苦,请勿转载此译文。)
如果觉得对您有帮助,请给我打赏点币儿吧。
BTC地址:19hexJYkSBpqDmG4phGmE9Q7CK5SRxE4r9
ETH地址:0xa9b6344371588c3911e5172d52f114b3b5377536
Please do not reproduce this translation if you find it helpful.
BTC address: 19hexJykSpqDmG4phGmE9Q7CK5SRxE4r9
ETH address: 0xa9b6344371588c3911e5172d52f114b3b5377536
原文来自:
https://ethereum.stackexchange.com/questions/3/what-is-meant-by-the-term-gas/62#62
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论