比特币挖矿原理_比特币挖矿的真正工作原理

比特币挖矿原理

by Subhan Nadeem

由Subhan Nadeem

比特币挖矿的真正工作原理 (How Bitcoin mining really works)

As Bitcoin approaches mainstream adoption and recognition, its fundamental security model, characterized as mining, is being put under the spotlight and scrutinized more and more everyday.

随着比特币接近主流采用和认可,其基础安全模型(即挖矿)正日益受到关注,并且每天都在受到越来越多的审查。

People are increasingly concerned about and interested in the environmental impact of Bitcoin mining, the security and degree of decentralization of the underlying model, and even the potential impact of a quantum computing breakthrough on the future of Bitcoin and other cryptocurrencies.

人们越来越关注比特币采矿对环境的影响,底层模型的安全性和分散程度,甚至对量子计算突破对比特币和其他加密货币的未来的潜在影响,都越来越感兴趣。

Often times, proof-of-work is described as a “cryptographic puzzle,” but what is that puzzle, really?

通常,工作量证明被描述为“密码难题”,但那实际上是什么难题?

In order to truly understand these questions (and any possible answers), you need to have a fundamental understanding Bitcoin mining itself and its evolution.

为了真正理解这些问题(以及任何可能的答案),您需要对比特币开采本身及其发展有一个基本的了解。

This article will explore all the technical components and moving parts of proof-of-work, and how they seamlessly synchronize with one another to allow Bitcoin to be the decentralized platform it is today.

本文将探讨工作量证明的所有技术组成部分和移动部分,以及它们如何无缝同步以使比特币成为当今的去中心化平台。

为何采矿:加密单向散列 (Why Mining Works: Cryptographic One-Way Hashing)

The Bitcoin blockchain is often described as a database that is cryptographically secure and, subsequently, immutable. The underlying technology that powers this immutability and security is cryptographic hashing.

比特币区块链通常被描述为密码安全的数据库,随后是不可变的。 支持这种不变性和安全性的基础技术是加密哈希。

A cryptographic hash function is a mathematical function that, simply put, takes any input and maps it to a fixed-size string.

简单来说,加密哈希函数是一种数学函数,它接受任何输入并将其映射到固定大小的字符串。

However, there are four special properties of these functions that make them invaluable to the Bitcoin network. They are:

但是,这些功能具有四个特殊属性,这使得它们对于比特币网络而言是无价之宝。 他们是:

  1. Deterministic — for any input into the cryptographic hash function, the resulting output will always be the same.

    确定性-对于密码哈希函数的任何输入,结果输出将始终相同。

  2. Fast — Computing the output of the hash function, given any input, is a relatively fast process (doesn’t need heavy computation)

    快速 -在给定任何输入的情况下,计算哈希函数的输出是一个相对较快的过程(不需要大量计算)

  3. Unique — Every input into the function should result in a completely random and unique output (in other words, no two inputs result in the same output)

    唯一-函数的每个输入都应产生完全随机且唯一的输出(换句话说,没有两个输入会产生相同的输出)

  4. Irreversible — Given an output of a hash function, the original input is unable to be obtained

    不可逆-给定哈希函数的输出,将无法获得原始输入

These rules provide the foundation that enables Bitcoin mining to secure the network.

这些规则提供了使比特币挖掘能够保护网络安全的基础。

In particular, the creator of the Bitcoin protocol, Satoshi Nakomoto, chose to use the SHA-256 hash function as the basis for Bitcoin mining. This is a specific cryptographic hash function that has been mathematically proven to hold the above properties. It always outputs a 256 bit number (the most basic unit of computation), which is usually represented in the hexadecimal number system with 64 characters for human-readability.

特别是,比特币协议的创建者中本聪(Satoshi Nakomoto)选择使用SHA-256哈希函数作为比特币挖矿的基础。 这是一种特殊的加密哈希函数,已在数学上证明具有上述特性。 它总是输出一个256位数字 (最基本的计算单位),该数字通常在十六进制数字系统中以64个字符表示,以方便人们阅读。

The output of the SHA-256 function is usually referred to as the hash of its input.

SHA-256函数的输出通常称为其输入的哈希

Here is an example of a SHA-256 function input and output (you can try it out yourself here):

这是SHA-256函数输入和输出的示例(您可以在此处尝试一下):

Input to SHA-256:

Output to SHA-256:
77077b1f4c3ad44c83dc0bdb8d937e9b71c0ef07a35c2664bb7da85be738eacf

Interestingly enough, in the majority of places where hashing is used in the Bitcoin protocol, double hashing is used. This means that the output of the original SHA-256 function is then put right back into the SHA-256 function to obtain another output. Here is what that process looks like:

有趣的是,在比特币协议中使用散列的大多数地方,都使用了双重散列 。 这意味着原始SHA-256函数的输出然后又被放回到SHA-256函数中以获得另一个输出。 该过程如下所示:

Input to SHA-256(first round):

Output (first round):
77077b1f4c3ad44c83dc0bdb8d937e9b71c0ef07a35c2664bb7da85be738eacf

Input to SHA-256 (second round):
77077b1f4c3ad44c83dc0bdb8d937e9b71c0ef07a35c2664bb7da85be738eacf
Output (second round and final result):
3c6c55b0e4b607b672b50f04e028a6951aed6dc97b91e103fb0f348c3f1dfa00

Double hashing is used to safeguard against birthday attacks. A birthday attack is a scenario where an attacker is able to produce the same hash as another input by using a completely different input (called a collision). This breaks the third property of uniqueness. Without it, two completely different Bitcoin blocks may be represented by the exact same hash, allowing attackers to potentially switch out blocks.

双散列用于防止生日攻击。 生日攻击是一种情形,攻击者可以通过使用完全不同的输入(称为冲撞 )来产生与另一个输入相同的哈希。 这打破了唯一性的第三个属性 没有它,两个完全不同的比特币块可能会由完全相同的散列表示,从而使攻击者有可能切换出块。

With the SHA-256 function, the probability of this attack happening is infinitely small. If it wasn’t close to impossible, SHA-256 would be considered broken.

使用SHA-256功能,发生这种攻击的可能性非常小。 如果不是几乎不可能,SHA-256将被视为损坏。

However, other hash functions have been “broken” in the past. In order to safeguard against this happening to SHA-256 in the future (and effectively breaking the security model of Bitcoin) it’s best to hash the hash. This halves the probability of a collision occurring, making the protocol that much more secure.

但是,其他哈希函数在过去已被“破坏”。 为了防止将来SHA-256发生这种情况(并有效打破比特币的安全模型),最好对哈希进行哈希处理 。 这将发生冲突的可能性减半,从而使该协议更加安全。

At a very high level, Bitcoin mining is a system in which all Bitcoin transactions are sent to Bitcoin miners. Miners select one megabyte worth of transactions, bundle them as an input into the SHA-256 function, and attempt to find a specific output the network accepts. The first miner to find this output and publish the block to the network receives a reward in the form of transaction fees and the creation of new Bitcoin.

在非常高的水平上,比特币挖掘是一个系统,其中所有比特币交易都发送到比特币矿工。 矿工选择价值1兆字节的交易,将其捆绑为SHA-256功能的输入,然后尝试查找网络接受的特定输出。 第一个找到此输出并将其发布到网络的矿工以交易费和创建新比特币的形式获得奖励。

Let’s take things a step further and dive into the Bitcoin blockchain itself to see what exactly it is that miners do to make the network secure.

让我们更进一步,深入了解比特币区块链本身,看看矿工为确保网络安全所做的到底是什么。

比特币采矿:技术介绍 (Bitcoin Mining: A Technical Introduction)

Mining was introduced as the solution to the double-spend problem. If I have 1 Bitcoin and I send it to Bob, and then try sending that same Bitcoin to Alice, the network ensures that only one transaction will be accepted. It does this through the well-known process called mining.

引入了挖掘技术来解决双花问题。 如果我有1个比特币,然后将其发送给Bob,然后尝试将同一比特币发送给Alice,则网络将确保仅接受一笔交易。 它通过称为挖掘的众所周知的过程来做到这一点。

Before diving into the technical details, its important to understand why mining is necessary to secure the network. As fiat currency exists now, the currency we hold is created and validated by a federal reserve. Because Bitcoin operates under the rigid assumption of decentralization and consensus, no central authority can exist that validates and time-stamps the issuance of that currency and validation of any transactions that occur with that currency.

在深入探讨技术细节之前,重要的是要了解为什么必须进行挖掘以保护网络。 由于现在存在法定货币 ,我们持有的货币由联邦储备金创建和验证。 由于比特币在去中心化和共识的严格假设下运作,因此不存在任何中央机构可以验证和时间戳记该货币的发行以及对该货币进行的任何交易的验证。

Satoshi Nakamoto proposed the only known solution at the time to solving this validation problem in a consensus-oriented system. Titled in the Bitcoin whitepaper as proof-of-work, this scheme elegantly justifies that transactions are validated by those who are willing to expend enough physical computational energy and time to do so, while simultaneously introducing an incentive to induce market competition. This competition enables the property of decentralization to emerge and thrive organically within the ecosystem.

中本聪(Satoshi Nakamoto)提出了当时唯一的解决方案,以解决面向共识的系统中的验证问题。 该方案在比特币白皮书中被称为工作量证明 ,该方案优雅地证明了交易是由愿意花费足够的物理计算能力和时间来进行交易的人进行验证的,同时还引入了诱使市场竞争的激励措施。 这种竞争使权力下放的性质在生态系统中有机地出现并蓬勃发展。

块内的外观 (A Look Inside a Block)

A Bitcoin block consists primarily of two components:

比特币块主要由两个部分组成:

1.交易,以merkle树的形式 (1. Transactions, in the form of a merkle tree)

Mining computers collect enough transactions to fill a block and bundle them into a merkle tree.

采矿计算机收集足够的交易来填充一个区块并将其捆绑到一颗默克尔树中。

A merkle tree is a relatively simple concept: transactions lie at the bottom of the tree as leaves and are hashed using the SHA-256 function. The combination of two leaf transactions are hashed again using the SHA-256 function to form a parent of the leaves. This parent is continuously hashed upwards in combination with other parents of hashed transactions, until a single root is created. The hash of this root is effectively a unique representation of the transactions that are underneath it.

merkle树是一个相对简单的概念:事务像树叶一样位于树的底部,并使用SHA-256函数进行哈希处理。 使用SHA-256函数再次哈希两个叶子事务的组合,以形成叶子的父级。 将此父项与哈希交易的其他父项连续向上哈希,直到创建单个为止。 此根的哈希实际上是其根下事务的唯一表示。

The root of the merkle tree is a combination of the hashes of every transaction in the tree.

merkle树的根是树中每个事务的哈希值的组合。

Recall that for any any input to a hash function, the output is entirely unique. Therefore, once most nodes on the network receive a mined block, the root of the merkle tree hash acts as an unchangeable summary of all the transactions in that given block.

回想一下,对于哈希函数的任何输入,输出都是唯一的。 因此,一旦网络上的大多数节点接收到一个挖出的块,merkle树哈希的根就充当该给定块中所有事务的不变摘要。

If a malicious actor were to try and change the contents of a transaction in a block, its hash would be changed. This change of a hash would be propagated up the transaction’s merkle tree until the hash of the root is changed. Any node can then quickly catch this malicious act by comparing the root of the changed block’s merkle tree to that of a valid block’s merkle tree.

如果恶意行为者试图在一个块中更改事务的内容,则其哈希将被更改。 哈希的这种更改将沿事务的merkle树传播,直到更改根的哈希为止。 然后,任何节点都可以通过将更改后的块的Merkle树的根与有效块的merkle树的根进行比较来Swift捕获此恶意行为。

2.块头 (2. The block header)

The block header is a summary of the contents of the block itself. It contains the following six components:

块标题是该块本身内容的摘要。 它包含以下六个组件

  • The version of software the Bitcoin client is running

    比特币客户端正在运行的软件版本
  • The timestamp of the block

    区块的时间戳
  • The root of its containing transactions' merkle tree

    包含交易的Merkle树的根
  • The hash of the block before it

    之前块的哈希
  • A nonce

    随机数

  • The target

    目标

Remember that the root of the transaction merkle tree acts as an effective summary of every transaction in the block without having to look at each transaction.

请记住,事务Merkle树的根充当块中每个事务的有效摘要,而不必查看每个事务。

The hash of the previous block before it allows the network to properly place the block in chronological order. This is where the term blockchain is derived from — each block is chained to a previous block.

前一个块的哈希值,它允许网络按时间顺序正确放置该块之前。 这是术语“区块链”的来源-每个块都链接到前一个块。

The nonce and target are what make mining tick. They are the basis for solving the SHA-256 puzzle that miners need to solve.

随机数目标是导致挖矿tick的原因。 它们是解决矿工需要解决的SHA-256难题的基础。

Please note that all of this data in the block header is compressed into 80 bytes using a notation called little-endian, making the transfer of block headers between nodes a trivially efficient process. For the purposes of this explanation, we’ll ignore this compression and assume data is in its original form.

请注意,使用称为little-endian的表示法将块头中的所有这些数据压缩为80个字节 ,从而使节点之间的块头传输成为微不足道的过程。 出于解释的目的,我们将忽略此压缩,并假定数据为原始格式。

解释采矿问题 (Explaining the Mining Problem)

The target stored in the block header is simply a numeric value stored in bits. In traditional base 10 notation, this target ranges anywhere between 0 to somewhere in the range of 2²²⁴ (a 67+ digit number), depending on how many miners are competing to solve this problem at the same time.

存储在块标题中的目标只是一个以位存储的数字值。 在传统的以10为基数的表示法中,此目标的范围是0到2²²⁴( 67+ 数量),具体取决于有多少矿工竞相同时解决此问题。

Recall that the output of SHA-256 is just a number. The goal of a miner is to take the current block’s header, add a random number to it called the nonce, and calculate its hash. This numeric value of the hash must be smaller than the target value.

回想一下SHA-256的输出只是一个数字。 矿工的目标是获取当前块的标头,向其添加一个随机数,称为随机数 ,并计算其哈希值。 哈希的此数字值必须小于目标值。

That’s all there is to it. But it’s much easier said than done.

这里的所有都是它的。 但这说起来容易做起来难。

Recall the first property of SHA-256: an input into a hash function will always result in the same output. Therefore, if the miner took the block header, hashed it, and realized that the hash value wasn’t less than the target, they would have to change the input somehow in order to try finding a hash below the target value.

回想一下SHA-256的第一个属性:哈希函数的输入将始终导致相同的输出。 因此,如果矿工使用了块头,对其进行了哈希处理,并意识到哈希值不小于目标值,则他们将不得不以某种方式更改输入,以尝试找到低于目标值的哈希值。

This is where the nonce comes in.

这是nonce出现的地方。

The miner adds a number (starting from 0), called the nonce, to the block header, and hashes that value. If the hash value isn’t less than the target, the miner will increment the nonce by 1, add it again to the block header, and hash that changed value. This process is repeated continuously until a hash less than the target value is found.

矿工将一个称为nonce的数字(从0开始)添加到块头,并对该值进行哈希处理。 如果哈希值不小于目标值,则矿工将随机数增加1,将其再次添加到块头中,并对更改后的值进行哈希处理。 连续重复此过程,直到发现哈希值小于目标值为止。

一个采矿的例子 (A Mining Example)

Here’s a rough approximation of what made up the first block header:

这是第一个块头的大致组成:

  • The merkle root of the transaction in the Genesis block:

    创世块中交易的商品根:
Merkle Root:
4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
  • The first known Bitcoin version: 0.1.0

    已知的第一个比特币版本: 0.1.0

  • The timestamp of the block: 2009–01–03 18:15:05

    该区块的时间戳: 2009–01–03 18:15:05

  • The target (this is also the highest the target will ever be):

    目标(这也是有史以来的最高目标):
Target:
0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  • No previous block hash — this was the first block, and so this is a unique case

    没有以前的块哈希-这是第一个块,因此这是一个特例

The final block header after adding its components together:

将其组件添加在一起后的最终块头:

Let’s take this large header and compute the double-hash:

让我们使用这个大标头并计算double-hash:

SHA-256 of header:
7d80bd12dfdccbdde2c41c9f406edfc05afb3320f5affc4f510b05a3394e1c91

SHA-256 of the previous result (final result):
c5aa3150f61b752c8fb39525f911981e2f9982c8b9bc907c73914585ad2ef12b

Both the target and the output hash are incredibly large numbers when converted to base 10 (remember, over 67 digits long). Instead of trying to demonstrate the comparison of the two here, the following Python function handles the comparison instead:

当转换为基数10时,目标哈希和输出哈希都是非常大的数字(请记住,长度超过67位)。 下面的Python函数代替了这里的Python函数,而不是试图在此处演示两者的比较:

def isBlockHashLessThanTarget(blockHash, target):
    return int(blockHash, 16) < int(target, 16)

True is returned if the hash is less than the target, false otherwise.

如果哈希小于目标,则返回True,否则返回false。

Here is the result with our target and block hash:

这是我们的目标和区块哈希的结果:

Now we take the original block hexadecimal value and add 1 to it. Here is the following result:

现在,我们将原始块的十六进制值加上1。 结果如下:

We then run the same hashing algorithm and comparison on this changed data. If its not below the target, keep repeating.

然后,我们运行相同的哈希算法,并对更改后的数据进行比较。 如果它不低于目标,请继续重复。

Once a successful hash is found, the latest nonce used to find this solution is saved within the block.

一旦找到成功的哈希,用于查找此解决方案的最新随机数将保存在块中。

The listed nonce on the Genesis block is 2,083,236,893.

Genesis块上列出的现时值为2,083,236,893。

This means Satoshi Nakomoto iterated through this process over 2 billion times before he found a hash that was acceptable.

这意味着中本聪(Satoshi Nakomoto)遍历此过程超过20亿次,然后才发现可接受的哈希值。

I’ve written a small Python implementation of this Genesis block mining process that can be found on my GitHub.

我已经编写了这个Genesis块挖掘过程的小型Python实现,可以在我的GitHub上找到 。

subhan-nadeem/bitcoin-mining-pythonbitcoin-mining-python - A Python implementation of the Bitcoin mining algorithmgithub.com

subhan-nadeem / bitcoin-mining-python bitcoin-mining- python- 比特币挖掘算法的Python实现 github.com

See how long it would take for you to successfully mine the Genesis block!

看看成功开采Genesis区块需要多长时间!

注意事项: extraNonce (A Caveat: extraNonce)

The nonce value in a block header is stored as a 32-bit number. This means that the highest nonce anybody is able to achieve is 2³² (approximately 4 billion). After 4 billion iterations, the nonce is exhausted, and if a solution is not found, miners are once again stuck.

块标题中的现时值存储为32位数字。 这意味着任何人都可以达到的最高随机数为2³² (约40亿)。 经过40亿次迭代,随机数已用尽,如果找不到解决方案,矿工将再次陷入困境。

The solution to this is to add a field to the coinbase (the transaction contents of a block, stored as the merkle tree) called the extraNonce. The size of this extraNonce is only limited by the size of block itself, and so it can be as large as miners wish as long as the block size is within protocol limits.

解决方案是在coinbase (一个区块的交易内容,存储为merkle树)中添加一个称为extraNonce的字段。 这个extraNonce的大小仅受块本身的大小限制,因此只要块大小在协议限制之内,它就可以像矿工所希望的那样大。

If all 4 billion possible values of the nonce are exhausted, the extraNonce is added and incremented to the coinbase. A new merkle root and subsequently new block header are calculated, and the nonce is iterated over once again. This process is repeated until a sufficient hash is found.

如果随机数的所有40亿可能值都用尽,则将extraNonce添加并增加到币库中。 计算一个新的merkle根,然后计算出新的块头,并再次迭代nonce 。 重复此过程,直到找到足够的散列为止。

It’s best to avoid adding the extraNonce until the nonce is exhausted, because any change to the extraNonce changes the merkle tree. This requires extra computation in order to propagate the change upwards until a new root of the merkle tree is calculated.

最好避免在随机数用尽之前添加extraNonce ,因为extraNonce的任何更改都会改变merkle树。 这需要额外的计算才能向上传播更改,直到计算出Merkle树的新根为止。

矿工奖励 (The Miner Reward)

A miner who successfully publishes a block the fastest is rewarded brand new Bitcoin, created out of thin air. That reward currently stands at 12.5 BTC. Just how do these Bitcoins come into existence?

一个成功发布区块最快的矿工是凭空创造的奖励全新比特币。 该奖励目前为12.5 BTC。 这些比特币如何诞生?

Each miner simply adds a new output transaction to their block that attributes 12.5 Bitcoins to themselves before beginning to mine the block. The network protocol will accept this special transaction as valid upon receiving a newly validated block. This special transaction is called a generation transaction.

每个矿工只需在其区块中添加一个新的输出交易,即可在开始开采该区块之前将12.5比特币分配给自己。 网络协议在收到新验证的块后将接受此特殊交易为有效。 这种特殊交易称为世代交易。

Its the miner’s responsibility to add this transaction into the block before mining it. There has been at least one case where miners forgot to add the reward to the transaction before mining a block, effectively destroying 12.5 BTC!

采矿者有责任在开采之前将交易添加到区块中。 至少有一种情况 ,矿工在挖出一个区块之前忘记为交易增加奖励,实际上破坏了12.5 BTC!

验证工作量证明 (Validating Proof-of-Work)

Let’s say our miner has found a hash that is less than the target. All this miner has to do is publish the mined block with the original six components to any connected nodes.

假设我们的矿工发现哈希值小于目标值。 矿工要做的所有事情就是将具有原始六个组件的已开采区块发布到任何连接的节点。

This node receiving the block will first verify the transaction set, ensuring all transactions are valid (for example, all transactions are appropriately signed, and coins aren’t being double-spent and/or being created out of thin air).

接收到该块的节点将首先验证交易集,以确保所有交易均有效(例如,所有交易均已适当签名,并且不会花双花钱和/或凭空创建硬币)。

It will then simply double-hash the block header and ensure the value is below the block’s included target value. Once the block is deemed valid, the new node will continue to propagate this block across the network until every node has an up-to-date ledger.

然后,它会简单地双击哈希 块标题,并确保该值低于该块包含的目标值。 一旦该块被视为有效,新节点将继续在网络上传播该块,直到每个节点都拥有最新的分类帐。

As you can see, newly published blocks can easily be verified by any given node. However, publishing a valid block to the network requires an incredibly large amount of computational power (thus, electricity and time). This asymmetry is what allows the network to be secured while simultaneously allowing individuals who wish to conduct economic activity on the network to do so in a relatively seamless manner.

如您所见,任何给定节点都可以轻松验证新发布的块。 但是,将有效块发布到网络需要大量的计算能力(因此,电和时间)。 这种不对称性可以确保网络的安全,同时又允许希望在网络上进行经济活动的个人以相对无缝的方式进行网络活动。

封锁时间和调整目标 (The Block Time and Adjusting the Target)

As the first miners began mining, they each monitored the block time. Each Bitcoin block has a set block time of 10 minutes. What this means is that given the current level of computing power (network hashrate) on the network, nodes will always expect newly validated blocks to be produced every 10 minutes on average.

当第一批矿工开始开采时,他们每个人都在监视区块时间 。 每个比特币区块的设定区块时间为10分钟。 这意味着在给定当前网络上的计算能力( 网络 哈希率 )水平的情况下,节点始终希望平均每10分钟产生一次新验证的块。

We can reasonably expect blocks to be produced within 10 minutes because the probability of finding a block, given the network hashrate, is known.

我们可以合理地预期在10分钟内会生成块,因为已知网络哈希率的情况下找到块的概率是已知的。

For example, let’s take the easiest target that’s ever existed in Bitcoin: the genesis block. The probability of any single hash being less than the easiest target is 1 in 2³². That’s one in over four billion. Therefore, we can reasonably expect somebody to run 2³² iterations of the mining problem in order to find a proper hash. Nodes on the network expected four billion of these iterations to be run across all miners on the network every 10 minutes.

例如,让我们以比特币有史以来最简单的目标为依据:创世块。 任何单个哈希值小于最简单目标的可能性为23²1。 这是超过40亿的数字之一。 因此,我们可以合理地期望有人对挖掘问题进行2²²迭代,以找到合适的哈希值。 网络上的节点预计其中40亿次迭代将在所有节点上运行 每10分钟在网络上的矿工。

If, over a large sample size of blocks, blocks start appearing faster than 10 minutes, this is a pretty clear indication that nodes on the network are iterating through four billion hashes much faster than 10 minutes. This situation prompts every node to adjust the target proportionally based on the increase (or decrease) in network power to ensure blocks continue to be produced every 10 minutes.

如果在大量的块样本中,块开始出现的时间快于10分钟,则很明显地表明网络上的节点正在迭代40亿个散列,其速度比10分钟要快得多。 这种情况促使每个节点根据网络功率的增加(或减少)按比例调整目标,以确保每10分钟继续产生块。

In actuality, nodes on the network monitor the block time across 2016 blocks, which comes out to exactly two weeks. Every two weeks, the total block time is compared to the expected block time (which is 20160 minutes).

实际上,网络上的节点会监视2016年区块的区块时间,这恰好是两周。 每两周将总阻止时间与预期的阻止时间(即20160分钟)进行比较。

To obtain the new target, simply multiply the existing target by the ratio of the total actual block time over the last two weeks to get the expected block time. This will adjust the target proportionally to the amount of entering or exiting computing power on the network.

要获得新的目标,只需将现有目标乘以最近两周的总实际封锁时间之比即可得出预期的封锁时间。 这将根据网络上输入或退出计算能力的数量成比例地调整目标。

The block time and the ability to easily calculate the probability of finding a valid block lets nodes easily monitor and determine the total hashpower on the network and adjust the network. No matter how much computing power is added to the network or how quickly its added, on average the block time will always remain at 10 minutes.

块时间和轻松计算发现有效块概率的能力使节点可以轻松监视和确定网络上的总哈希功率,并调整网络。 不管将多少计算能力添加到网络中,或将其添加到网络中的速度有多快,平均阻塞时间将始终保持在10分钟。

The current total hash rate on the network is 28.27 exahash per second. That’s 28.27 x 10¹⁸ hashes run every second across all computers on the network.

网络上当前的总哈希率是每秒28.27 exahash。 那是28.27 x 10 -1的散列值在网络上的所有计算机上每秒运行一次。

综上所述 (In summary)

We have now comprehensively covered the following:

现在,我们全面介绍了以下内容:

  • Why cryptographic one way hashing is vital to proof-of-work

    为什么加密单向哈希对工作量证明至关重要
  • A breakdown of the construction of a Bitcoin block

    比特币区块的构造分解
  • The actual mining process and iteration itself

    实际的挖掘过程和迭代本身
  • How nodes can easily validate other blocks

    节点如何轻松验证其他块
  • How the network manages to maintain the algorithm and competitiveness by monitoring the block time and adjusting the target

    网络如何通过监视阻塞时间和调整目标来维护算法和竞争力

You should now be able to understand and explain how proof-of-work actually functions and why it is considered to be an entirely secure algorithm that enables decentralization and consensus!

您现在应该能够理解和解释工作量证明的实际功能,以及为什么它被认为是能够实现分散化和共识的完全安全的算法!

Follow me on Twitter and Medium if you’re interested in more in-depth and informative write-ups like these in the future!

如果您将来对此类更深入,内容更丰富的文章感兴趣,请在Twitter和Medium上关注我!

翻译自: https://www.freecodecamp.org/news/how-bitcoin-mining-really-works-38563ec38c87/

比特币挖矿原理

你可能感兴趣的:(算法,区块链,python,比特币,机器学习)