1

What happens when two miners include same or set of transaction in their block, mine it and then broadcast it at same time? Can the transaction be included in two separate block like this OR a fork happens?

1

If both blocks are broadcast at the same time, and we assume both miners are equally connected to the network, a fork may occur.

Since the default mining policy is mining on the top of the longest chain, or the first one heard in case of a fork, the network should mine in two different blocks until a new one is found, moment when all should go back to "normal".

1

It is possible for two miners find blocks at the same height simultaneously, and for those two blocks to have an overlap of included transactions. Each block is valid in it's own right, but eventually only one can be included in the longest chain, and the other will become an 'orphan block'. Lets call these two blocks Block A and Block B.

When the blocks are found, the lucky miners will immediately broadcast them to the network. Block propagation has been optimized very well over the years, so in reality it takes very little time for the entire network to hear about a new block (and miners generally stay very well connected to the network), but lets pretend it takes much longer than normal. In this situation, some nodes may hear about Block A first, and other nodes will hear about Block B first. Many nodes follow the rule of 'first seen is valid', so they will reject the second block they hear about (even though it is valid). This creates a fork, since the network is not all agreeing on a common history.

This situation resolves once the next block is found**. Miners run nodes as well, so each miner will begin mining the next block on top of whichever block they heard about first. So if a miner that saw Block A finds the next block, then Block A will be included in the final blockchain history, and Block B will be orphaned (and vice versa). This brings the network back in sync, as all nodes that heard about Block B first would drop Block B in order to stay in sync with what is now the longest chain.

** note that it is possible for the situation to repeat, and for a miner on each side of the fork to again find blocks simultaneously. The resolution is no different, but now the orphaned blocks will be two deep, instead of just one. In practice it is very rare for this situation to occur (it is equal to the probability of an orphan block occurring, squared)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.