7
1
Occasionally, a Bitcoin client will come across a fork of blocks that is longer than the chain it is currently on. Depending on how often orphaned blocks occur, this could be quite often. When this happens, any internal data structures relating to the "current" state of the blockchain (for example, a hashtable of unspent outputs) need to be updated to reflect the state of the new, longer fork.
How is this accomplished? Is history played "backwards" to the most recent common ancestor and then "forwards" to the new top block? Is it all just reconstructed from scratch?
Large reorganisations aren't assumed to be impossible, but they would certainly have a terrible effect if they occurred, as any transaction (recursively) that spends the coins generated in the reorganized chain will inevitable become invalid (and since the coinbases they originate from disappear, these cannot just be moved to the other chain, like other transactions in a reorganisations). – Pieter Wuille – 2013-09-26T23:12:29.030
I have corrected the original answer, thanks. – Anonymous – 2013-09-27T03:29:53.633
1
For those reading Anonymous's answer above, and noticed that his link to the Bitcoin source now points to something completely different (master has changed since then), the original reference was to this line which shows how Bitcoin Core steps back through transactions.
– XertroV – 2014-04-02T01:56:44.840Thanks. However, we do have a workflow for that: You can just click "edit" and correct a mistake, it will then be added to a review queue automatically. – Murch – 2014-04-02T08:06:00.043