You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @dev A factory of trees that keeps track of staked values for sortition.
21
-
*/
18
+
/// @title SortitionModule
19
+
/// @dev A factory of trees that keeps track of staked values for sortition.
22
20
contractSortitionModuleisISortitionModule {
23
-
/* Structs */
21
+
// ************************************* //
22
+
// * Enums / Structs * //
23
+
// ************************************* //
24
+
24
25
struct SortitionSumTree {
25
26
uint256 K; // The maximum number of children per node.
26
27
// We use this to keep track of vacant positions in the tree after removing a leaf. This is for keeping the tree as balanced as possible without spending gas on moving nodes around.
@@ -38,6 +39,10 @@ contract SortitionModule is ISortitionModule {
38
39
uint256 penalty; // Penalty value, in case the stake was set during execution.
39
40
}
40
41
42
+
// ************************************* //
43
+
// * Storage * //
44
+
// ************************************* //
45
+
41
46
uint256public constant MAX_STAKE_PATHS =4; // The maximum number of stake paths a juror can have.
42
47
uint256public constant DEFAULT_K =6; // Default number of children per node.
43
48
@@ -57,6 +62,10 @@ contract SortitionModule is ISortitionModule {
57
62
mapping(bytes32=> SortitionSumTree) sortitionSumTrees; // The mapping trees by keys.
58
63
mapping(uint256=> DelayedStake) public delayedStakes; // Stores the stakes that were changed during Drawing phase, to update them when the phase is switched to Staking.
59
64
65
+
// ************************************* //
66
+
// * Function Modifiers * //
67
+
// ************************************* //
68
+
60
69
modifier onlyByGovernor() {
61
70
require(address(governor) ==msg.sender, "Access not allowed: Governor only.");
62
71
_;
@@ -67,13 +76,16 @@ contract SortitionModule is ISortitionModule {
67
76
_;
68
77
}
69
78
70
-
/** @dev Constructor.
71
-
* @param _core The KlerosCore.
72
-
* @param _minStakingTime Minimal time to stake
73
-
* @param _maxDrawingTime Time after which the drawing phase can be switched
74
-
* @param _rng The random number generator.
75
-
* @param _rngLookahead Lookahead value for rng.
76
-
*/
79
+
// ************************************* //
80
+
// * Constructor * //
81
+
// ************************************* //
82
+
83
+
/// @dev Constructor.
84
+
/// @param _core The KlerosCore.
85
+
/// @param _minStakingTime Minimal time to stake
86
+
/// @param _maxDrawingTime Time after which the drawing phase can be switched
87
+
/// @param _rng The random number generator.
88
+
/// @param _rngLookahead Lookahead value for rng.
77
89
constructor(
78
90
address_governor,
79
91
KlerosCore _core,
@@ -91,26 +103,25 @@ contract SortitionModule is ISortitionModule {
91
103
rngLookahead = _rngLookahead;
92
104
}
93
105
94
-
/* Public */
106
+
// ************************************* //
107
+
// * Governance * //
108
+
// ************************************* //
95
109
96
-
/** @dev Changes the `minStakingTime` storage variable.
97
-
* @param _minStakingTime The new value for the `minStakingTime` storage variable.
98
-
*/
110
+
/// @dev Changes the `minStakingTime` storage variable.
111
+
/// @param _minStakingTime The new value for the `minStakingTime` storage variable.
99
112
function changeMinStakingTime(uint256_minStakingTime) external onlyByGovernor {
100
113
minStakingTime = _minStakingTime;
101
114
}
102
115
103
-
/** @dev Changes the `maxDrawingTime` storage variable.
104
-
* @param _maxDrawingTime The new value for the `maxDrawingTime` storage variable.
105
-
*/
116
+
/// @dev Changes the `maxDrawingTime` storage variable.
117
+
/// @param _maxDrawingTime The new value for the `maxDrawingTime` storage variable.
106
118
function changeMaxDrawingTime(uint256_maxDrawingTime) external onlyByGovernor {
107
119
maxDrawingTime = _maxDrawingTime;
108
120
}
109
121
110
-
/** @dev Changes the `_rng` and `_rngLookahead` storage variables.
111
-
* @param _rng The new value for the `RNGenerator` storage variable.
112
-
* @param _rngLookahead The new value for the `rngLookahead` storage variable.
113
-
*/
122
+
/// @dev Changes the `_rng` and `_rngLookahead` storage variables.
123
+
/// @param _rng The new value for the `RNGenerator` storage variable.
124
+
/// @param _rngLookahead The new value for the `rngLookahead` storage variable.
114
125
function changeRandomNumberGenerator(RNG _rng, uint256_rngLookahead) external onlyByGovernor {
115
126
rng = _rng;
116
127
rngLookahead = _rngLookahead;
@@ -120,6 +131,10 @@ contract SortitionModule is ISortitionModule {
120
131
}
121
132
}
122
133
134
+
// ************************************* //
135
+
// * State Modifiers * //
136
+
// ************************************* //
137
+
123
138
function passPhase() external {
124
139
if (phase == Phase.staking) {
125
140
require(
@@ -146,11 +161,9 @@ contract SortitionModule is ISortitionModule {
146
161
emitNewPhase(phase);
147
162
}
148
163
149
-
/**
150
-
* @dev Create a sortition sum tree at the specified key.
151
-
* @param _key The key of the new tree.
152
-
* @param _extraData Extra data that contains the number of children each node in the tree should have.
153
-
*/
164
+
/// @dev Create a sortition sum tree at the specified key.
165
+
/// @param _key The key of the new tree.
166
+
/// @param _extraData Extra data that contains the number of children each node in the tree should have.
154
167
function createTree(bytes32_key, bytesmemory_extraData) externaloverride onlyByCore {
155
168
SortitionSumTree storage tree = sortitionSumTrees[_key];
156
169
uint256 K =extraDataToTreeK(_extraData);
@@ -160,9 +173,8 @@ contract SortitionModule is ISortitionModule {
160
173
tree.nodes.push(0);
161
174
}
162
175
163
-
/** @dev Executes the next delayed stakes.
164
-
* @param _iterations The number of delayed stakes to execute.
165
-
*/
176
+
/// @dev Executes the next delayed stakes.
177
+
/// @param _iterations The number of delayed stakes to execute.
166
178
function executeDelayedStakes(uint256_iterations) external {
167
179
require(phase == Phase.staking, "Should be in Staking phase.");
168
180
@@ -216,21 +228,17 @@ contract SortitionModule is ISortitionModule {
216
228
disputesWithoutJurors--;
217
229
}
218
230
219
-
/**
220
-
* @dev Saves the random number to use it in sortition. Not used by this contract because the storing of the number is inlined in passPhase().
221
-
* @param _randomNumber Random number returned by RNG contract.
222
-
*/
231
+
/// @dev Saves the random number to use it in sortition. Not used by this contract because the storing of the number is inlined in passPhase().
232
+
/// @param _randomNumber Random number returned by RNG contract.
223
233
function notifyRandomNumber(uint256_randomNumber) publicoverride {}
224
234
225
-
/**
226
-
* @dev Sets the value for a particular court and its parent courts.
227
-
* @param _courtID ID of the court.
228
-
* @param _value The new value.
229
-
* @param _account Address of the juror.
230
-
* `O(log_k(n))` where
231
-
* `k` is the maximum number of children per node in the tree,
232
-
* and `n` is the maximum number of nodes ever appended.
233
-
*/
235
+
/// @dev Sets the value for a particular court and its parent courts.
236
+
/// @param _courtID ID of the court.
237
+
/// @param _value The new value.
238
+
/// @param _account Address of the juror.
239
+
/// `O(log_k(n))` where
240
+
/// `k` is the maximum number of children per node in the tree,
241
+
/// and `n` is the maximum number of nodes ever appended.
234
242
function setStake(address_account, uint96_courtID, uint256_value) externaloverride onlyByCore {
0 commit comments