How Uncles (Ommers) Hash include in headers

block-headerblocksmininguncle-blocks

I'm confused with the definition of uncle block. I read every articles and they say basically uncle block is a block that valid but lose the race to main blockchain. All the blocks' hashes that lose are include in the won block. And the header's of won block is also contains the hash of list of uncle blocks' hashes.

But, to get the ethash, you need the RLP of headers, right? How could you be the first one to mine block if you must first include uncle block that lose to race after you? Or the uncles are the blocks that lose against your parent block? If the latter is right, what criteria to make block to be our uncle block? Are every blocks that valid but lose the race must be our uncles?

Best Answer

I think the yellow paper or beige paper best explain this.

to understand uncles first it's important to understand consensus. imagine two miners, let's say in US and in China, work on two different blocks of the same height N; let's call them US miner and CH miner. approximately at the same time, both miners find solutions (a nonce matching the required difficulty) and start propagating the blocks through the network. Now nodes closer to US miner probably get the US block first and same thing for nodes closer to CH miner. At this point there are two canonical chains and the blockchain is split at block N. This is fine and happens all the time (approximately every 8 blocks), you can think of these blocks as committed but not yet finalized until the network reaches consensus as per the consensus rules.

Now some miners begin working on block N+1 building on top of US block where others start building on top of CH block. At some point a solution to that block will be found and will be broadcasted to the network.

If block N is US block, it will include CH block headers in uncles list. Likewise if block N is CH block, it will include US block headers in uncles list. Miners are incentivized to include uncle blocks, not only because the miner of block N will be rewarded for it, but also the miner of N+1 who includes it. This way miners are rewarded for their work regardless if they were strictly the fastest/luckiest or not.

Now since block N+1 has larger "weight" than either blocks N, the network chooses it as the canonical chain and reaches consensus. ("weight" can be calculated from total difficulty and chain length, I don't remember the exact details of the implementation but this is the general idea)

Related Topic