1/6

A block's parent hash, not its height, tells you whether it extends your chain.

genesis - a1 - a2 - a3 - a4 - a5          <- indexed head
               \
                b3 - b4 - b5 - b6         <- arrives, parent = a2

b3 arrives at height 3 while the head is a5. On height alone that looks like a duplicate, or a feed that jumped backwards. On parent it is unambiguous: it forks below the head, so three blocks of yours are now orphaned.

Rollback runs head-downwards, applying the inverse of each block's effect, and stops at the fork point. Reverse order matters the moment effects stop commuting; unwinding forwards produces a store that no branch ever had.