UNPKG

namillum

Version:
62 lines (50 loc) 2.44 kB
--- id: core-difficulty-adjustment title: Difficulty Adjustment keywords: - core - difficulty - adjustment description: Core protocol design - difficulty adjustment. --- --- Zilliqa has a dynamic difficulty level adjustment mechanism. The goal of this mechanism is to adjust the difficulty level according to the number of PoW submissions received. When the network receives a low number of PoW submissions, the mechanism will reduce the difficulty so that more nodes can join and maintain the network. On the other hand, when the network receives a high number of PoW submissions, the mechanism will increase the difficulty level, making it harder for Sybil attacks to be executed. ## Adjustment Procedure 1. When we bootstrap the system, every node reads the initial difficulty level from `constants.xml`. After that, the nodes will update the difficulty level at the first transaction epoch of each DS epoch 1. At the beginning of each DS epoch, every DS node receives PoW submissions and records them. When the DS leader proposes the next DS block, it calls `CalculateNewDifficulty()` and `CalculateNewDSDifficulty()` to calculate the new difficulty levels. These difficulty levels are placed in the `m_dsDifficulty` and `m_difficulty` fields in the DS block. Finally, the DS leader announces the DS block to start the consensus 1. The DS backup nodes receive the announcement, and calculate the new difficulty by similarly calling `CalculateNewDifficulty()` and `CalculateNewDSDifficulty()` then comparing the results with those proposed by the DS leader 1. Once the DS committee completes consensus over the DS block containing the new difficulty level, the committee broadcasts the block to the shards. The shard nodes accept the new difficulty and use it to do PoW for the next DS epoch 1. New nodes that are not part of the network can get the latest difficulty from the lookup nodes by retrieving the latest DS block ## Adjustment Formula and Parameters There are 4 parameters in `constants.xml` that are used to calculate the difficulty: - `POW_CHANGE_TO_ADJ_DIFF` - `POW_CHANGE_TO_ADJ_DS_DIFF` - `EXPECTED_SHARD_NODE_NUM` - `NUM_DS_ELECTION` Additionally, there are two dynamic parameters that are used to calculate the difficulty: - The number of shard PoW submissions - The number of DS PoW submissions The basic formulas used to calculate the new difficulty are: