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?

2

Do nodes store all the branches from entire blockchain history?

They will store all branches that they know of so long as the block headers of each branch are fully valid.

The way that Bitcoin Core nodes (and all node software based upon Bitcoin Core) work is that they will ask for an receive a block header before asking for the actual block itself. Using the headers, the node builds a headers chain. So if a block header is valid (i.e. it has a valid proof of work and connects to known previous block headers), it will be stored and added to the chainstate. In this way, a node can know of and keep track of all branches of the blockchain without having the block itself.

Even if a headers chain does not have the most work, it will still be kept around forever and kept track of. Although blocks for that headers chain will not be requested, if any peers have that chain as their actual blockchain and the headers are completely valid, it will still be known to a peer and kept track of.

If a headers chain suddenly begins having invalid block headers, the chain of valid headers will still be kept and tracked; the invalid headers extending that won't be.

  • 1
    But why would I keep track of "obsolete" branches? It is reasonable to track only the branch node is currently on. – croraf Oct 22 '17 at 17:18
  • 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 Oct 22 '17 at 17:22
  • 1
    But 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 Oct 22 '17 at 17:24
  • 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 Oct 22 '17 at 17:29
  • 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 Oct 22 '17 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.