<p>Miners keep a pool of unconfirmed transactions (called &quot;mempool&quot;) which usually contains many more transactions that can fit in one block. When a new block is created, miners immediately remove that block's transactions from the mempool and fill a candidate block with a selection of the remaining transactions (usually in a way that maximizes fee revenue). This can easily take less than a second, during which miners either do nothing, or (more often) try to mine an empty block (to have a small chance of getting at least the block subsidy).</p>
<p>As new transactions keep coming in, miners keep updating their candidate block, replacing lower-feerate transactions with more lucrative ones. This can happen frequently, perhaps every few seconds.</p>

CC BY-SA 4.0
2023-07-28T00:37:23.920Z
when is the hash calculated for a block in this process?
Joey Yi Zhao
CC BY-SA 4.0
2023-07-28T00:43:28.293Z
The block hash is based on the block header, which includes the transaction merkle root, which depends on the list of transactions to be included in the block. So whenever that list changes, the merkle root needs to be recalculated.
Vojtěch Strnad
CC BY-SA 4.0
2023-07-28T00:06:52.393Z
2023-07-28T00:06:52.393Z
Vojtěch Strnad
<blockquote>
<p>the hash value could be changed very frequently until the block finished?</p>
</blockquote>
<p>Even if no new transactions were arriving and the set of transactions was unchanging, the hash value would be changing trillions of times each second as the miner searches for nonce values that produce a sufficiently small hash.</p>
<p>Hash value changing frequently during mining is normal</p>

CC BY-SA 4.0
2023-07-28T07:56:47.050Z
2023-07-28T12:49:07.683Z
2023-07-28T12:49:07.683Z
RedGrittyBrick
<p>When a new block is created and transactions are added, the block's header hash needs to be recalculated for each change. Miners continuously modify a field called the &quot;nonce&quot; to find a valid hash that meets the network's requirements. Once a valid hash is found, the block is added to the blockchain. The process can take time, but the difficulty adjusts to maintain a consistent block creation rate.</p>

CC BY-SA 4.0
2023-07-28T06:51:02.903Z
2023-07-28T06:51:02.903Z
Mani T
<p>I know that a block in a chain has <code>prev.hash</code> and <code>hash</code>. The <code>prev.hash</code> is the previous block's hash. The <code>hash</code> is the current block's hash which is calculated based on <code>nonce</code>.</p>
<p>One block can also have up to 1MB data which could include hundreds of transactions. My question is when a new block is created and start getting transactions, it could take a few minutes to fill in 1MB data. How does the <code>hash</code> work in this progress? Does the hash need to be calculated for every transaction added in the block? so the hash value could be changed very frequently until the block finished?</p>

CC BY-SA 4.0
2023-07-28T00:53:40.223Z
Maximum block size is 4MB actually.
Jannes
<blockchain><block-header>
How does hash work in a block for many transactions?
Joey Yi Zhao
# How does hash work in a block for many transactions?

(Asked by: username_0 on 2023-07-27)

I know that a block in a chain has `prev.hash` and `hash`. The `prev.hash` is the previous block's hash. The `hash` is the current block's hash which is calculated based on `nonce`.

One block can also have up to 1MB data which could include hundreds of transactions. My question is when a new block is created and start getting transactions, it could take a few minutes to fill in 1MB data. How does the `hash` work in this progress? Does the hash need to be calculated for every transaction added in the block? so the hash value could be changed very frequently until the block finished?

**Tags:** blockchain, block-header

> **Comments:**
> **username_1**: Maximum block size is 4MB actually.  

---

## 3 answers

### Answer by username_2 on 2023-07-28. Score: 2 | Accepted answer

Miners keep a pool of unconfirmed transactions (called "mempool") which usually contains many more transactions that can fit in one block. When a new block is created, miners immediately remove that block's transactions from the mempool and fill a candidate block with a selection of the remaining transactions (usually in a way that maximizes fee revenue). This can easily take less than a second, during which miners either do nothing, or (more often) try to mine an empty block (to have a small chance of getting at least the block subsidy).

As new transactions keep coming in, miners keep updating their candidate block, replacing lower-feerate transactions with more lucrative ones. This can happen frequently, perhaps every few seconds.

> **Comments:**
> **username_0**: when is the hash calculated for a block in this process?  
> **username_2**: The block hash is based on the block header, which includes the transaction merkle root, which depends on the list of transactions to be included in the block. So whenever that list changes, the merkle root needs to be recalculated.  

---

### Answer by username_3 on 2023-07-28. Score: 1

> the hash value could be changed very frequently until the block finished?

Even if no new transactions were arriving and the set of transactions was unchanging, the hash value would be changing trillions of times each second as the miner searches for nonce values that produce a sufficiently small hash.

Hash value changing frequently during mining is normal


---

### Answer by username_4 on 2023-07-28. Score: -2

When a new block is created and transactions are added, the block's header hash needs to be recalculated for each change. Miners continuously modify a field called the "nonce" to find a valid hash that meets the network's requirements. Once a valid hash is found, the block is added to the blockchain. The process can take time, but the difficulty adjusts to maintain a consistent block creation rate.


---

