Difference between revisions of "Mining"

Line 34: Line 34:
  
 
=== Proof-of-work ===
 
=== Proof-of-work ===
Bitcoin uses the hashcash proof-of-work function.
+
Bitcoin uses the [[hashcash]] proof-of-work function.
  
A miner cannot create a new block without finding a valid proof-of-work hash for the block header they are hashing. To be valid, the SHA-256d hash (which is just a number) of the block header must be less than another number, called the target. The target value is defined by the nBits field in the block header that is being hashed.
+
A miner cannot create a new block without finding a valid proof-of-work hash for the block header they are hashing. To be valid, the SHA-256d hash (which is just a number) of the block header must be less than another number, called the [[target]]. The target value is defined by the [[Block hashing algorithm|Bits]] field in the block header that is being hashed.
 
   
 
   
 
The target adjusts so that the average time it takes to find a valid proof-of-work hash is ten minutes.  
 
The target adjusts so that the average time it takes to find a valid proof-of-work hash is ten minutes.  
Line 43: Line 43:
  
 
=== Incentive ===
 
=== Incentive ===
The first transaction in every block is called the Coinbase transaction. The Coinbase transaction is a special transaction which pays bitcoins to the creator of the block. The Coinbase payment is made up of the subsidy amount and the sum of all transaction fees paid by transactions within the mined block.  
+
The first transaction in every block is called the [[Coinbase]] transaction. The Coinbase transaction is a special transaction which pays bitcoins to the creator of the block. The Coinbase payment is made up of the [[Miner subsidy|subsidy]] amount and the sum of all [[transaction fees]] paid by transactions within the mined block.  
  
 
== Competition ==
 
== Competition ==

Revision as of 12:42, 2 January 2020

Introduction

Mining is the process where nodes in the Bitcoin Network assemble newly broadcast bitcoin transactions into a data structure called a block. Nodes then compete to append their block to the public blockchain by attempting to find a hash value that satisfies a difficult proof-of-work.

When a node finds a valid proof-of-work hash for a block, it broadcasts the block to all nodes. Other nodes accept this block only if all the transactions in it are valid and not already spent. Nodes then express their acceptance of the block by working on creating the next block in the chain.

Every block is timestamped and references the hash of the block preceding it. Blocks form a backward reinforcing, timestamped chain – a 'timechain', the precursor to the term ‘blockchain’.

The blockchain structures itself in a manner that is computationally impractical to modify by any one entity. Due to this, transactions included in the blockchain are considered immutable. In addition to this quality, the blockchain establishes an authoritative order of these transactions throughout the network, thereby protecting users from attempts to re-spend coins that have already been spent elsewhere. This is the key innovation of mining and of bitcoin.

Nodes

Nodes are entities that run software that adheres to the bitcoin protocol and carry out the mining functions above.

Interestingly, the bitcoin whitepaper makes no reference to the term ‘miner’ or the concept of ‘mining’. These terms are encompassed within Satoshi Nakamoto’s description of a ‘node’. It is possible however to run a node and make no attempts to find a proof-of-work. Such a setup is called a ‘listener node’ – they only participate in receiving and broadcasting transactions.

Listener nodes perform no proof-of-work and therefore cannot append new blocks to the blockchain. They can neither express acceptance of valid blocks by working on extending them, nor reject invalid blocks by refusing to work on them. Listener nodes are passive entities that follow the gatekeepers of the network, the miners. An example of a listener node is a block explorer. Block explorers are a useful service that allow users to query the blockchain for block or transaction information.

Mempool

Before a bitcoin transaction can be committed to the blockchain it needs to be received and validated by a miner. If the miner deems the transaction has paid enough in fees, they add the transaction to their mempool. As such, the mempool is just a temporary transaction store.

It is important to note every miner has their own mempool and that mempools vary across miners. It is also important to note that an individual transaction can be included in many different miner’s mempools at the same time.

A miner takes all the transactions in its mempool and hashes them into a merkle tree structure and includes the resulting merkle root within a candidate block header. The miner then hashes this candidate block header, attempting to find a valid proof-of-work.

Hashing

A hash is a function that converts a string of data into a fixed length value that represents the original string, called the hash value. Every hash value is unique.

Hashing is a one-way function, meaning it is infeasible to determine what the input data is by looking at the hash produced from it. Conversely, it is trivial to run the same input data through the same hash function and reproduce the same hash. Because of this, a hash value of input data can be thought of as the digital fingerprint of that data. In bitcoin mining, the input data is the 80-byte block header.

The hashing algorithm used in bitcoin mining is SHA-256. SHA-256 stands for Secure Hash Algorithm – 256 bit. Passing the block header data through this algorithm will always output a 256-bit number that is unique.

Bitcoin mining passes the block header data through the SHA-256 algorithm twice (SHA-256d). The reason for this is to accommodate the presumed future fracture of mining interests into separate specialized entities. A double hash allows for a hashing entity to indicate they have a valid proof-of-work to another mining related entity without having to reveal the block header input data.

The Bitcoin (BSV) network is currently making 1.3E18 attempts to find a valid block hash every second.

Proof-of-work

Bitcoin uses the hashcash proof-of-work function.

A miner cannot create a new block without finding a valid proof-of-work hash for the block header they are hashing. To be valid, the SHA-256d hash (which is just a number) of the block header must be less than another number, called the target. The target value is defined by the Bits field in the block header that is being hashed.

The target adjusts so that the average time it takes to find a valid proof-of-work hash is ten minutes.

Because of the extraordinarily large SHA-256 target space, it is extremely unlikely that any given hash will be below the target. As a result of this, hashing entities invest large amounts of capital into specialized hashing hardware along with the associated electricity costs in order to produce as many of these hashes as possible. Therefore, the only way a miner can append a block to the blockchain is through substantial financial commitment – proof-of-work.

Incentive

The first transaction in every block is called the Coinbase transaction. The Coinbase transaction is a special transaction which pays bitcoins to the creator of the block. The Coinbase payment is made up of the subsidy amount and the sum of all transaction fees paid by transactions within the mined block.

Competition

Propagation and validation

Competing best blocks

Nakamoto consensus

The mining ecosystem

Asic mining

An application-specific integrated circuit, or ASIC, is a microchip designed and manufactured for a very specific purpose. ASICs designed for Bitcoin mining were first released in 2013. For the amount of power they consume, they are vastly faster to the predecessor approach - mining using CPU or GPU.

Commercial mining

Pooled mining

Stratum

See also