<p>Bitcoin is a distributed system. At any given time, there are <code>n</code> different representations of the network, where <code>n</code> is the number of nodes participating in the network. These nodes have a consensus protocol (defined by the Bitcoin specification) which allows each of the nodes to maintain a state consistent with all of the other nodes on the network. The consensus mechanism in Bitcoin is related to the chain of blocks (hence the namesake, "blockchain"), essentially, the longest chain wins.</p>

<p>Blocks can be created by any miner participating in the network, anywhere in the world. When a block is created it needs to be propagated across the entire network, to all <code>n</code> nodes in the world. This can take time, and there is a chance that a new block is created before this process completes. That new block could then get propagated to nodes which haven't heard of the prior block (think network locality). When this happens your network has a fork.</p>

<p>The way the consensus protocol deal with this fork is by seeing which version of the chain the next block is built on top of--that chain will then be 1 block longer than the other and the nodes that see this will consider this the main chain, and the true representation of the Bitcoin ledger.</p>

<p>Interesting cases can come in where there is a major segmentation of the network (say an intercontinental cable is severed and India drops off the internet). Different segments of the network will have a different understanding of the state of the Bitcoin ledger, and thus, could begin building a diverging set of chains. When networks are rejoined, nodes again regain consensus by comparing chain length and choosing the longes; the shorter chain's blocks become invalid.</p>

<p>As time goes on, the ability of a network segmentation unseating a chain is reduced--the likelihood your transactions are on an invalid chain (i.e. the likelihood there is a longer chain being mined by a different portion of a segmented network) goes to zero.</p>

CC BY-SA 4.0
2018-09-26T22:20:40.567Z
Thank you - very detailed. Where do you get such good information or understanding from? Looking for you to teach me how to fish for this sort of info.
Boon
CC BY-SA 4.0
2018-09-26T22:22:50.063Z
What about the part where a block can be reversed?
Boon
CC BY-SA 4.0
2018-09-26T22:32:38.807Z
@Boon By virtue of those blocks no longer being in the longest chain, those transactions are no longer considered valid. Therefore any coins spent in those invalid chains are available to be spent again. It's not about actually reversing blocks, it's that nodes no longer consider them valid.
Motoma
CC BY-SA 4.0
2018-09-26T22:40:46.317Z
@Boon I mined Bitcoin back in '11 and wrote Bitcoin apps in the years following. I've worked with Bitcoin, Ethereum, and a handful of other cryptocurrencies in the time since then. There's no one place I got this information, it's just built up over time.

If you are technically minded, or have some programming experience, I would point you to the excellent article "Learn Blockchains by Building One": https://hackernoon.com/learn-blockchains-by-building-one-117428612f46?gi=f16a96caa9eb
Motoma
CC BY-SA 4.0
2018-09-27T12:59:13.843Z
By saying the longest chain wins, does it mean the entire chain is broadcasted when a new block is mined? Isn’t that a lot of data?
Boon
CC BY-SA 4.0
2018-09-27T13:55:34.063Z
No, all node records each block that is broadcast; when a new block comes in it contains a reference to the block it builds on.
Motoma
CC BY-SA 4.0
2018-09-27T17:19:17.623Z
So when or where does "the longest chain wins" happen? Surely the node's current chain must be compared against something to know it is longer or shorter? Simply having the  previous hash reference can't give you that info.
Boon
CC BY-SA 4.0
2018-09-28T12:42:56.803Z
Consider the simple case of a chain with 4 blocks, in sequential order, 1->2->3->4. Block 5 could come in and be built off of block 4--in this case everything would proceed on its merry way. If block 5 came in instead on top of block 2, it would be recorded, but those transactions wouldn't be considered a valid part of the current networks state. If block 5 came on pointing at block 3 though, you'd have to wait for block 6 to come through; whichever block it built on (4 or 5) would then be considered the canonical chain.
Motoma
CC BY-SA 4.0
2018-09-26T21:54:17.423Z
2018-09-26T21:54:17.423Z
Motoma
<p>In Mastering Bitcoin, page 196, it says "While the protocol always allows a chain to be undone by a longer chain and while the possibility of any block being reversed always exists, the probability of such an event decreases as time passes..."</p>

<p>How and when will a chain be undone? How and when a block be reversed? Does Bitcoin core actually allow/support such operations?</p>

CC BY-SA 4.0
2018-09-26T21:49:05.170Z
Possible duplicate of [What can an attacker with 51% of hash power do?](https://bitcoin.stackexchange.com/questions/658/what-can-an-attacker-with-51-of-hash-power-do)
JBaczuk
CC BY-SA 4.0
2018-09-27T17:21:21.900Z
I am asking how and when it will be undone, 51% can be one way but not the only way, therefore it's not a dupe.
Boon
<bitcoin-core><blockchain>
Bitcoin protocol allows a chain to be undone by a longer chain
Boon
# Bitcoin protocol allows a chain to be undone by a longer chain

(Asked by: username_0 on 2018-09-26)

In Mastering Bitcoin, page 196, it says "While the protocol always allows a chain to be undone by a longer chain and while the possibility of any block being reversed always exists, the probability of such an event decreases as time passes..."

How and when will a chain be undone? How and when a block be reversed? Does Bitcoin core actually allow/support such operations?

**Tags:** bitcoin-core, blockchain

> **Comments:**
> **username_1**: Possible duplicate of [What can an attacker with 51% of hash power do?](https://bitcoin.stackexchange.com/questions/658/what-can-an-attacker-with-51-of-hash-power-do)  
> **username_0**: I am asking how and when it will be undone, 51% can be one way but not the only way, therefore it's not a dupe.  

---

## 1 answers

### Answer by username_2 on 2018-09-26. Score: 2 | Accepted answer

Bitcoin is a distributed system. At any given time, there are `n` different representations of the network, where `n` is the number of nodes participating in the network. These nodes have a consensus protocol (defined by the Bitcoin specification) which allows each of the nodes to maintain a state consistent with all of the other nodes on the network. The consensus mechanism in Bitcoin is related to the chain of blocks (hence the namesake, "blockchain"), essentially, the longest chain wins.

Blocks can be created by any miner participating in the network, anywhere in the world. When a block is created it needs to be propagated across the entire network, to all `n` nodes in the world. This can take time, and there is a chance that a new block is created before this process completes. That new block could then get propagated to nodes which haven't heard of the prior block (think network locality). When this happens your network has a fork.

The way the consensus protocol deal with this fork is by seeing which version of the chain the next block is built on top of--that chain will then be 1 block longer than the other and the nodes that see this will consider this the main chain, and the true representation of the Bitcoin ledger.

Interesting cases can come in where there is a major segmentation of the network (say an intercontinental cable is severed and India drops off the internet). Different segments of the network will have a different understanding of the state of the Bitcoin ledger, and thus, could begin building a diverging set of chains. When networks are rejoined, nodes again regain consensus by comparing chain length and choosing the longes; the shorter chain's blocks become invalid.

As time goes on, the ability of a network segmentation unseating a chain is reduced--the likelihood your transactions are on an invalid chain (i.e. the likelihood there is a longer chain being mined by a different portion of a segmented network) goes to zero.

> **Comments:**
> **username_0**: Thank you - very detailed. Where do you get such good information or understanding from? Looking for you to teach me how to fish for this sort of info.  
> **username_0**: What about the part where a block can be reversed?  
> **username_2**: @username_0 By virtue of those blocks no longer being in the longest chain, those transactions are no longer considered valid. Therefore any coins spent in those invalid chains are available to be spent again. It's not about actually reversing blocks, it's that nodes no longer consider them valid.  
> **username_2**: @username_0 I mined Bitcoin back in '11 and wrote Bitcoin apps in the years following. I've worked with Bitcoin, Ethereum, and a handful of other cryptocurrencies in the time since then. There's no one place I got this information, it's just built up over time.  If you are technically minded, or have some programming experience, I would point you to the excellent article "Learn Blockchains by Building One": https://hackernoon.com/learn-blockchains-by-building-one-117428612f46?gi=f16a96caa9eb  
> **username_0**: By saying the longest chain wins, does it mean the entire chain is broadcasted when a new block is mined? Isn’t that a lot of data?  
> **username_2**: No, all node records each block that is broadcast; when a new block comes in it contains a reference to the block it builds on.  
> **username_0**: So when or where does "the longest chain wins" happen? Surely the node's current chain must be compared against something to know it is longer or shorter? Simply having the  previous hash reference can't give you that info.  
> **username_2**: Consider the simple case of a chain with 4 blocks, in sequential order, 1->2->3->4. Block 5 could come in and be built off of block 4--in this case everything would proceed on its merry way. If block 5 came in instead on top of block 2, it would be recorded, but those transactions wouldn't be considered a valid part of the current networks state. If block 5 came on pointing at block 3 though, you'd have to wait for block 6 to come through; whichever block it built on (4 or 5) would then be considered the canonical chain.  

---

