<p>Every node in the network has a <code>mempool</code>. The <code>mempool</code> contains unconfirmed transactions. Each <code>mempool</code> may be slightly different as they constitute a subset of all unconfirmed transactions in the network: Some might not have been relayed to a node, so he doesn't know about them, the node owner has set a higher <code>minTxRelayFee</code> and filtered out some transactions with low fee, or the node owner has set a smaller data limit for his <code>mempool</code>.</p>

<p>Anyway, all of the above is also true for any miner's node. When miners are trying to find a block, they select a set of transactions to confirm from their <code>mempool</code>. From these transactions, they build a Merkle tree. 
The Merkle tree allows the whole transaction data to be represented by only the <a href="https://bitcoin.stackexchange.com/questions/10479/what-is-the-merkle-root">Merkle root</a>. This Merkle root is part of the block header.<br>
Miners get to choose which transactions to include freely, and they can also put them in any order they want, as long as the transactions are valid. Since there are now often more transactions available for confirmation than block space, miners usually select transactions that maximize the fees that the miner can earn.</p>

<p>So, miners have selected some transactions and created a Merkle tree to contain them. They combine this with the other parts of the block header: Time-stamp, Reference to previous block, difficulty statement, and the <code>nonce</code>. The <a href="https://en.wikipedia.org/wiki/Cryptographic_nonce" rel="nofollow noreferrer"><code>nonce</code></a> is an arbitrary number, so miners can build a block candidate with all the other data and then try this candidate a lot of times by cycling through all possible values for the nonce.<br>
Every try they put the block header into the hashing algorithm and receive a digest or hash of the data. If this hash satisfies the difficulty statement, the miner has found a new block and will relay it to the network.</p>

CC BY-SA 3.0
2016-08-07T18:56:13.453Z
2016-08-07T19:03:00.240Z
2017-04-13T12:47:33.610Z
Murch
<p>So I've been reading about how the nonce is calculated. There is one part that I don't get. So there is a mempool, and each node (or mining node) takes a part (or the whole part) of that mempool, computes a <a href="https://bitcoin.stackexchange.com/questions/10479/what-is-the-merkle-root">merkle root</a> and combines it with a nonce to get a hash that has a certain difficulty level. </p>

<p>Is the mempool (or part of it) is first converted to a hash by the mining software, then enters the nonce calculation?</p>

<p>Are there requirements on how the transactions are ordered when mining a block?</p>

<p>Can nodes choose the order of transactions in a block? Is a node free to choose any order of the transactions that it wants or must it be chosen chronologically?</p>

<p>(feel free to edit the question, I tried to explain it the best I could)</p>

<blockchain><mining-theory><block-header><transaction-selection><nonce>
How is the mempool incorporated in the calculation of the block hash?
Mostafa Zamani
# How is the mempool incorporated in the calculation of the block hash?

(Asked by: username_0 on 2016-08-07)

So I've been reading about how the nonce is calculated. There is one part that I don't get. So there is a mempool, and each node (or mining node) takes a part (or the whole part) of that mempool, computes a [merkle root](https://bitcoin.stackexchange.com/questions/10479/what-is-the-merkle-root) and combines it with a nonce to get a hash that has a certain difficulty level.

Is the mempool (or part of it) is first converted to a hash by the mining software, then enters the nonce calculation?

Are there requirements on how the transactions are ordered when mining a block?

Can nodes choose the order of transactions in a block? Is a node free to choose any order of the transactions that it wants or must it be chosen chronologically?

(feel free to edit the question, I tried to explain it the best I could)

**Tags:** blockchain, mining-theory, block-header, transaction-selection, nonce


---

## 1 answers

### Answer by username_1 on 2016-08-07. Score: 4 | Accepted answer

Every node in the network has a `mempool`. The `mempool` contains unconfirmed transactions. Each `mempool` may be slightly different as they constitute a subset of all unconfirmed transactions in the network: Some might not have been relayed to a node, so he doesn't know about them, the node owner has set a higher `minTxRelayFee` and filtered out some transactions with low fee, or the node owner has set a smaller data limit for his `mempool`.

Anyway, all of the above is also true for any miner's node. When miners are trying to find a block, they select a set of transactions to confirm from their `mempool`. From these transactions, they build a Merkle tree.
The Merkle tree allows the whole transaction data to be represented by only the [Merkle root](https://bitcoin.stackexchange.com/questions/10479/what-is-the-merkle-root). This Merkle root is part of the block header.  
Miners get to choose which transactions to include freely, and they can also put them in any order they want, as long as the transactions are valid. Since there are now often more transactions available for confirmation than block space, miners usually select transactions that maximize the fees that the miner can earn.

So, miners have selected some transactions and created a Merkle tree to contain them. They combine this with the other parts of the block header: Time-stamp, Reference to previous block, difficulty statement, and the `nonce`. The [`nonce`](https://en.wikipedia.org/wiki/Cryptographic_nonce) is an arbitrary number, so miners can build a block candidate with all the other data and then try this candidate a lot of times by cycling through all possible values for the nonce.  
Every try they put the block header into the hashing algorithm and receive a digest or hash of the data. If this hash satisfies the difficulty statement, the miner has found a new block and will relay it to the network.


---

