Chain Switching Rule
The chain switching rule in IOTA 2.0 is a tool that enables liveness for finalizationThe irreversible operation where blocks receive sufficient approval and consensus, ensuring their permanence. after an asynchronous period ends and allows for the safety property of the finalization flag. With the chain switching rule, a node finds the heaviest chain and syncs from that chain, i.e., updates the locally maintained Tangle and the ledger.
Cumulative Weight
Weight of a Slot Commitment
Let be a slot commitment chainA chain created by a sequence of slot commitments. It is used to determine eligible blocks and finality..
Let denote the set of all accepted validation blocksValidation Blocks is a special type of blocks that are issued by members of the Validator Committee. These block allows to reach consensus in the network. that are committed into such that each block from approves . Then the weight of the slot commitment with drifting parameter (in the code, it is set to parameter maxCommittableSlotAge
) is defined as the sum of voting weights of committee members who issued a block from , i.e. those committee members who approve this commitment during slots after slot , i.e.
where slot belongs to epochA specific time period during which a dedicated committee is responsible for driving consensus. Epoch consists of multiple slots. .
Example
In this example, the committee consists of nodes. Their weights are specified at the bottom of the following image.
Suppose that the current slotTime interval of fixed duration. The protocol divides time into non-overlapping slots. For each slot, nodes generate a slot commitment which encapsulates all accepted blocks and transactions issued within this time interval. commitment chain consists of two elements . The weight of the commitment with drifting parameter can be computed as follows:
All the blocks, that are included in the set in the above definition, are highlighted with a border. The weight is equal to the sum of voting weights of the blue, orange, purple, grey, and green nodes, i.e. . The weight of the green node that commits to is counted as is an extension of and the corresponding block of the green node is issued at slot , which is covered by the drifting parameter. The weight of the grey node is counted only once in even though it has issued two blocks satisfying the requirements. The weight of the yellow node that commits to at slot is not counted as this slot is not covered by the drifting parameter , i.e. .
Image: Illustration for computing the weight of a slot commitment.
Cumulative Weight of a Slot Commitment Chain
Let be a slot commitment chain. Then the cumulative weight of the chain with a drifting parameter is defined as
Chain Switching Rule Algorithm
The chain switching rule relies on the last finalized slot and the cumulative weight of slot commitment chains.
Conflicting Slot Commitments
Two slot commitment chains are called conflicting if none of them is a prefix of the other. A slot commitment is called conflicting to a slot commitment chain if this chain is conflicting with the slot commitment chain that ends at .
Suppose a node adopts a slot commitment chain and receives a block from a conflicting slot commitment chain . Then the node proceeds with the following steps:
- Find the slot index of the forking point, i.e. and .
- Check if the last finalized slot of the chain is greater than . If yes, ignore the block and stay on the chain . Otherwise, proceed with the next step.
- Check if the inequality holds . If yes, ignore the block and stay on the chain . Otherwise, proceed with the next step.
- If there exist at least
optsChainSwitchingThreshold=3
consecutive indices when the cumulative weight of the conflicting chain is larger than the one of the currently adopted chain , i.e. for , then request the attestation for the cumulative weightA system for valuing transactions. The cumulative weight of a transaction increases with each additional transaction that references it. A path through transactions with a higher cumulative weight is preferred when selecting tips., validate the attestations and switch to after the current slot is completed.
Chain Switching
Switching the chain only happens when the current slot is finished. This property is important for the safety of the finalization flag as it does not allow honest nodes to vote on conflicting chains within one slot.