1

When a set of new transactions is broadcast to all the Bitcoin mining pools, my understanding is that they all start working on a new block to include all those transactions. But how is it agreed upon which block is the next one to be included in the Bitcoin blockchain? Is it just the first mining pool to generate the block? And if that's the case, isn't it going to be tremendously wasteful if all but one mining pool have been working on generating a new block but all that work is wasted because their block wasn't chosen to be the next one in the chain?

1

3 Answers 3

1

When a set of new transactions is broadcast ...

Individual transactions get broadcast, not specific well-defined sets. That is, the identity or membership of a set of transactions is not preserved as data diffuses across the network.

... to all the Bitcoin mining pools,

The broadcast (as you would guess from that name) is sent to nodes in general not to specific types of node. So the transactions are broadcast to all member of the Bitcoin network, not just to members that are mining pools.

my understanding is that they all start working on a new block to include all those transactions.

No, there is no synchronisation between different mining pools. each pool can be working on different sets of transactions. The sets might overlap or be distinct.

But how is it agreed upon which block is the next one to be included in the Bitcoin blockchain?

First one to find a valid block wins.

Is it just the first mining pool to generate the block?

Yes.

Since the Bitcoin network is global and subject to communication latency, it occasionally happens that two or more miners successfully generate a new block that is accepted as the next block by topologically nearby nodes. However eventually all nodes naturally converge on a common understanding of which block is the accepted one. They will discard a branch if they later become aware of a branch that has more work invested in it. This happens fast enough that normal usage is unaffected by this. Transactions in a discarded branch still get included in later blocks of the commonly accepted branch.

And if that's the case, isn't it going to be tremendously wasteful if all but one mining pool have been working on generating a new block but all that work is wasted because their block wasn't chosen to be the next one in the chain?

That's certainly one way of looking at it. Energy has been consumed by organisations who get no immediate or direct reward for this, in this instance. However there is a benefit to Bitcoin users in general as it is a necessary part (or a necessary consequence) of securing the blockchain.

It is certainly just as valid to be concerned about the energy efficiency of cryptocurrencies as it is to be concerned about the energy efficiency of traditional monetary systems.

4
  • I agree the answer is correct. @RedGrifftyBrik, I think we should remove the AFAIK part from the answer to make it sound more assuring.
    – sanket1729
    Jan 26, 2021 at 23:20
  • @sanket1729: Done. Thanks for the feedback. Jan 26, 2021 at 23:43
  • It isn't really wasted. If lots of humans work on solving a complex math problem and only one of them succeeds, it doesn't follow that the work of the others was wasted. It's only because so many approaches were tried by so many people that the successful approach was discovered. The same logic applies here. It is not possible to have only successful attempts, so the failed attempts are not wasted -- you can't have the successes without the failures. Jan 27, 2021 at 1:11
  • @DavidSchwartz, agreed. The answer could use more clarification that "in the long run, you cannot have only successful tries without having failed attempts".
    – sanket1729
    Jan 27, 2021 at 2:49
1

Miner ASICs have one job: Change the meaningless parts of the block until the difficulty target (related to the hash of the block) is satisfied.

ASICs connect to the pool to first download the block template (they regularly do that - maybe every few seconds?). The block template contains the transactions. They calculate the merkle hash of the transactions, embed it in the block header, and hash the block header many times.

When the target is satisfied, the block is published. From then on, no one can change the transactions in the block.

all that work is wasted

This is a lottery where everyone's chances of finding the next block is proportional to their hashrates. If you need to mine all day to find one block per day -- congratulations! You can afford solo mining and you don't lose anything, and your reward is fair.

Trivia: Block mining is a Poisson process. One property of this is memory-less-ness. That is, given that the average time until the next block is 10 minutes (it is for Bitcoin):

  • After about how many blocks will someone find a block if everyone started just now: 10 minutes (t = 10)
  • What if you all had been mining for 2 minutes? Still 10 minutes (block to be released at t = 12)
  • What if you all had been mining for 20 minutes? Still 10 minutes (block to be released at t = 30)

Here's a fun puzzle by Russel O'Connor and Pieter Wuille.

So, there is no wasting in mining: it's memoryless. If you fail, you just keep trying, and everything works as intended in the end.

1

When miners generate a block template, they select most transactions from their mempool with one exception. Each miner creates their own coinbase transaction. The coinbase transaction pays out the block reward—and if a miner finds a valid block, they want to pay themselves! Since the Merkle root in the block header is a digest of all transactions in the block, and the coinbase transaction is hashed into the Merkle root, it follows that every miner has a unique block template, even if they are trying to confirm exactly the same transaction set other than the coinbase transaction.

Now, each miner generates block candidates by trying different nonces, extranonces, etc. This is not a stack of work that needs to be powered through, it is a progress-free "distributed lottery". As each block candidate is hashed, there is a tiny chance¹ that it may yield a valid block—completely independent of whether you have tried fifteen or a quintillion hashes before.

This means that:

  1. no work is ever "wasted", because every miner is working on unique block candidates, and there is no progress in the first place
  2. finding a valid block both determines the author of the newest block and the winner of the "lottery" for the corresponding block reward²

Consequently, it's in the successfully miner's interest to immediately broadcast their block far and wide. As nodes hear about the extended best chain, they converge on the new shared state of the network, update their UTXO sets and mempools. Miners update their block templates for the new height, and hash away.


¹about one in 93 sextillion these days
²except when two miners find blocks at the same height every three weeks or so, and only one can sire the best chain

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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