5
Forks are possible when mining the blockchain and happen "all the time" during mining.
This means the nodes monitoring the blockchain have recorded many forks during blockchain's lifetime, with some of non-main branches long several blocks.
Do nodes store all the branches from entire blockchain history?
EDIT: I read another question, and it is logical that the node should return the transactions from the "alternative" branch they were on to the memory pool (or discard them). But does this happen at the very same time when someone "shows" them longer branch, or they still somehow keep the alternative branches?
1But why would I keep track of "obsolete" branches? It is reasonable to track only the branch node is currently on. – croraf – 2017-10-22T17:18:00.573
Because those "obsolete branches" are completely valid and could potentially become the main chain one day. Without tracking those branches, we would be unable to reorg onto the chain with the most work in the event that we find ourselves on a chain with less work. – Andrew Chow – 2017-10-22T17:22:38.997
1But 99.99% of these branches are useless. And we don't need to track them at all. If any of them eventually becomes main chain the node can reconstruct it completely from the point it diverged (and can switch itself). – croraf – 2017-10-22T17:24:58.827
We don't know what point it diverged from. If you are suggesting that we build the chain by asking for the blocks from a peer, then that is easily DoS attackable. – Andrew Chow – 2017-10-22T17:29:01.060
I disagree. You ask from the peer that provided new block. If he fails to provide we stop. No DoS. Moreover the situation is the same as if we stay behind for couple of blocks from his branch (or even the main branch). – croraf – 2017-10-22T17:31:35.063
The attack is that a malicious peer can continuously tell you that he is using a different fork causing you to continuously request new blocks which take up more disk space, more CPU and RAM for validation, and more bandwidth. We don't know what the branches are, so we would have to take that peer's word for it and see if his branches are correct. By tracking all branches, we don't need to do that and we know what all the branches are and their current tips. – Andrew Chow – 2017-10-22T17:37:35.200
Let us continue this discussion in chat.
– croraf – 2017-10-22T17:38:31.780