Blockchain series of tutorials: mining in Bitcoin

Posted Jun 26, 20205 min read

Introduction

We know that Bitcoin is produced by mining, so what are the characteristics of mining in the Bitcoin network? How to distribute mining income? You can find the answer in this article.

Bitcoin node structure

As mentioned in the last article, Bitcoin is a P2P network. There are many nodes in the P2P network. From the definition of P2P, the status of each node is the same, but it is not. The nodes of the Bitcoin network have their own roles.

Let's first look at an overall picture. There are 4 types of Bitcoin nodes:

The four types are wallet, mining node, full node, and network routing node.

Different characters combined to form a huge Bitcoin network. Depending on the function, different roles may require different types.

Above we introduced 7 common nodes.

  1. Bitcoin Core This is the official bitcoin software you downloaded. It contains 4 types of functions.
  2. Full Block Chain Node, this node contains all bitcoin blockchain history information, called full node, full node is mainly used for historical transaction verification.
  3. Solo Miner, this is an independent mining node.
  4. SPV wallet, this is the lightweight wallet we introduced earlier.
  5. Pool Protocol Servers, this is the gateway of the mining pool to the Bitcoin network.

Note that in addition to its own P2P network protocol, the Bitnet network also has a Stratum protocol, which is used in mining and lightweight or mobile bitcoin wallets.

  1. Mining Nodes, which are miner nodes connected to the Bitcoin mining pool.
  2. SPV stratum wallet, a lightweight wallet using Stratum protocol.

These nodes are combined to form a huge Bitcoin network.

Mining

Mining is a process of increasing Bitcoin's money supply. Mining also protects the security of the Bitcoin system, prevents fraudulent transactions, and avoids "double payment", which means spending the same bitcoin multiple times. Miners provide the Bitcoin network with computing power in exchange for the opportunity to receive Bitcoin rewards.

Every 10 minutes, a new block will be "mined", each block contains all transactions that occurred from the previous block to the current time, these transactions are added to the blockchain in sequence in

Miners will receive two types of rewards during the mining process:new currency rewards for creating new blocks, and transaction fees for transactions contained in the blocks. In order to get these rewards, miners are competing to complete a mathematical problem based on cryptographic hash algorithm. The answers to these problems are included in the new block as proof of the miner's computational workload, which is called "proof of work". The competition mechanism of the algorithm and the mechanism that the winner has the right to record transactions on the blockchain are the cornerstones of Bitcoin security.

The new bitcoin generation process is called mining because its reward mechanism is designed as a decreasing speed mode, similar to the mining process of precious metals. Bitcoin currency is issued through mining, similar to the central bank issuing currency by printing bank notes.

The number of bitcoins miners earn by creating a new block is reduced by about half every four years(or precisely every 210,000 blocks). It started with 50 bitcoins for each block in January 2009, and then halved by November 2012 to award 25 bitcoins for each block. After that, it will be halved again at some point in 2016 to reward 12.5 bitcoins for each new block. Based on this formula, Bitcoin mining rewards decrease exponentially until 2140. At that time, all bitcoins(20,999,999,980) will be issued.

In other words, after 2140, there will be no new bitcoins.(Deflationary currency)

Mining node

In the Bitcoin network, some nodes are called professional node miners.

Like any other complete node, these nodes receive and propagate unconfirmed transaction records in the Bitcoin network. However, these nodes can also integrate these transaction records in new blocks.

The competition between miners ends with the spread of new blocks, like announcing who is the final winner. For miners, obtaining a new block means that a participant has won, and they have lost the competition. However, the end of one round of competition also represents the beginning of the next round of competition. The new block is not just a checkered flag that symbolizes the end of the competition; it is also the starting gun for the next block competition.

Coin trading

The first transaction in the block is a special transaction called a coin transaction or coinbase transaction.

This transaction is constructed by mining nodes and used to reward miners for their contributions. The mining node will create a transaction "pay 25.09094928 bitcoins to the address of XX" and send the reward of the generated transaction to its own wallet. The reward amount for miners who dig out the block is the sum of coinbase reward(25 brand new bitcoins) and all transaction miner fees in the block.

Unlike regular transactions, Genesis transactions have no input and do not consume UTXO. It contains only one input called coinbase and is only used to create new bitcoins.

The coin transaction has an output, which is paid to the miner's bitcoin address.

Mining pool income distribution

According to the different income distribution of the mining pool, it can be divided into two types.

  1. PPLNS

The full name is Pay Per Last N Shares, which means "paying profits based on the past N shares." This means that once all miners find a block, everyone will be allocated according to the proportion of the number of shares each person contributes. The currency in the block.

  1. PPS

PPS mining pool(similar to working mode) PPS is called Pay Per Share. In order to solve the situation where PPLNS sometimes has high returns and sometimes no returns, PPS uses a new algorithm. PPS calculates the mineral resources that the mining pool can obtain every day based on your computing power in the mining pool, and gives you a basically fixed income every day.

Mining direction

Since 2009, the original ordinary computers can be "mined", but by 2014, all mining computers have also become "mining machines" customized by professional design chip companies for Bitcoin.

As computers involved in mining become more and more expensive, the cost of bitcoin production is rising. As of October 2014, the cost of each bitcoin production has reached nearly 3,000 yuan. This production includes computer manufacturing costs, electricity costs incurred during the production process, as well as personnel costs and site costs. That is to say, before the end of 2016, because 3,600 bitcoins were produced every day, the daily investment reached 10 million yuan. And with increasing competition, this cost is still in the rising stage.

Waste of computing power

So what exactly did mining do with so much electricity? Without him, it is just a hash value.

So this causes serious waste. Of course, some people have come up with some solutions, use these computing power to do something useful:

  • Sunny King's prime currency
  • Prime currency(PrimeCoin code XPM) to find prime numbers
  • GridCoin(GridCoin code GRC) distributed scientific computing

Hash adjustment

Note that the difficulty of mining Bitcoin does not necessarily increase. It is dynamically adjusted.

If the average block generation time in the previous cycle(2016 blocks) is greater than 10 minutes, that is, the entire network's computing power decreases, the difficulty in the current cycle will decrease, making the block generation time faster. However, it seems that there has not been a decline in the computing power of the entire network so far, and the difficulty has been increasing.

Because it is based on ex-post statistics, the change in difficulty will lag behind the change in computing power of the entire network by 1 to 2 cycles. If the computing power of the entire network increases, the mining speed will increase in these 1 to 2 cycles, and the mining revenue will increase; otherwise, the revenue will decrease. But in the long run, it remains balanced.

to sum up

This article introduces the mining-related content in the Bitcoin network, I hope you can like it.

Author:flydean program those things

Link to this article: http://www.flydean.com/bitcoin-mine-consensus/

Source of this article:flydean's blog

Welcome to pay attention to my public number:those things of the program, more exciting waiting for you!