1

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?

1
  • Maximum block size is 4MB actually.
    – Jannes
    Jul 28, 2023 at 0:53

3 Answers 3

2

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.

2
  • when is the hash calculated for a block in this process? Jul 28, 2023 at 0:37
  • 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. Jul 28, 2023 at 0:43
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

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

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.