In all of the blockchain samples that I see e.g. adilmoujahid, Savjee as I checked, they added previous Hash by creating a block.

Suppose that, L is the current last block in a chain. Block A and B are created at the same time. So they set their previous hash with the same hash e.g. Hash of L.

What happens by mining when both of them are mined successfully, but B was mined faster.

Therefore normally previous hash of B is correct, but previous hash of A should be changed to the hash of B.

What I want to reach, I think assigning previous hash by creating a block is not necessary, but by mining. Am I right?

  • 3
    Does this answer your question? What happens if two miners mine the next block at the same time?
    – chytrik
    Dec 16, 2019 at 7:02
  • Thanks to mention that, that helped me to differ my situation from normal blockchain. I am working on arduino device for health care, that it cannot synch it self every time with main ledger. Because of that, Arduino just sing the data and send it without previous hash to the server. And my server as a miner verify the signature and add the hash of last block as previous hash. My solution is not proper for shared ledger, but because I am using individual ledger for each member there shouldn't be any conflict between transaction and member data
    – masoud2011
    Dec 18, 2019 at 12:58

2 Answers 2


A fork happens. If A and B are competing for the next block, they probably share transactions. So you cannot simply append A to B.

They're both valid blocks, nodes hold both of them until they hear about a new block that was built on top of either A or B. Let's say a node hears a new block C was built on top of B, that node will then disregard A because it isn't a part of the longest/heaviest chain. The transactions in A that are not in B are returned to the mempool to be mined in a new block.

The network reaches consensus by trusting the longest chain. This is why it is suggested to wait 6 confirmations for a transaction. This gives extremely high confidence that the network has reached consensus on your transaction and there is a very low probability that your transaction will be apart of a reorganization of the blockchain.

  • Blocks are not discarded if they’re not part of the main chain.
    – Claris
    Dec 15, 2019 at 23:00
  • 1
    @Anonymous when I refer to the stale block A being disregarded, I mean that it simply isn't part of the main chain. I said, "disregarded", because I was not sure what actually happened to it. Dec 16, 2019 at 9:53
  • They’re retained on disk just in case they become part of the main chain, it’s a minor distinction.
    – Claris
    Dec 16, 2019 at 15:02
  • 1
    @masoud2011 we’re actually talking about the same thing here and what you said in your first comment is correct. In this scenario it is just a one block fork and is generally resolved after the next block is mined. The fork you’re thinking of is like Bitcoin Cash. The difference is that there are miners building on the new branch, where as just working within Bitcoin’s blockchain the miners will only work on the longest chain (because of the reward). Dec 22, 2019 at 11:38
  • 2
    @masoud2011: The term "fork" appears in more than one context in Bitcoin. You can read more about forks here: bitcoin.stackexchange.com/q/30817/5406
    – Murch
    Dec 22, 2019 at 18:12

Each block commits to the previous block in the block header by including the previous block's hash. A block's hash is defined as the output of hashing the block header, and for a block to be valid, this hash must fulfill the current difficulty requirement. While blocks can have more than one child block, the Bitcoin network finally agrees on just one best chain. In the best chain there is only one block at each height, so while blocks can have multiple child blocks, only one of them will be relevant in the longterm.

Therefore normally previous hash of B is correct, but previous hash of A should be changed to the hash of B.

Firstly, changing even a single bit in the block header will cause the hash of the block header to come out differently (see e.g. Mastering Bitcoin (Ch8, section "Mining the Block")). It's astronomically unlikely that the new hash also fulfills the difficulty statement. Therefore, the modified block header would no longer represent a valid block.

Secondly, given that A and B were drawing on the same set of unconfirmed transactions when they were found, it's extremely likely that the transactions included in the blocks for confirmation have some overlap. However, each transaction can only be included in one block, because each transaction output can only be spent once, and therefore the inputs of a transaction that was already confirmed are no longer available in a later block. It follows that A would likely include invalid transactions if it were following B.

So, once both A and B were found, and both have each independently committed to block L as their predecessor as well as including some of the same transactions, the blocks A and B are competing to be part of the best chain and exclusive to each other.

  • An important problem that I have here, nobody talks with references, what you said here is wrong, please read here blog.goodaudience.com/… , We create identical hash with data inside the block. But previous hash is part of header of block, and changing in header of block doesn't make any change in hash of block.
    – masoud2011
    Dec 22, 2019 at 12:28
  • On the other hand please read here 99bitcoins.com/bitcoin/mempool . Most of the block in memory pool with lower fee will be delayed. Because they are priorities and transactions with more fee have more priority. That means previous hash of most of transaction with lower fee should be changed by mining. Because they should be added after transaction with higher fee, even if previous hash of lower fee is earlier than previous hash of higher fee
    – masoud2011
    Dec 22, 2019 at 12:38
  • 1
    Hi Masoud, "changing in header of block doesn't make any change in hash of block". Maybe that was a confusing. The block hash is the digest of the block header, so if one changes anything in a block header that block's hash will change and all subsequent blocks also need to change because they referred to that previous header directly or indirectly. (See e.g. Mastering Bitcoin oreilly.com/library/view/mastering-bitcoin/9781491902639/…
    – Murch
    Dec 22, 2019 at 18:05
  • Transaction hashes are only dependent on the content of the transaction. Mining a transaction doesn't change the transaction (that would invalidate the signature) or the transaction hash. The only thing that changes about the transaction is that it is now being referred to by a block, i.e. it's part of a Merkle tree whose Merkle root is part of a block header that's part of the best chain.
    – Murch
    Dec 22, 2019 at 18:09

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.