<blockquote>
<p>In one reading I have read, Only longest chain is valid and and rest chains transactions are sent back to unconfirmed transactions, but in bitcoin blockchain how more than 2 chains(Side Chains) co-exist together? There should be only 1 single valid chain right ?</p>
</blockquote>
<p>From the point of view of the side chain, blocks in the main chain are not blocks at all, they're meaningless garbage because they don't follow the side chain's rules. From the point of view of the main chain, blocks in the side chain are not blocks at all because they don't follow all the main chain's rule.</p>
<p>In short, if there is more than one persistent distinct chain, it can only be because the two chains follow different rules.</p>
<blockquote>
<p>If a honest miner has a double spent transaction in his block, which was done by some malicious person, honest miner after broadcasting his block, his block will be rejected because he has double spent transaction of some other malicious person, where this is not miner's fault. How miner is this problem solved?</p>
</blockquote>
<p>An honest miner would never include a double spend in his block.</p>
<blockquote>
<p>If only longest chain is valid, after how many blocks in small chain transactions are discarded and sent back to unconfirmed pool?</p>
</blockquote>
<p>From the point of view of a longer chain that doesn't include those transactions, if they are valid in that chain, they are considered unconfirmed. From the point of view of any particular chain, any valid transaction not included in that chain is considered unconfirmed to long as it remains neither included nor conflicted due to inclusion of a conflicting transaction.</p>
<blockquote>
<p>If attacker tried to double spend and somehow tried to surpass the valid chain, how to deal with this problem?</p>
</blockquote>
<p>A chain with a double spend in it can never be valid because double spends are against the chain rules. Such a &quot;chain&quot; is treated no differently from random garbage.</p>

CC BY-SA 4.0
2022-07-20T07:13:43.653Z
Blocks in main chain are not valid in side chain and vice versa that is okay, but my doubt is "If only longest chain is taken into consideration and short chain is sent back to unconfirmed transactions(un technically deleting short chain) why there are other chains in bitcoin, there should be only 1 single chain right?"
Arjun Reddy
CC BY-SA 4.0
2022-07-20T14:11:25.690Z
@ArjunReddy What do you mean by "other chains" exactly? There only is one bitcoin chain. A side chain is not the bitcoin blockchain which has only one chain.
David Schwartz
CC BY-SA 4.0
2022-07-20T15:44:45.027Z
Sorry, My bad I had interpreted something wrong about side chain. Thank you for information :)
Arjun Reddy
CC BY-SA 4.0
2022-07-19T05:55:23.233Z
2022-07-19T05:55:23.233Z
David Schwartz
<h2>Blockchain forks, chain reorganizations, and stale blocks</h2>
<p>You're mixing up a few separate concepts. Since there is no central coordination, occasionally two miners will randomly find a new block at the same time. As each of the competing blocks is seen first by some nodes and they both have the same amount of total chainwork, the network briefly disagrees on what the best chaintip is. Let's say the blockheight is 500 and the blocks are 500_A and 500_B.</p>
<p>Naturally the two competing blocks include much of the same transactions, since both miners were seeing the same unconfirmed transactions and picked whatever provided the most transaction fees. Perhaps there is even a transaction in block 500_A that conflicts with a transaction in block 500_B.</p>
<p>However, the best chain can only have one block at height 500! From the perspective of nodes that saw the 500_A first, the other block, 500_B, is not part of the best chain and doesn't count. From the perspective of the nodes that saw 500_B first, 500_A is not part of the best chain and doesn't count.</p>
<p>Eventually, another block is found. Let's say it is 501_A and builds on top of 500_A. As the chain-tip consisting of 500_A+501_A is now longer and has more work than the chain-tip 500_B, the tie is broken and every node recognizes the same best chain. The nodes that were already following that chain-tip with 500_A simply add the new block 501_A. The ones that had seen the block 500_B first <em>reorganize</em> to the new best chain-tip by reverting block 500_B, then applying 500_A and 501_A. We call the block 500_B which does not become part of the best chain a <em>stale block</em>. From the perspective of the best chain, it does not matter whether the stale block was ever found. It's not part of the best chain.</p>
<h2>Sidechains</h2>
<p><a href="https://bitcoin.stackexchange.com/q/49943/5406">Sidechains</a> are <em>distinct other</em> blockchain networks that are pegged to the Bitcoin blockchain. They can use different consensus mechanisms, allow other rules, and have specialized purposes such as more private ways of transacting or enabling additional smart contract functionality. Examples for sidechains include Liquid, and RSK.</p>
<h2>&quot;An honest miner includes a doublespend in his block&quot;</h2>
<p>In Bitcoin we track every spendable amount of bitcoin separately in the form of <em>unspent transaction outputs (UTXOs)</em>. Every transaction output is uniquely identifiable. When creating a transaction, the transaction explicitly specifies which UTXOs it spends. Each transaction output can be spent only once.</p>
<p>A doublespend is an attempt to spend the same transaction output twice. Such an attempt could for example entail creating a transaction that spends the UTXO to send Alice money, and a second transaction that spends the same UTXO to send money to the attacker. The attacker then shows Alice the transaction sending money to Alice, but tries to get the transaction that returns the money to themselves included in a block instead. Since these two transactions conflict with each other, they can never be included in the same transaction history, let alone in one block.</p>
<p><a href="https://bitcoin.stackexchange.com/a/114449/5406">An honest node validates all unconfirmed transactions they hear about before adding them to their own mempool.</a> A miner builds their block template from their mempool. An honest miner would <a href="https://bitcoin.stackexchange.com/a/114442/5406">never have two conflicting transactions in their mempool at the same time</a>, and therefore would never include them both in the same block, because they would notice that the UTXO is already spent when validating the second transaction of the conflicting pair before accepting the transaction to their mempool.</p>
<p>If a miner does not validate transactions before building blocks, and they end up producing an invalid block, it <strong>is their fault</strong> for not following the consensus rules.</p>
<h2>No honest network participant accepts invalid blocks</h2>
<p>Transactions that spend money that has been spent before are invalid. Blocks that include invalid transactions are invalid. Nodes do not accept invalid blocks. An attacker that tries to broadcast an invalid block is simply banned and ignored.</p>

CC BY-SA 4.0
2022-07-18T19:53:51.280Z
2022-07-20T02:29:05.713Z
2022-07-20T02:29:05.713Z
Murch
<blockquote>
<p>Only longest chain is valid</p>
</blockquote>
<p>There can briefly exist multiple equally long chains. Eventually one of them wins.</p>
<blockquote>
<p>where this is not miner's fault</p>
</blockquote>
<p>It's always the miner's fault too, because he could've validated what he was mining.</p>
<blockquote>
<p>after how many blocks in small chain transactions are discarded</p>
</blockquote>
<p>In the moment the longer chain is detected, all the transactions from the &quot;short chain&quot; are put into the memory pool. After that the longest chain absorbs the transactions (that it confirms) from the memory pool.</p>
<blockquote>
<p>tried to double spend and somehow tried to surpass the valid chain</p>
</blockquote>
<p>chain containing a double spend is never valid (no matter how long it is).</p>

CC BY-SA 4.0
2022-07-17T09:27:21.523Z
2022-07-17T09:27:21.523Z
Hugo Franklin
<p>I am not able to understand, how 2 chains co-exist together, like these were the observations which are ambiguity for me:</p>
<ul>
<li>In one reading I have read, Only longest chain is valid and and rest chains transactions are sent back to unconfirmed transactions, but in bitcoin blockchain how more than 2 chains(Side Chains) co-exist together? There should be only 1 single valid chain right ?</li>
<li>If a honest miner has a double spent transaction in his block, which was done by some malicious person, honest miner after broadcasting his block, his block will be rejected because he has double spent transaction of some other malicious person, where this is not miner's fault. How miner is this problem solved?</li>
<li>If only longest chain is valid, after how many blocks in small chain transactions are discarded and sent back to unconfirmed pool?</li>
<li>If attacker tried to double spend and somehow tried to surpass the valid chain, how to deal with this problem?</li>
</ul>

CC BY-SA 4.0
2022-07-18T19:59:26.117Z
Hi Arjun Reddy, as I wrote earlier, please only ask one question per topic. Also, I'm confused about your repeated questions about doublespends. I thought I had explained this twice before, but it seems that there is an underlying assumption that I keep missing. You do realize that there is only one block at each height in the best chain? Perhaps this topic will help: https://bitcoin.stackexchange.com/q/12427/5406?
Murch
CC BY-SA 4.0
2022-07-20T06:55:38.207Z
Sorry Murch, I will make sure not to repeat again and ask a one question per topic
Arjun Reddy
<bitcoin-core><transactions><blockchain><doublespend>
How 2 chains co-exist together?
Arjun Reddy
# How 2 chains co-exist together?

(Asked by: username_0 on 2022-07-17)

I am not able to understand, how 2 chains co-exist together, like these were the observations which are ambiguity for me:

* In one reading I have read, Only longest chain is valid and and rest chains transactions are sent back to unconfirmed transactions, but in bitcoin blockchain how more than 2 chains(Side Chains) co-exist together? There should be only 1 single valid chain right ?
* If a honest miner has a double spent transaction in his block, which was done by some malicious person, honest miner after broadcasting his block, his block will be rejected because he has double spent transaction of some other malicious person, where this is not miner's fault. How miner is this problem solved?
* If only longest chain is valid, after how many blocks in small chain transactions are discarded and sent back to unconfirmed pool?
* If attacker tried to double spend and somehow tried to surpass the valid chain, how to deal with this problem?

**Tags:** bitcoin-core, transactions, blockchain, doublespend

> **Comments:**
> **username_1**: Hi username_0 username_0, as I wrote earlier, please only ask one question per topic. Also, I'm confused about your repeated questions about doublespends. I thought I had explained this twice before, but it seems that there is an underlying assumption that I keep missing. You do realize that there is only one block at each height in the best chain? Perhaps this topic will help: https://bitcoin.stackexchange.com/q/12427/5406?  
> **username_0**: Sorry username_1, I will make sure not to repeat again and ask a one question per topic  

---

## 3 answers

### Answer by username_2 on 2022-07-19. Score: 3

> In one reading I have read, Only longest chain is valid and and rest chains transactions are sent back to unconfirmed transactions, but in bitcoin blockchain how more than 2 chains(Side Chains) co-exist together? There should be only 1 single valid chain right ?

From the point of view of the side chain, blocks in the main chain are not blocks at all, they're meaningless garbage because they don't follow the side chain's rules. From the point of view of the main chain, blocks in the side chain are not blocks at all because they don't follow all the main chain's rule.

In short, if there is more than one persistent distinct chain, it can only be because the two chains follow different rules.

> If a honest miner has a double spent transaction in his block, which was done by some malicious person, honest miner after broadcasting his block, his block will be rejected because he has double spent transaction of some other malicious person, where this is not miner's fault. How miner is this problem solved?

An honest miner would never include a double spend in his block.

> If only longest chain is valid, after how many blocks in small chain transactions are discarded and sent back to unconfirmed pool?

From the point of view of a longer chain that doesn't include those transactions, if they are valid in that chain, they are considered unconfirmed. From the point of view of any particular chain, any valid transaction not included in that chain is considered unconfirmed to long as it remains neither included nor conflicted due to inclusion of a conflicting transaction.

> If attacker tried to double spend and somehow tried to surpass the valid chain, how to deal with this problem?

A chain with a double spend in it can never be valid because double spends are against the chain rules. Such a "chain" is treated no differently from random garbage.

> **Comments:**
> **username_0**: Blocks in main chain are not valid in side chain and vice versa that is okay, but my doubt is "If only longest chain is taken into consideration and short chain is sent back to unconfirmed transactions(un technically deleting short chain) why there are other chains in bitcoin, there should be only 1 single chain right?"  
> **username_2**: @username_0 What do you mean by "other chains" exactly? There only is one bitcoin chain. A side chain is not the bitcoin blockchain which has only one chain.  
> **username_0**: Sorry, My bad I had interpreted something wrong about side chain. Thank you for information :)  

---

### Answer by username_1 on 2022-07-18. Score: 2

## Blockchain forks, chain reorganizations, and stale blocks

You're mixing up a few separate concepts. Since there is no central coordination, occasionally two miners will randomly find a new block at the same time. As each of the competing blocks is seen first by some nodes and they both have the same amount of total chainwork, the network briefly disagrees on what the best chaintip is. Let's say the blockheight is 500 and the blocks are 500\_A and 500\_B.

Naturally the two competing blocks include much of the same transactions, since both miners were seeing the same unconfirmed transactions and picked whatever provided the most transaction fees. Perhaps there is even a transaction in block 500\_A that conflicts with a transaction in block 500\_B.

However, the best chain can only have one block at height 500! From the perspective of nodes that saw the 500\_A first, the other block, 500\_B, is not part of the best chain and doesn't count. From the perspective of the nodes that saw 500\_B first, 500\_A is not part of the best chain and doesn't count.

Eventually, another block is found. Let's say it is 501\_A and builds on top of 500\_A. As the chain-tip consisting of 500\_A+501\_A is now longer and has more work than the chain-tip 500\_B, the tie is broken and every node recognizes the same best chain. The nodes that were already following that chain-tip with 500\_A simply add the new block 501\_A. The ones that had seen the block 500\_B first *reorganize* to the new best chain-tip by reverting block 500\_B, then applying 500\_A and 501\_A. We call the block 500\_B which does not become part of the best chain a *stale block*. From the perspective of the best chain, it does not matter whether the stale block was ever found. It's not part of the best chain.

## Sidechains

[Sidechains](https://bitcoin.stackexchange.com/q/49943/5406) are *distinct other* blockchain networks that are pegged to the Bitcoin blockchain. They can use different consensus mechanisms, allow other rules, and have specialized purposes such as more private ways of transacting or enabling additional smart contract functionality. Examples for sidechains include Liquid, and RSK.

## "An honest miner includes a doublespend in his block"

In Bitcoin we track every spendable amount of bitcoin separately in the form of *unspent transaction outputs (UTXOs)*. Every transaction output is uniquely identifiable. When creating a transaction, the transaction explicitly specifies which UTXOs it spends. Each transaction output can be spent only once.

A doublespend is an attempt to spend the same transaction output twice. Such an attempt could for example entail creating a transaction that spends the UTXO to send Alice money, and a second transaction that spends the same UTXO to send money to the attacker. The attacker then shows Alice the transaction sending money to Alice, but tries to get the transaction that returns the money to themselves included in a block instead. Since these two transactions conflict with each other, they can never be included in the same transaction history, let alone in one block.

[An honest node validates all unconfirmed transactions they hear about before adding them to their own mempool.](https://bitcoin.stackexchange.com/a/114449/5406) A miner builds their block template from their mempool. An honest miner would [never have two conflicting transactions in their mempool at the same time](https://bitcoin.stackexchange.com/a/114442/5406), and therefore would never include them both in the same block, because they would notice that the UTXO is already spent when validating the second transaction of the conflicting pair before accepting the transaction to their mempool.

If a miner does not validate transactions before building blocks, and they end up producing an invalid block, it **is their fault** for not following the consensus rules.

## No honest network participant accepts invalid blocks

Transactions that spend money that has been spent before are invalid. Blocks that include invalid transactions are invalid. Nodes do not accept invalid blocks. An attacker that tries to broadcast an invalid block is simply banned and ignored.


---

### Answer by username_3 on 2022-07-17. Score: 0

> Only longest chain is valid

There can briefly exist multiple equally long chains. Eventually one of them wins.

> where this is not miner's fault

It's always the miner's fault too, because he could've validated what he was mining.

> after how many blocks in small chain transactions are discarded

In the moment the longer chain is detected, all the transactions from the "short chain" are put into the memory pool. After that the longest chain absorbs the transactions (that it confirms) from the memory pool.

> tried to double spend and somehow tried to surpass the valid chain

chain containing a double spend is never valid (no matter how long it is).


---

