<blockquote>
  <p>Do nodes store all the branches from entire blockchain history?</p>
</blockquote>

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

<p>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.</p>

<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2017-10-22T17:18:00.573Z
But why would I keep track of "obsolete" branches? It is reasonable to track only the branch node is currently on.
croraf
CC BY-SA 3.0
2017-10-22T17:22:38.997Z
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.
Ava Chow
CC BY-SA 3.0
2017-10-22T17:24:58.827Z
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
CC BY-SA 3.0
2017-10-22T17:29:01.060Z
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.
Ava Chow
CC BY-SA 3.0
2017-10-22T17:31:35.063Z
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
CC BY-SA 3.0
2017-10-22T17:37:35.200Z
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.
Ava Chow
CC BY-SA 3.0
2017-10-22T17:38:31.780Z
Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/67474/discussion-between-croraf-and-andrew-chow).
croraf
CC BY-SA 3.0
2017-10-22T17:11:18.720Z
2017-10-22T17:11:18.720Z
Ava Chow
<p>Forks are possible when mining the blockchain and happen "all the time" during mining.</p>

<p>This means the nodes monitoring the blockchain have recorded many forks during blockchain's lifetime, with some of non-main branches long several blocks.</p>

<p>Do nodes store all the branches from entire blockchain history? </p>

<p>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?</p>

<blockchain><bitcoin-core><algorithms>
Does full node store all valid forks and "alternative" blocks from blockchain history?
croraf
# Does full node store all valid forks and "alternative" blocks from blockchain history?

(Asked by: username_0 on 2017-10-22)

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?

**Tags:** blockchain, bitcoin-core, algorithms


---

## 1 answers

### Answer by username_1 on 2017-10-22. Score: 2 | Accepted answer

> 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.

> **Comments:**
> **username_0**: But why would I keep track of "obsolete" branches? It is reasonable to track only the branch node is currently on.  
> **username_1**: 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.  
> **username_0**: 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).  
> **username_1**: 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.  
> **username_0**: 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).  
> **username_1**: 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.  
> **username_0**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/67474/discussion-between-username_0-and-andrew-chow).  

---

