In a reorg where a node receives blocks for a longer or equal-length chain than the chain they previously followed as longest, what is the process for that node to handle this situation?
I can imagine that in the situation the new chain is clearly longer, the node would have to revert its UTXO set to the point at which the chains diverged, add back mempool transactions that were used since the chains diverged, and then re validate all blocks in the new chain. I can also imagine that some work that was already done in validating transactions could be reused, but not all of it.
How is the UTXO set reverted? Do nodes maintain a history of UTXO set diffs?
In the case where the length of the chains are not significantly different, I can imagine that a node might want to maintain both chains concurrently until it becomes clear one will be longer. Are nodes programmed to do this?
What is the longest reorg a node can handle without revalidating the entire chain from the genesis block?
These questions are primarily about how the software is currently written, rather than about theoretical ways nodes could handle these cases.