An Observation About The Bitcoin Block Size Debate

https://eklitzke.org/an-observation-about-the-bitcoin-block-size-debate

An Observation About The Bitcoin Block Size Debate

An Observation About The Bitcoin Block Size Debate

关于比特币区块大小争论的观察

Dec 22, 2017

I recently started working on a Bitcoin client so I could learn more about Bitcoin internals and the P2P protocol. I’ve written some C++ code that can connect to the Bitcoin P2P network and do basic things like syncing block headers. It’s been a lot of fun, and I’ve learned a lot from the experience.

我最近开始开发一个比特币的客户端,所以我可以了解关于比特币内部,和P2P协议更多的信息。我写过一些c++代码,可以连接比特币P2P网络,做些基本的事情,比如同版本区块头。这很有趣,我从这次经历中学到了很多。

One of the things that I learned as a result of this project is exactly how blocks are mined and organized. Bitcoin uses a proof-of-work system to mine new blocks, which is implemented by repeatedly computing SHA-256 hashes. The way I always assumed mining worked is that miners repeatedly vary some fields in a block like the nonce and then hash the block. They do this over and over again until they find a block whose hash is lower than the difficulty target. Since Bitcoin blocks are currently about 1 MB in size, I always assumed that this proof-of-work function requires hashing 1 MB of data. I’ve since learned that this is dead wrong.

我从这个项目从学得到的事情之一就是区块是如何开采和组织的。比特币使用了一个工作证明系统去挖掘新块,这是通过反复SHA-256 hash方式计算去实现的。我一直认为挖掘工作的方式是反复改变块中字段,比如说nonce,然后hash这个块。他们一遍又一遍的这样做,直到找到hash值低于难度目标的块,比特币目前的大小是1MB,直到我一直假定这个函数需要hash1MB的数据,我才意识到这是错的。

Miners don’t hash blocks, they hash block headers. A block header is an 80-byte message that contains metadata about a block (which I covered briefly in a recent post). Since miners are hashing block headers rather than the blocks themselves, the amount of time it takes to do the proof-of-work hash for a block is independent of the number of transactions in the block. Miners are always hashing 80 bytes of data, regardless of the actual size of the underlying block.

矿工们不去hash区块,他们hash 区块的头部,一个区块的头是长度是80字节的消息,包含了区块的元数据(我在最近的一篇文章中简要介绍过),自从旷工开始hashing区块头部而不是区块本身,他们为区块去执行工作量证明的hash花费时间与区块传输的数量无关。矿工总会hashing 80字节的数据,无论底层区块的大小是多少。

Technically miners do have to hash the full block data to generate a Merkle root, which is part of the block header. This means that at some point in time, a miner really does need to hash all of the data in a block. But let’s examine this closer. The nonce field in a block header is 32 bits, so there’s four billion possible variations of a given Merkle root and timestamp just via the nonce field. Timestamps in block headers are allowed to have some skew: you can be approximately two hours off from true time. If you take full advantage of this, just between the timestamp and the nonce there are trillions of possible hashes per Merkle root. The Bitcoin difficulty target is high enough that trillions of hashes is rarely sufficient to find a block, so miners periodically update the block’s coinbase transaction to generate a new Merkle root. You might think that this operation at least would require rehashing the full block, but that’s also not true! A Merkle tree is a binary tree of hashes, where the value for each interior node in the tree is the hash of its children. This means that if one of the leaves in an NN element Merkle tree is updated, the new Merkle root can be recomputed in O(log2N)O(log2⁡N) hashing operations. Any way you cut it, miners only have to do a full hash over the block data once per block, which is only about every ten minutes.

从技术上来说,矿工必须hash完整的区块数据用以生成Merkle的根,是属于区块头部的一部分,这就意味着在某个时间点,一个矿工确实需要Hash一个区块中是所有数据。但是我们仔细研究一下,这个nonce字段是32位的,那么仅通过nonce字段,给定的merkle根和时间戳就有40亿种可能的变化,区块头中的时间戳允许有一些偏差:你可以离实际时间大约两个小时,如果你充分利用这一点,在时间戳和nonce之间每个merkle根可能有数亿万个哈希值,比特币的难度目标很高,数万亿的hash们很少能找到一个区块。因此矿工们定期更新该块的coinbase事务,以生存一个新的merkle根。你可能认为这个操作至少需要重新清洗整个街区,但是这不是真的,一个merkle树,是一个hash的二叉树,树中的每一个每部节点的值都是其子节点的hash.这就意味着如果更新一个NN元素Merkle树种的一个叶子节点,就可以在O(Log2n)O(Log2×n)的hash操作中重新计算。不管你怎么切割它,矿工们只需要去对每个区块数据进行一次完整的hash,大约没十分钟一次。

My point is that miners are insensitive to block size because it doesn’t really affect them. Bitcoin could switch to gigabyte blocks, and it would have almost no impact on miners. On the other hand, block size very much impacts everyone else. Bigger blocks mean a bigger blockchain, and that deters users from running full nodes. The block size even impacts users running pruned nodes, as it affects the amount of data involved in the initial blockchain sync, as well as the amount of data transferred over the P2P network when new blocks are announced. The block size debate is a complex and nuanced issue. I see how increasing the block size would be an effective short term fix to Bitcoin scaling and transaction fees. But I also see how large blocks might ultimately make running full nodes too onerous for hobbyists, and how this will lead to increased centralization. There’s no easy answer here, and I can understand both points of view on the matter. But I hope that others evaluating the issue are at least aware of why miners have an incentive to push for bigger blocks: it increases the amount of Bitcoin they collect from transaction fees at almost no cost to them.

我的观点是矿工对区块大小不敏感,因为这并不会真正的影响到他们。比特币可能转换成千兆字节块。对矿工们几乎没有影响,在另一方面,区块大小对其他影响很大。更大的区块意味着更大的区块链,这会阻止用户运行完整的节点。这个区块大小甚至会影响运行修剪节点的用户,因为她影响初始区块链同步所涉及的数据量,以及在宣布新块时通过p2p网络传输的数据量,区块规模的争论是一个复杂并且微妙的问题。我知道增加块的大小将是比特币规模和交易费用的短期有效的解决方案,但是我也看到了对于爱好者来说,大型的区块可能会使运行完整的节点变的过于繁重,以及这将会如何导致更大的集中化。因为这里没有简易的答案。我可以理解这两种观点。但是我希望其他苹果这一问题的人至少需要知道为什么矿工有动力推动更大的区块:这会增加他们从交易费用中收取的比特币的数量。而且几乎不会让他们付出任何代价。

发布了88 篇原创文章 · 获赞 33 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/ccmedu/article/details/101075117