@@ -58,7 +58,7 @@ contract SortitionModule is ISortitionModule, UUPSProxiable, Initializable {
58
58
uint256 public disputesWithoutJurors; // The number of disputes that have not finished drawing jurors.
59
59
RNG public rng; // The random number generator.
60
60
uint256 public randomNumber; // Random number returned by RNG.
61
- uint256 public rngLookahead ; // Minimal block distance between requesting and obtaining a random number.
61
+ uint256 public rngFallbackTimeout ; // Time after which RNG fallback will be used if no random number was received .
62
62
uint256 public delayedStakeWriteIndex; // The index of the last `delayedStake` item that was written to the array. 0 index is skipped.
63
63
uint256 public delayedStakeReadIndex; // The index of the next `delayedStake` item that should be processed. Starts at 1 because 0 index is skipped.
64
64
mapping (bytes32 => SortitionSumTree) sortitionSumTrees; // The mapping trees by keys.
@@ -92,22 +92,22 @@ contract SortitionModule is ISortitionModule, UUPSProxiable, Initializable {
92
92
/// @param _minStakingTime Minimal time to stake
93
93
/// @param _maxDrawingTime Time after which the drawing phase can be switched
94
94
/// @param _rng The random number generator.
95
- /// @param _rngLookahead Lookahead value for rng .
95
+ /// @param _rngFallbackTimeout RNG fallback timeout in seconds .
96
96
function initialize (
97
97
address _governor ,
98
98
KlerosCore _core ,
99
99
uint256 _minStakingTime ,
100
100
uint256 _maxDrawingTime ,
101
101
RNG _rng ,
102
- uint256 _rngLookahead
102
+ uint256 _rngFallbackTimeout
103
103
) external reinitializer (1 ) {
104
104
governor = _governor;
105
105
core = _core;
106
106
minStakingTime = _minStakingTime;
107
107
maxDrawingTime = _maxDrawingTime;
108
108
lastPhaseChange = block .timestamp ;
109
109
rng = _rng;
110
- rngLookahead = _rngLookahead ;
110
+ rngFallbackTimeout = _rngFallbackTimeout ;
111
111
delayedStakeReadIndex = 1 ;
112
112
}
113
113
@@ -135,18 +135,22 @@ contract SortitionModule is ISortitionModule, UUPSProxiable, Initializable {
135
135
maxDrawingTime = _maxDrawingTime;
136
136
}
137
137
138
- /// @dev Changes the `_rng` and `_rngLookahead` storage variables .
138
+ /// @dev Changes the `_rng` storage variable .
139
139
/// @param _rng The new value for the `RNGenerator` storage variable.
140
- /// @param _rngLookahead The new value for the `rngLookahead` storage variable.
141
- function changeRandomNumberGenerator (RNG _rng , uint256 _rngLookahead ) external onlyByGovernor {
140
+ function changeRandomNumberGenerator (RNG _rng ) external onlyByGovernor {
142
141
rng = _rng;
143
- rngLookahead = _rngLookahead;
144
142
if (phase == Phase.generating) {
145
- rng.requestRandomness (block .number + rngLookahead );
143
+ rng.requestRandomness (block .number );
146
144
randomNumberRequestBlock = block .number ;
147
145
}
148
146
}
149
147
148
+ /// @dev Changes the `rngFallbackTimeout` storage variable.
149
+ /// @param _rngFallbackTimeout The new value for the `rngFallbackTimeout` storage variable.
150
+ function changeRNGFallbackTimeout (uint256 _rngFallbackTimeout ) external onlyByGovernor {
151
+ rngFallbackTimeout = _rngFallbackTimeout;
152
+ }
153
+
150
154
// ************************************* //
151
155
// * State Modifiers * //
152
156
// ************************************* //
@@ -158,23 +162,31 @@ contract SortitionModule is ISortitionModule, UUPSProxiable, Initializable {
158
162
"The minimum staking time has not passed yet. "
159
163
);
160
164
require (disputesWithoutJurors > 0 , "There are no disputes that need jurors. " );
161
- rng.requestRandomness (block .number + rngLookahead );
165
+ rng.requestRandomness (block .number );
162
166
randomNumberRequestBlock = block .number ;
163
167
phase = Phase.generating;
168
+ lastPhaseChange = block .timestamp ;
169
+ emit NewPhase (phase);
164
170
} else if (phase == Phase.generating) {
165
- randomNumber = rng.receiveRandomness (randomNumberRequestBlock + rngLookahead);
166
- require (randomNumber != 0 , "Random number is not ready yet " );
167
- phase = Phase.drawing;
171
+ randomNumber = rng.receiveRandomness (randomNumberRequestBlock);
172
+ if (randomNumber == 0 ) {
173
+ if (block .number > randomNumberRequestBlock + rngFallbackTimeout) {
174
+ rng.receiveRandomnessFallback (block .number );
175
+ }
176
+ } else {
177
+ phase = Phase.drawing;
178
+ lastPhaseChange = block .timestamp ;
179
+ emit NewPhase (phase);
180
+ }
168
181
} else if (phase == Phase.drawing) {
169
182
require (
170
183
disputesWithoutJurors == 0 || block .timestamp - lastPhaseChange >= maxDrawingTime,
171
184
"There are still disputes without jurors and the maximum drawing time has not passed yet. "
172
185
);
173
186
phase = Phase.staking;
187
+ lastPhaseChange = block .timestamp ;
188
+ emit NewPhase (phase);
174
189
}
175
-
176
- lastPhaseChange = block .timestamp ;
177
- emit NewPhase (phase);
178
190
}
179
191
180
192
/// @dev Create a sortition sum tree at the specified key.
0 commit comments