关于区块大小:Gas 上限与可扩展性

币圈资讯 阅读:42 2024-04-22 09:50:36 评论:0
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

作者:Toni Wahrstätter

最近关于提高以太坊区块 Gas 上限的讨论非常多。有些人基于摩尔定律主张增大区块大小,有些人基于个人直觉,有些人则只是在随意散布消息,还有些人担心其他链如 Solana 会在用户广泛采用方面超越以太坊。

接下来,我想展示一些图表和数据,这可能有助于我们做出一个在不影响以太坊去中心化的前提下最大化 Gas 上限的决策。

从最初讲起

与比特币不同,以太坊没有固定的区块大小限制,而是依赖于一种灵活的区块大小机制,这种机制由某种单位 "gas" 来衡量。在以太坊中,Gas 是一个衡量执行操作(如交易或智能合约)所需计算量的单位。以太坊中的每项操作都需要一定数量的 Gas 来完成,每个区块都有一个 Gas 上限,这决定了一个区块可以包含多少操作。

最开始,2015 年时以太坊每个区块有 5000 Gas 的上限制。这个上限很快被提高到约 300 万,然后在 2016年稍后 提高到约 470 万。随着 Tangerine Whistle 硬分叉 (EIP-150) 在 2016年 的实施,作为对 DoS 攻击的回应,通过重新定价各种 IO 密集型操作码,Gas 上限被提高到 550 万。在这些攻击之后,矿工持续提高 Gas 上限,在 2017 年 7 月 到约 670 万,2017 年 12 月 到约 800 万,2019 年 9 月 到约 1000 万,2020 年 8 月 到 1250 万,最终在 2021 年 4 月 3 日 到约 1500 万。

随时间变化的 Gas 使用情况

此后,随着 Spurious Dragon、Byzantium、Constantinople、Istanbul 和 Berlin 硬分叉的激活,某些操作码的定价进一步得到了细化。这些细化的例子包括 EIP-145、EIP-160、EIP-1052、EIP-1108、EIP-1884、EIP-2028、EIP-2200、EIP-2565 和 EIP-2929。

以太坊费用市场最重大的变化发生在 2021 年 8 月的伦敦硬分叉 (EIP-1559) 的引入。EIP-1559 引入了 base fee,该费用会根据对区块空间的需求随时间/区块高度动态调整。同时引入了 "target size",将其设定为每个区块 1500 万 Gas。这个 target 用于指导 base fee 的动态调整。如果一个区块中使用的总 Gas 数量超过这个 target,那么下一个区块的 base fee 就会增加。相反,如果使用的总 Gas 数量低于 target,则 base fee 减少。这个机制旨在创建一个更可预测的费用市场,并通过稳定交易开销改善用户体验。此外,EIP-1559 还引入了 base fee 的销毁机制,永久地从流通量中移除了那部分 Ether。这增强了协议的可持续性,同时创造了所谓的超稳健货币迷因 (ultra sound money meme)。

在 EIP-1559 下,还设有一个最大(或“硬上限”)Gas 上限,设为 target 的两倍,即 3000 万 Gas。这意味着一个区块可以打包总使用量高达 3000 万 Gas 的交易。

伦敦分叉后的 Gas 使用情况

自那时起,以太坊的区块 Gas 上限保持不变,截至 2024 年,仍然是每个区块 3000 万 Gas。

我们准备好增加区块大小了吗?

最近,一些人对以太坊的 Gas 上限表示担忧,并要求将其增加。在 Reddit 上的最新以太坊基金会 AMA 中,Vitalik 表示考虑了将 Gas 上限增加 33% 至 4000 万的想法。他的推理基于摩尔定律,该定律指出微芯片上的晶体管数量大约每两年翻一番,从而使得计算能力相应增加。这一原则表明,网络性能,包括处理和执行交易的能力,也可以随时间增加。

来自以太坊基金会的研究人员 Dankrad 和 Ansgar 也支持在评估 Dencun 升级后的情况后增加 Gas 上限的想法。此外,以太坊基金会的 Pari 发表了一篇帖子,探索潜在的 Gas 上限增加途径。像 Geth 的 Peter 和 Marius 这样的其他人则对增加 Gas 上限表示担忧,特别是在没有适当的工具/监控到位的情况下。这些担忧主要和这些问题相关:加速状态增长、同步时间和重组块率。

区块大小是什么?

区块的大小可以通过两种方式衡量:

Gas 使用量

区块大小(以字节为单位)

虽然这两种衡量方式相关联,但必须独立考虑。

例如,一个包含许多非零 calldata 字节的区块在字节大小上可能很大,而实际的 Gas 使用量 (每非零字节需要 16 Gas) 可能仍然相对较小。

先不考虑压缩后的情况,在遵守 Geth 每笔交易 128 KB 限制的前提下,当前可以达到的最大区块大小约为 6.88 MB。这样一个的区块里将最大化打包 128 KB 交易的数量。实际计算出来的结果是,包含约 130,900 字节的零字节 calldata(每字节 4 Gas)的 55 笔交易,以及一个填满剩余空间的交易。然而,经过 snappy 压缩后,这样的区块最终大小约为 0.32 MB,这可以忽略不计。

而另一种情况,考虑最大可能性的区块大小,包含 15 笔携带非零字节 calldata 的交易,压缩后大小可达约 1.77 MB。

因此,截至今日,1.77 MB 代表执行层区块的真实区块大小上限。

译者注:

在上面的几个段落中,作者在固定 gas 上限 30 M 的情况下,想要让 block size 最大,尝试计算最多可以把区块塞到多大。

如果固定 gas 上限,要让 block size 变大,那么只能塞 calldata(因为计算/STORE之类的字节码其实是不会消耗区块存储空间的)。

所以,要让区块变大,无非就是尽量往交易塞 calldata。然后,有“塞 0 calldata” 和 “塞非 0 calldata” 两种方法,需要计算才能知道哪种能让 block size 更大。最终结果是“塞非 0 calldata” 的 block size 更大。

基于 Geth 客户端限制每笔交易最多 128 KB 这一前提,下面开始计算两个例子。

case 1: 56 个大小为 130,900 B (< 128 KB) 的交易(里面都是零 calldata,4 gas/B):用的 gas = 56* (130,900 * 4+21000) = 30497600 > (30 M),所以最多只能塞 55 个上述交易+ 1 个小于上述交易的交易。对应的区块大小约为 55*128 = 7040 kB = 6.875 MB。然而,由于 calldata 全是 0,所以压缩后区块大小约为 0.32 MB。

case 2: 15 个大小为 130,900 B (< 128 KB) 的交易(里面都是非零 calldata,16 gas/B):用的 gas = 15 *(130900 *16+21000) = 31731000 > 30 M。对应的区块大小约为 14 *128 = 1792 kB = 1.75 MB ~ 15 * 128 = 1.875 M。然而,由于 calldata 是非零,不好压缩,所以压缩后区块大小约为 1.77 MB。)

就这个最大区块大小而言,我们可以识别出几个影响它的因素:

Gas 上限:Gas 上限会影响最大区块大小,这是毋庸置疑的。上限越高,区块中可以塞进的数据就越多。

操作和数据的定价:操作的 gas 越便宜,区块内就能执行越多次操作。虽然像 CALLDATALOAD 或 CALLDATACOPY 这样的操作,它们的开销都是 3 Gas,相对便宜;但其他操作码如 CREATE 则更昂贵。区块中使用的操作码越昂贵,该区块中用于 calldata(或其他操作)的空间就越少。

客户端限制:虽然客户端限制的影响不那么明显,但比如像 Geth 客户端这样对每笔交易的 128 kb 限制也可以影响最终区块大小。由于每笔交易的固定费用是 21k Gas,客户端每笔交易的大小限制越低,就需要更频繁地支付固定费用,从而“浪费”本可以用于 calldata 的 gas。所以最终,这个限制可以导致最大区块大小减少约 0.07 MB。需要注意的是,客户端限制只影响交易的广播,并不影响已经被确认的区块。

首先,让我们看看每个区块的 Gas 上限:

区块 Gas 上限对最大区块大小的影响

像以太坊这样的区块链,提高区块 Gas 上限是最直接和明显的扩容方式。更高的上限意味着更多的数据空间。然而,这也意味着需要每个运行全节点的人传播和下载更大的区块。如上图所示,“最坏情况(即前面通过计算得出的最大区块大小)”下的区块大小与区块 Gas 上限的增加大致呈线性关系。通过创建塞满尽可能多的非零字节 calldata 交易的区块,就可以达到这样的最大区块大小。

接下来,让我们看看另一个影响因素 —— 以太坊的定价机制。在当前的例子中,具体就是目前被设定为 16 Gas 的非零字节 calldata 的开销:

每非零字节 Calldata 开销对最大区块大小的影响

如上图所示,增加非零 calldata 的开销会让区块大小减小。换句话说,将开销降低到比如说每字节 8 Gas,会使最坏情况下的区块大小翻倍。这很直观,因为降低价格允许将双倍数量的数据放入区块中。

那么 EIP-4844 (Proto-Danksharding)上线后呢?

我不会在这里详细介绍 4844,因为 eip4844.com 上有很好的文档,但简单来说,EIP-4844 引入了类似“sidecar (挎斗)”结构的数据类型,叫做 blob,每个 blob 可塞进约 125 kb 的数据。Blob 数据费用机制与 EIP-1559 类似,也存在一个“target”,用于锚定 blob 数量。在 Dencun 硬分叉中,target 设为每个区块 3 个 blob,最大限制设为每个区块 6 个 blob。值得注意的是,blob 拥有自己的费用市场,创建了所谓的多维费用市场。这意味着 blob 不必与标准交易竞争,而是与 EIP-1559 机制下的费用解耦。

到目前为止,一切顺利。让我们看看这次升级如何影响以太坊的平均区块大小。

新增 blob 之后对压缩后的信标链平均区块大小的影响

截至今日,采用 snappy 压缩后的信标链区块的平均区块大小约为 125 KB。有了 4844,我们每个区块再增加 375 KB,从而使当前平均区块大小增加 4 倍。如果达到最大数量的 blob,我们实质上将当前区块大小增加了七倍。

最坏情况下的区块大小从约 1.77 MB 增加到约 2.5 MB。这个估算没有将区块的 CL (共识层) 部分考虑在内。但不管怎样,在遭受 DoS 攻击的情况下,我们必须做好应对这种最大区块大小的准备。

总结

最终,如果要提高当前的区块 Gas 上限,我们需要在实施前进行彻底的研究和分析。虽然像 Coinbase、Binance、Kraken 或 Lido 节点运营商这样的成熟的实体能够应对超过 4000 万的区块 Gas 上限的情况,但独立质押者可能会比较困难。

因此,这样的决策必须经过深思熟虑,以确保我们不会牺牲去中心化。

最后,构建一个像 Facebook 那样容量大、性能强的东西相对容易,但重要的是不能失去我们大多数人所追求的东西:去中心化。


Recently, the author has discussed a lot about increasing the upper limit of the Ethereum block. Some people advocate increasing the block size based on Moore's Law, some people are just spreading news at will, and some people are worried that other chains will surpass Ethereum in terms of users' wide adoption. Next, I want to show some charts and data, which may help us make a decision to maximize the upper limit without affecting the decentralization of Ethereum. From the beginning, Ethereum is different from Bitcoin. Fixed block size limit depends on a flexible block size mechanism, which is measured by a certain unit. In Ethereum, it is a unit to measure the amount of calculation needed to perform operations such as transactions or smart contracts. Every operation in Ethereum needs a certain amount to complete, and each block has an upper limit, which determines how many operations can be contained in a block. At the beginning of the year, the upper limit of each block in Ethereum was quickly raised to about 10,000, and then it was raised to about 10,000 later in the year. With the implementation of the hard fork in 2000, as a response to the attack, the upper limit of various intensive operation codes was raised to 10,000 by repricing. After these attacks, miners continued to raise the upper limit from October to about 10,000 to about 10,000, and finally from October to about 10,000. After that, with the activation of the hard fork, the pricing of some operation codes was further refined. Examples of these refinements include Lun, the most important change in the expense market of Ethereum, which occurred in June. The introduction of hard bifurcation introduces that the cost will be dynamically adjusted with time according to the demand for block space, and it is also introduced as a dynamic adjustment for guidance. If the total quantity used in one block exceeds this, the next block will increase. On the contrary, if the total quantity used is lower, it will decrease. This mechanism aims to create a more predictable cost market and improve the user experience by stabilizing transaction expenses. In addition, it also introduces a destruction mechanism forever. That part has been removed from the circulation for a long time, which enhances the sustainability of the agreement and creates the so-called ultra-stable currency meme. There is also a maximum or hard upper limit, which is set to twice the upper limit of 10,000, which means that a block can package transactions with a total usage of up to 10,000. Since then, the upper limit of Ethereum has remained unchanged, and it is still 10,000 per block by the end of the year. Are we ready to increase the block size? Recently, some people have expressed concern about the upper limit of Ethereum and want to. In the latest Ethereum Foundation in the world, he said that he considered the idea of increasing the upper limit to 10,000. His reasoning is based on Moore's Law, which points out that the number of transistors on microchips doubles every two years, thus increasing the computing power accordingly. This principle shows that network performance, including the ability to handle and execute transactions, can also be increased over time. Researchers from Ethereum Foundation also support the idea of increasing the upper limit after evaluating the upgraded situation. In addition, the development of Ethereum Foundation Other people are worried about increasing the upper limit, especially in the absence of proper monitoring tools. These concerns are mainly related to these problems, such as accelerating state growth synchronization time and reorganization block rate. What is the block size? The usage of the block size can be measured in two ways, in bytes. Although these two measures are related, for example, a block containing many non-zero bytes must be considered independently. Blocks may be large in byte size, but the actual usage per non-zero byte may still be relatively small. Regardless of the situation after compression, the maximum block size that can be achieved at present is about such a block under the premise of observing the limit of each transaction. The actual calculation result is a transaction with zero bytes per byte and a transaction that fills the remaining space. However, after compression, the final size of such a block is about this negligible. On the other hand, considering the maximum possible block size, the transaction size including pen carrying non-zero bytes can reach about after compression, so up to now, it represents the real block size upper limit of the execution layer block. Getting bigger is nothing more than trying to plug the transaction, and then there are two methods, plug and plug, which need to be calculated to know which can make it bigger. The final result is that the plug is bigger. Based on the premise that the client limits each transaction to the maximum, the following two examples will be calculated. The transactions with a size of are petty, so at most only one of the above transactions can be plugged, and the corresponding block size is about. However, because of all of them, the compressed block size is about one, and the transactions with a size of are non-petty. The corresponding block size is about, however, because non-zero is not easy to compress, the compressed block size is about. As far as this maximum block size is concerned, we can identify several factors that affect it. There is no doubt that the upper limit will affect the maximum block size. The higher the upper limit, the more operations can be packed in the block, and the cheaper the data pricing operation, the more operations can be performed in the block. Although operations like or this are relatively cheap, other operation codes are more expensive. The more expensive the opcode used in a block, the less space there is for other operations in the block. Although the impact of client restrictions is not so obvious, the restrictions on each transaction like the client can also affect the final block size. Because the fixed fee for each transaction is that the lower the size limit of each transaction, the client needs to pay the fixed fee more frequently, thus wasting what could have been used. Therefore, this restriction can eventually lead to the reduction of the maximum block size. The purpose is that client restrictions only affect the broadcast of transactions, but not the confirmed blocks. First, let's look at the influence of the upper limit of each block on the maximum block size. It is the most direct and obvious way to increase the upper limit of a block chain like Ethereum. A higher upper limit means more data space. However, it also means that everyone running the whole node needs to spread and download larger blocks. As shown in the figure above, the worst case is that the block size under the maximum block size calculated above is roughly linear with the increase of the upper limit of the block. By creating a block that is filled with as many non-zero bytes as possible. 比特币今日价格行情网_okx交易所app_永续合约_比特币怎么买卖交易_虚拟币交易所平台

文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明 网址:https://netpsp.com/?id=60857

美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
关注我们

若遇到问题,加微信客服---清歌

搜索
排行榜
扫一扫,加我为微信好友加我为微信好友