<p>You can start to work in a block at any moment, you can even mine an empty block. If any new transaction arrives you rebuild the merkle tree and continue. </p>

CC BY-SA 4.0
2019-01-27T11:58:06.800Z
So there is a possibilty to choose how many transactions is ok to start minning? Will the adding new transaction to potential block reset the minning (reset the nonce to zero)?
Konrad
CC BY-SA 4.0
2019-10-02T18:46:14.697Z
One don't need to reset the nounce. One can choose any nounce in any order.
Osias Jota
CC BY-SA 4.0
2019-01-27T11:41:07.667Z
2019-01-27T11:41:07.667Z
Osias Jota
<p>While mining is done by specialized hardware, transaction choosing and merkle root calculating is done by the node software. While the specialized hardware is mining, a node may (and will) update its mempool continuously, and will calculate a new merkle root every few seconds. The mining hardware will check for header-template updates often, (and this instantaneous process is done without needing a restart), and will continue mining. The interval of header updates is chosen by the pool, and one of the aims is not to do it <em>too</em> often, or it'll waste the bandwidth</p>

CC BY-SA 4.0
2019-01-27T11:56:34.653Z
I'm not sure that I understand, I thougt that merkle tree is taken to the block, so updating list of transactions will somehow start minning again? (Reset the nonce to zero)
Konrad
CC BY-SA 4.0
2019-01-27T12:32:09.530Z
Yes, they can reset the nonce.
MCCCS
CC BY-SA 4.0
2019-01-27T13:20:49.507Z
So this will not complicate mining? I mean after reseting the nonce we are starting again so we are not as close to winning as we were before reseting the nonce (I guess)
Konrad
CC BY-SA 4.0
2019-01-27T15:15:52.687Z
No, reseting the nonce with a different block template is not repeating the same POW, as the header hash will be different with the same nonce. (Same nonce, but different merkle-root)
James C.
CC BY-SA 4.0
2019-01-28T00:45:16.450Z
Increase or decreasing a nounce don't make you any closer or far from finding a block. Otherwise you would just go straight to the highest nounce. Any order you try nounces is good.
Osias Jota
CC BY-SA 4.0
2019-01-27T11:41:23.793Z
2019-01-27T11:41:23.793Z
MCCCS
<p><strong>Producing the optimal block-template to mine is a NP-hard problem.</strong> </p>

<p>The optimal block-template includes the highest sat/byte(or weight) transactions to maximise the miner reward. Assuming this computation and propagation of the perfect block-template took no time, it would make sense to update the block-template for each new transaction accepted to the memo-pool, as this new transaction could potentially increase the block reward. In this hypothetical scenario, the mining hardware is continuously working (hashing) and continuously updating the block header for a better block reward.</p>

<p>However, since producing the optimal block-template is NP-hard, it takes significant time/cost to compute the optimal block-template from the mempool at any point in time:</p>

<ul>
<li>Knapsack problem - maximise total fee value in block</li>
<li>Maximum independent vertex set - ensure no two tx spend the same output.</li>
</ul>

<p>Both problems scale exponentially and are expensive. This cost could have been invested in more hash-rate.</p>

<p><strong>Therefore, there is a trade-off between block optimisation and mining utilization.</strong></p>

<ul>
<li>Continuously optimising for a better block-template represents a cost in itself, which could be invested in more mining hash rate.</li>
<li>There exists a financial optimum, where suboptimal blocks-templates are mined, whilst mining equipment is fully utilised. </li>
<li>(One extreme could be mining empty blocks, maximising the number of hashes performed, whilst spending zero resources in block optimisation.)</li>
<li>In practice, simplified heuristics are used to update new block-templates cost-effectively as mining is being performed.</li>
</ul>

CC BY-SA 4.0
2019-01-27T15:14:39.003Z
2019-01-27T15:14:39.003Z
James C.
<p>I have a question about getting transactions from mempool to be added to block. Imagine the situation where we have 500 transactions in mempool, when we decide that is enough to start adding them to the block? Also what if we sre in the middle of mining (so we have Merkles tree root already) and the new transaction is added to the mempool? The process of our mining in my node is starting again?</p>

<transactions><mempool>
Getting transactions from mempool to block
Konrad
# Getting transactions from mempool to block

(Asked by: username_0 on 2019-01-27)

I have a question about getting transactions from mempool to be added to block. Imagine the situation where we have 500 transactions in mempool, when we decide that is enough to start adding them to the block? Also what if we sre in the middle of mining (so we have Merkles tree root already) and the new transaction is added to the mempool? The process of our mining in my node is starting again?

**Tags:** transactions, mempool


---

## 3 answers

### Answer by username_1 on 2019-01-27. Score: 1

You can start to work in a block at any moment, you can even mine an empty block. If any new transaction arrives you rebuild the merkle tree and continue.

> **Comments:**
> **username_0**: So there is a possibilty to choose how many transactions is ok to start minning? Will the adding new transaction to potential block reset the minning (reset the nonce to zero)?  
> **username_1**: One don't need to reset the nounce. One can choose any nounce in any order.  

---

### Answer by username_2 on 2019-01-27. Score: 1

While mining is done by specialized hardware, transaction choosing and merkle root calculating is done by the node software. While the specialized hardware is mining, a node may (and will) update its mempool continuously, and will calculate a new merkle root every few seconds. The mining hardware will check for header-template updates often, (and this instantaneous process is done without needing a restart), and will continue mining. The interval of header updates is chosen by the pool, and one of the aims is not to do it *too* often, or it'll waste the bandwidth

> **Comments:**
> **username_0**: I'm not sure that I understand, I thougt that merkle tree is taken to the block, so updating list of transactions will somehow start minning again? (Reset the nonce to zero)  
> **username_2**: Yes, they can reset the nonce.  
> **username_0**: So this will not complicate mining? I mean after reseting the nonce we are starting again so we are not as close to winning as we were before reseting the nonce (I guess)  
> **username_3**: No, reseting the nonce with a different block template is not repeating the same POW, as the header hash will be different with the same nonce. (Same nonce, but different merkle-root)  
> **username_1**: Increase or decreasing a nounce don't make you any closer or far from finding a block. Otherwise you would just go straight to the highest nounce. Any order you try nounces is good.  

---

### Answer by username_3 on 2019-01-27. Score: 1

**Producing the optimal block-template to mine is a NP-hard problem.**

The optimal block-template includes the highest sat/byte(or weight) transactions to maximise the miner reward. Assuming this computation and propagation of the perfect block-template took no time, it would make sense to update the block-template for each new transaction accepted to the memo-pool, as this new transaction could potentially increase the block reward. In this hypothetical scenario, the mining hardware is continuously working (hashing) and continuously updating the block header for a better block reward.

However, since producing the optimal block-template is NP-hard, it takes significant time/cost to compute the optimal block-template from the mempool at any point in time:

* Knapsack problem - maximise total fee value in block
* Maximum independent vertex set - ensure no two tx spend the same output.

Both problems scale exponentially and are expensive. This cost could have been invested in more hash-rate.

**Therefore, there is a trade-off between block optimisation and mining utilization.**

* Continuously optimising for a better block-template represents a cost in itself, which could be invested in more mining hash rate.
* There exists a financial optimum, where suboptimal blocks-templates are mined, whilst mining equipment is fully utilised.
* (One extreme could be mining empty blocks, maximising the number of hashes performed, whilst spending zero resources in block optimisation.)
* In practice, simplified heuristics are used to update new block-templates cost-effectively as mining is being performed.


---

