I've been trying to learn Ethereum's mechanisms for a little while, but there is a thing I still don't understand and it is how nodes switch to the correct state when solving a fork.

As far as I understand it, there is a single state that is stored, which corresponds to the global state of the chain.

But in the case where a node has to give up a validated block in favor of a block with a longer chain, how exactly this node undo all transactions of the abandoned block to keep a correct state when executing the new blocks?

Let's say I validate a block A, but then I receive a block B followed by a block C, making it the longest chain. How do I go back to the state I had before processing A, in order to correctly process B and C?

2 Answers 2


Blockchain is a ledger, technically you could re-execute the entire chain up to a certain point and continue from there. Practically, there's a concept of checkpoints, in which case you would start re-execution from, for example, 128 blocks earlier. Up to each node to implement this to their liking.


There are multiple possible implementations.

One option since the ethereum world state is modeled as a patricia trie is to keep all state around. The changes between states are small so they won't waste too much space. The disadvantage is that in order to resolve any query you have to start from the current state and walk down the trie.

For example geth used to keep around the last state changes in memory and only flush to storage after a certain thresholds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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