Skip to main content

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 (C1,,Cs,Cs+1,,Cs+d)(C_1,\ldots,C_s,C_{s+1},\dots,C_{s+d}) be a slot commitment chainA chain created by a sequence of slot commitments. It is used to determine eligible blocks and finality.. Let AA 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 Cs+1,,Cs+dC_{s+1},\dots,C_{s+d} such that each block from AA approves CsC_s. Then the weight of the slot commitment CsC_s with drifting parameter dd (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 AA, i.e. those committee members who approve this commitment during dd slots after slot ss, i.e.

W(Cs)=iIssuerIDs(A)Wi(e),W(C_{s})=\sum_{i\in IssuerIDs(A)}W_i(e),

where slot ss belongs to epochA specific time period during which a dedicated committee is responsible for driving consensus. Epoch consists of multiple slots. ee.

Example

In this example, the committee consists of 77 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 (C1,C2)(C_1,C_2). The weight of the commitment C1C_1 with drifting parameter d=3d=3 can be computed as follows:

All the blocks, that are included in the set AA in the above definition, are highlighted with a border. The weight W(C1)W(C_1) is equal to the sum of voting weights of the blue, orange, purple, grey, and green nodes, i.e. W(C1)=1+2+3+1+1=8W(C_1)=1+2+3+1+1=8. The weight of the green node that commits to C2C_2 is counted as C2C_2 is an extension of C1C_1 and the corresponding block of the green node is issued at slot 44, which is covered by the drifting parameter. The weight of the grey node is counted only once in W(C1)W(C_1) even though it has issued two blocks satisfying the requirements. The weight of the yellow node that commits to C1C_1 at slot 55 is not counted as this slot is not covered by the drifting parameter d=3d=3, i.e. 1+3<51+3<5.

Illustration for computing the weight of a slot commitment

Image: Illustration for computing the weight of a slot commitment.

Cumulative Weight of a Slot Commitment Chain

Let (C1,,Cs,Cs+1,Cs+d)(C_1,\ldots,C_s,C_{s+1}\dots,C_{s+d}) be a slot commitment chain. Then the cumulative weight of the chain (C1,,Cs)(C_1,\ldots,C_s) with a drifting parameter dd is defined as

CW(C1,,Cs)=j=1sW(Cj).CW(C_1,\ldots,C_s)=\sum_{j=1}^{s}W(C_j).

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 CC is called conflicting to a slot commitment chain if this chain is conflicting with the slot commitment chain that ends at CC.

Suppose a node adopts a slot commitment chain chloc=(C1,,Cs+d)ch_{loc}=(C_1,\dots,C_{s+d}) and receives a block bb from a conflicting slot commitment chain chfork=(B1,,Bs+d)ch_{fork}=(B_1,\dots,B_{s+d}). Then the node proceeds with the following steps:

  1. Find the slot index ff of the forking point, i.e. C1=B1,,Cf=BfC_1=B_1,\dots,C_f=B_f and Cf+1Bf+1C_{f+1}\neq B_{f+1}.
  2. Check if the last finalized slot of the chain chlocch_{loc} is greater than ff. If yes, ignore the block bb and stay on the chain chlocch_{loc}. Otherwise, proceed with the next step.
  3. Check if the inequality holds CW(B1,,Bs)CW(C1,,Cs)CW(B_1,\dots,B_s)\le CW(C_1,\dots,C_s). If yes, ignore the block bb and stay on the chain chlocch_{loc}. Otherwise, proceed with the next step.
  4. If there exist at least optsChainSwitchingThreshold=3 consecutive indices when the cumulative weight of the conflicting chain chforkch_{fork} is larger than the one of the currently adopted chain chlocch_{loc}, i.e. CW(B1,,Bt)>CW(C1,,Ct),CW(B1,,Bt+1)>CW(C1,,Ct+1),CW(B1,,Bt+2)>CW(C1,,Ct+2)CW(B_1,\dots,B_{t})>CW(C_1,\dots,C_{t}), CW(B_1,\dots,B_{t+1})>CW(C_1,\dots,C_{t+1}), CW(B_1,\dots,B_{t+2})>CW(C_1,\dots,C_{t+2}) for fts2f\le t \le s-2, 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 chlocch_{loc} to chforkch_{fork} 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.