## Description
The mechanism for automatic fork resolution is designed to prevent the existence of two or more active chains simultaneously in the network.
A **fork** is the emergence of side chains in the blockchain due to network desynchronization or software modifications. In such cases, it often becomes unclear which chain to trust.
In our blockchain, this issue is resolved quite simply:
> [!NOTE] Important
> The longest chain is considered the valid one.
At the same time, side chains (forks), when they occur, are only allowed for blocks whose *depth* does not exceed the maximum fork resolution depth. **Depth** refers to the position of a block relative to the latest block in the main chain.
The maximum fork resolution depth in our blockchain is **10 blocks**.
## Example
Let's consider an example of a fork occurring.
![[Pasted image 20250317174201 1.png]]
Normal blockchain state.
![[Pasted image 20250317210800.png]]
The fork occurs at block **`N+1`**. The depth of this block is **2** at now. This means that the fork resolution mechanism can be applied to it.
![[Pasted image 20250317210952.png]]
The side chain started from the block **`K`** is growing with new blocks.
![[Pasted image 20250317152007 1.png]]
Here comes the *chain switch*.
During synchronization, a [[Node|node]] typically receives data for only one chain. If the chain starts to branch, the data for both the main chain and its branches are retained. If one of the branches becomes longer than the main chain, a switch occurs to that branch, and it becomes the main chain.
This switch is called **fork resolution**.
In this process, all transactions are invalidated, and the blockchain reverts to the state it was in at the block before the rollback occurred - **`BLOCK N+1`**.
![[Pasted image 20250317210506.png]]
This also applies to other [[Data element (Datum)|datums]]. For example, **[[Anchor|anchors]]** of **[[Decree|decrees]]** are canceled.
In fact, in the future, if the chain **`N+2 -> N+3 -> N+4`** suddenly becomes longer than chain started from the block **`K`**, the blockchain will roll back again to the block **`N+1`**, and the chain starting from block **`N+2`** will once again become the main chain.
Since switching involves rolling back all blocks and data from the chain that was previously the main chain but has now become a side chain, a **block confirmation metric** is introduced.
The **number of confirmations** is the number of blocks in the chain after the block that requires confirmation.
When this number reaches the maximum fork resolution depth (in our case, **10**), the block becomes **irreversible**, and external services can rely on it.
![[Pasted image 20250317210553.png]]
In this example, it is shown that blocks **`N`**, **`N+1`**, and **`N+2`** have become **irreversible**.