Blockchain reorganization is the process of swapping blocks from the previous longest chain for the new longest chain blocks.
You must be familiar with the fundamentals of blockchain technology in order to understand chain reorganization. This involves looking into the many parts that make up the blockchain. We must also know that not every blockchain is the same.
Blockchains, for instance, use a variety of consensus processes, including proof-of-work (PoW) and proof-of-stake (PoS). But here, we won't be concentrating on consensus procedures. For the time being, be clear that a blockchain is a digital transaction ledger. It can be compared to a distributed database that is managed by a system of computers known as "nodes."
When your node receives new blocks that are a part of a new longest chain, the chain undergoes reorganisation (also known as "reorg"). In favour of the blocks that create the new longest chain, your node will deactivate the blocks in its previous longest chain.
Due to the fact that the accepted version of the blockchain will always be the one with the longest chain of blocks, this approach enables different nodes on the network to concur on the same version of the blockchain.
A great example would be a Mechanical Pencil. We all used Mechanical pencils in our childhood. When one of the blocks was overused or it gets old, we just removes it to add a new incoming graphite cartridge while we put the used cartridge on the tail of the pencil. That’s exactly what a Chain Reorganisation does.
Most commonly, a Blockchain reorganization happens after two blocks have been mined simultaneously.
Some nodes will receive the first block first and some nodes will receive the second block first depending on how quickly blocks propagate over the network. The question of which of these blocks is genuine "first" and therefore should be at the top of the blockchain will therefore be disputed.
It can be resolved instantly when the next block is mined. The following block that is mined will add to one of these blocks, producing a new longest chain. When nodes acquire this most recent block, they will each undertake a chain reorganization in order to adopt the new longest chain that it produces. Wherever the next mined block goes, it will confirm the presence of the ‘First’ block.
As a result of chain reorganizations, each node can independently agree on the same version of the blockchain as everyone else.
Let’s get back to the Mechanical pencil example. What will happen to the nib cartridge which is already used? It will be replaced by the new cartridge and the used one will go back to the tail to maintain the length of the pencil but if one tries to write with that graphite cartridge he/she won’t be able to do so because the nib has been used already. That is exactly what happens to the deactivated block.
When nodes choose a block, the other side is discarded. So, what happens to the blocks containing transactions on the opposite side of the chain? Because only transactions on the longest chain are included in the valid blockchain history, the remaining block(s) are deactivated. These are referred to as "orphan blocks."
What happens to the transactions in orphan blocks is the next question. Transactions within orphan blocks are no longer part of the blockchain's transaction history after a chain reorganization. As a result, they must be reassigned to new blocks.
However, there are no certainties. Because the transaction isn't in the active chain, it's as if it never existed. As a result, if a user attempts to transfer crypto within an orphan block, the nodes will reject the transaction. This is due to the fact that the user is attempting to spend an asset that does not exist on the valid chain.
Chain reorganizations are an entirely typical element of the operation of a Bitcoin node. Adopting the longest known chain allows nodes throughout a network to agree on the same blockchain, and chain reorganizations are just one component of this process.
Transactions within blocks that are deactivated due to chain reorganization become invalid, although they are recycled into the memory pool for the chance to be mined into a block on the new longest chain.