<blockquote>
<p><strong>When a set of new transactions is broadcast ...</strong></p>
</blockquote>
<p><em>Individual</em> transactions get broadcast, not specific well-defined <em>sets</em>. That is, the identity or membership of a set of transactions is not preserved as data diffuses across the network.</p>
<blockquote>
<p><strong>... to all the Bitcoin mining pools,</strong></p>
</blockquote>
<p>The broadcast (as you would guess from that name) is sent to <em>nodes in general</em> 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.</p>
<blockquote>
<p><strong>my understanding is that they all start working on a new block to include all those transactions.</strong></p>
</blockquote>
<p>No, there is <em>no synchronisation</em> between different mining pools. each pool can be working on <em>different</em> sets of transactions. The sets might overlap or be distinct.</p>
<blockquote>
<p><strong>But how is it agreed upon which block is the next one to be included in the Bitcoin blockchain?</strong></p>
</blockquote>
<p>First one to find a valid block wins.</p>
<blockquote>
<p><strong>Is it just the first mining pool to generate the block?</strong></p>
</blockquote>
<p>Yes.</p>
<p>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.</p>
<blockquote>
<p><strong>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?</strong></p>
</blockquote>
<p>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.</p>
<p>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.</p>

CC BY-SA 4.0
2021-01-26T23:20:12.037Z
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
CC BY-SA 4.0
2021-01-26T23:43:08.790Z
@sanket1729: Done. Thanks for the feedback.
RedGrittyBrick
CC BY-SA 4.0
2021-01-27T01:11:09.683Z
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.
David Schwartz
CC BY-SA 4.0
2021-01-27T02:49:26.440Z
@DavidSchwartz, agreed. The answer could use more clarification that "in the long run, you cannot have only successful tries without having failed attempts".
sanket1729
CC BY-SA 4.0
2021-01-10T14:09:34.137Z
2021-01-26T23:42:49.393Z
2021-01-26T23:42:49.393Z
RedGrittyBrick
<p>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.</p>
<p>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.</p>
<p>When the target is satisfied, the block is published. From then on, no one can change the transactions in the block.</p>
<blockquote>
<p>all that work is wasted</p>
</blockquote>
<p>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.</p>
<p>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):</p>
<ul>
<li>After about how many blocks will someone find a block if everyone started just now: 10 minutes (t = 10)</li>
<li>What if you all had been mining for 2 minutes? Still 10 minutes (block to be released at t = 12)</li>
<li>What if you all had been mining for 20 minutes? Still 10 minutes (block to be released at t = 30)</li>
</ul>
<p>Here's a fun puzzle by <a href="https://twitter.com/pwuille/status/968241292189761536" rel="nofollow noreferrer">Russel O'Connor and Pieter Wuille</a>.</p>
<p>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.</p>

CC BY-SA 4.0
2021-01-10T10:35:03.213Z
2021-01-10T10:35:03.213Z
MCCCS
<p>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 <strong>unique</strong> block template, even if they are trying to confirm exactly the same transaction set other than the coinbase transaction.</p>
<p>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 &quot;distributed lottery&quot;. 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.</p>
<p>This means that:</p>
<ol>
<li><strong>no work is ever &quot;wasted&quot;</strong>, because every miner is working on unique block candidates, and there is no progress in the first place</li>
<li><strong>finding a valid block</strong> both determines the author of the newest block and the winner of the &quot;lottery&quot; for the corresponding block reward²</li>
</ol>
<p>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.</p>
<hr />
<p><sub>¹about one in 93 sextillion these days</sub><br />
<sub>²except when two miners find blocks at the same height every three weeks or so, and only one can sire the best chain</sub></p>

CC BY-SA 4.0
2021-01-26T22:47:20.497Z
2021-01-26T22:47:20.497Z
Murch
<p>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?</p>

CC BY-SA 4.0
2021-01-26T22:16:45.713Z
Related: https://bitcoin.stackexchange.com/q/36192/5406, https://bitcoin.stackexchange.com/a/101746/5406, https://bitcoin.stackexchange.com/a/3942/5406
Murch
<mining-theory><best-chain>
How does a Bitcoin block get generated and 'agreed upon' by everyone?
Jez
# How does a Bitcoin block get generated and 'agreed upon' by everyone?

(Asked by: username_0 on 2021-01-10)

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?

**Tags:** mining-theory, best-chain

> **Comments:**
> **username_1**: Related: https://bitcoin.stackexchange.com/q/36192/5406, https://bitcoin.stackexchange.com/a/101746/5406, https://bitcoin.stackexchange.com/a/3942/5406  

---

## 3 answers

### Answer by username_2 on 2021-01-10. Score: 1 | Accepted answer

> **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.

> **Comments:**
> **username_3**: I agree the answer is correct. @RedGrifftyBrik, I think we should remove the AFAIK part from the answer to make it sound more assuring.  
> **username_2**: @username_3: Done. Thanks for the feedback.  
> **username_4**: 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.  
> **username_3**: @username_4, agreed. The answer could use more clarification that "in the long run, you cannot have only successful tries without having failed attempts".  

---

### Answer by username_5 on 2021-01-10. Score: 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](https://twitter.com/pwuille/status/968241292189761536).

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.


---

### Answer by username_1 on 2021-01-26. Score: 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


---

