The reward mechanism of Ethereum (ETH)

write picture description here

If you ask a graphics card what it hates the most, the answer must be Ethereum.
Ethereum, miners are crazy, graphics cards are trembling, and gamers are cursed.
However, in addition to buying mining machines, connecting to mining pools, and selling coins to cash out, has anyone paid attention to the reward mechanism of Ethereum?

temporary fork

Since the blockchain is a decentralized technology, all miners in the world work at the same time and independently mine blocks that meet the requirements. Because of their independent work, it is possible that two independent miners have successively discovered two different blocks that meet the requirements, such as the following situation, which is called a temporary fork.

Note: the arrow pointing to a block means that it saves the hash of the previous block

write picture description here

Both miners found a block of height 2, so who should take?

So the tearing began. The blockchain is a snobby, only the longest chain is recognized. The yellow and green blocks who have the successor first and become the longest chain will be recognized, and those who fail will be rejected. abandon. In order to become the longest chain, both miners desperately broadcast the blocks they dug to more nodes, and hope that they can spread their blocks more widely, so that more miners can Mining the next block under the block you mined, and finally making your own block part of the longest chain.

However, there is only one winner, the winner writes history, and the loser will be discarded, and the transactions in it will be repackaged into subsequent blocks. The picture below shows that the green block won, and the yellow block became an orphan and was abandoned.

write picture description here

This kind of thing happens all the time, it's not uncommon. If a block is abandoned, what happens to the mining rewards contained in it? For Bitcoin, the winner takes all, the loser has nothing, and the bamboo basket is empty. The heart of the miner who dug out the yellow block is broken, he is crying.

叔块(Uncle Block)

Ethereum created a new term, Uncle Block. For a block of height 3, the green block is its parent block. Although the yellow block fails, it is still a sub-block of the block with height 1 and a sibling block of the green block. Therefore, the block with a height of 3 calls this yellow block an uncle, which is how the uncle gets its name.

Note: The dotted line is only used to state the relationship, and does not indicate an actual connection.

write picture description here

An orphan block that cannot be part of the main chain will become an uncle block if it is fortunate to be included in the blockchain by a subsequent block through the uncles field. If an orphan block is not accepted by any block, the orphan block will still be discarded and will not enter the blockchain, that is to say, the orphan block will become an uncle block after being accepted.

The design of Ethereum is more human than that of Bitcoin. Uncle blocks can also be rewarded. Miners no longer have to worry about being busy. And if anyone in the future blocks retains the uncle block, there will be additional rewards for the block that retains the uncle block. Retaining the uncle block is also called containing the uncle block.

The figure below shows that the block with height 3 contains an uncle block, but the uncle block is only included. The transactions in the uncle block will return to the transaction pool and wait for repackaging. A block can only contain at most 2 uncle blocks.

write picture description here

Why is Ethereum designed this way? Because the block time of Ethereum is around 20 seconds, it is more prone to temporary forks and orphaned blocks than Bitcoin. Moreover, the shorter block time also makes it more difficult for blocks to fully propagate throughout the network, especially for those miners with slow network speeds, which is a great injustice. In order to balance the interests of all parties, such an uncle block mechanism is designed. The proportion of uncle blocks in all mined blocks is called uncle block rate, and the current uncle block rate is about 9.7%.

write picture description here
Data source: The ethereum blockchain explorer

Gas (gasoline that drives the program)

Ethereum is a decentralized platform for running smart contracts. It provides an Ethereum Virtual Machine (EVM for short) on which developers can develop various applications. You can think of this EVM as your computer, which is capable of running some Ethereum-defined instructions. Unlike Bitcoin's scripting engine, Ethereum's EVM is very powerful and is known as "Turing complete". No matter what "Turing completeness" is, you only need to know that a "Turing complete" virtual machine can implement loop statements. With loops, there will be little bad guys or unqualified programmers who will create an infinite loop, and the computer will be in an infinite loop. The big deal is to restart, just restart, but Ethereum is decentralized, and if the EVM is in an infinite loop, it cannot be restarted.

Is there a way to solve this problem?

Unfortunately, this problem has been studied many years ago, called The Halting Problem, and it has been proved that there is no way to detect whether a program will loop infinitely.

Since it cannot be detected, is there any other way to prevent the infinite loop?

In the idle time of refueling at the gas station, the developers of Ethereum fell into contemplation and said to themselves: Why doesn’t the car keep running and can’t stop? "Because there will be no oil!" the refueling master said as he pulled out the refueling gun.
This story is just my own brain, to add a little more interest.

If each instruction of the program on the EVM consumes a little "resource" and the "resource" is used up, no matter whether the program is executed or not, it will be forcibly terminated, so it doesn't matter whether it is an infinite loop or not.

The resource to be consumed when the program is executed is called Gas, and each instruction consumes a different amount of gasoline.

To give a few examples:

  • ADD: Addition operation 3Gas
  • MUL: Multiplication operation 5Gas
  • SUB: Subtraction operation 3Gas
  • DIV: Division operation 5Gas
  • HASH: Calculate the hash value 30Gas

The more complex the operation, the more Gas it needs to consume. As long as a program is added with an upper limit of the gas consumption, it can prevent the program from having an infinite loop and cannot stop. At the same time, Ethereum also sets an upper limit on the total gas consumed by the programs contained in each block, so as not to contain too many programs in the block and affect some nodes with weaker performance. The upper limit of Gas that can be consumed by each block can also be adjusted, which is determined by the miners' vote. Currently, it is 6725538 Gas, which is the GAS LIMIT part in the figure below.

write picture description here

Data source: Ethereum Network Status

Gas is not free in real life, nor is it in Ethereum, you need to buy gas with ether. Each program gives how much ether they are willing to spend to buy 1 unit of Gas, which is called the Gas Price.

The Ether that each program needs to pay for Gas can be calculated with the following formula:

Gas cost = amount of gas consumed x price of gas

The higher the gas price you are willing to pay, the faster your transaction will be packaged by miners, which is similar to Bitcoin’s transaction fee.

Ethereum's block reward

The uncle block and Gas were introduced earlier, and now we enter the core part, the reward mechanism of Ethereum. As mentioned earlier, there are two types of blocks in Ethereum, ordinary blocks and uncle blocks. We need to discuss the rewards of each block according to the situation.

Normal block reward:

The fixed reward is 5ETH, and each ordinary
block the sum of the gas costs of all the programs
contained in the block. If the ordinary block contains uncle blocks, each uncle block can get 1/32 of the fixed reward 5ETH, which is 0.15625 ETH.

Uncle block reward:

The reward calculation of uncle block is a bit complicated, the formula is:

Uncle block reward = (uncle block height + 8 - height of block containing uncle block) * normal block reward / 8

Practice
a good Ethereum block browser, Ethereum Blocks Information , which can view the rewards of each block in detail.

Let's look at a block 4222300 that was just dug out . Since we saw it on the main chain, it is a normal block.

write picture description here

Its reward consists of three parts:

Fixed reward: 5ETH

The total cost of Gas (some people call it transaction fee): 0.281837168043699381ETH

Reward for including two uncle blocks: 5 * ( 1 / 32 ) * 2 = 0.3125ETH

One thing to note here is that the original text in the official document is "an extra reward for including uncles as part of the block". When I first came into contact with Ethereum in 2015, many articles on the Internet directly said "an extra reward for including uncles as part of the block". , which made me mistakenly think that I got the same amount of reward as the reward for mining these uncle blocks, that is, the Uncles Reward in the above picture: 8.75ETH, which is wrong, "including uncle block reward" refers to the uncle block Including the reward for the behavior of the blockchain, I hope everyone can avoid stepping into this pit.

Let's take another look at the uncle block 0x1c2cbba0403f1079dcdb70e5971a87ce0fbc03d4572be30e2d17e4e4a0f136d5 , does it look awkward? In fact, the uncle block also has height. The height of the uncle block's parent block +1 is the height of the uncle block .

Direct substitution formula:

( 4222271 + 8 - 4222272 ) * 5 / 8 = 4.375ETH

Off topic

That's it for the reward mechanism, have the careful readers found a hole in the front:

The upper limit of Gas that can be consumed in each block can also be adjusted, and the miners vote to decide.” What is the process of this voting adjustment?
In order not to make this article too long and cause inconvenience to everyone’s reading, sell it first I will fill in these holes slowly in the future. Ethereum is really a very good platform, and it is also developing rapidly. I hope everyone can pay attention to it, understand it, and control it, instead of hyping it and ignoring it. Eventually ruined it.

This article is reproduced from: https://juejin.im/entry/59ad0169f265da2498241fde

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325762901&siteId=291194637