1

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?

Boon
  • 123
  • 6

1 Answers1

2

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.

Motoma
  • 161
  • 6
  • 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 Sep 26 '18 at 22:20
  • What about the part where a block can be reversed? – Boon Sep 26 '18 at 22:22
  • @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 Sep 26 '18 at 22:32
  • @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 Sep 26 '18 at 22:40
  • 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 Sep 27 '18 at 12:59
  • 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 Sep 27 '18 at 13:55
  • 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 Sep 27 '18 at 17:19
  • 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 Sep 28 '18 at 12:42