@@ -11,8 +11,8 @@ import {Signature} from "@aztec/core/libraries/crypto/SignatureLib.sol";
11
11
import {DataStructures} from "@aztec/core/libraries/DataStructures.sol " ;
12
12
import {Errors} from "@aztec/core/libraries/Errors.sol " ;
13
13
import {
14
- Timestamp, Slot, Epoch, SlotLib, EpochLib, TimeFns
15
- } from "@aztec/core/libraries/TimeMath .sol " ;
14
+ Timestamp, Slot, Epoch, SlotLib, EpochLib, TimeLib
15
+ } from "@aztec/core/libraries/TimeLib .sol " ;
16
16
import {ValidatorSelectionLib} from
17
17
"@aztec/core/libraries/ValidatorSelectionLib/ValidatorSelectionLib.sol " ;
18
18
import {Staking} from "@aztec/core/staking/Staking.sol " ;
@@ -27,19 +27,19 @@ import {EnumerableSet} from "@oz/utils/structs/EnumerableSet.sol";
27
27
* It is a reference implementation, it is not optimized for gas.
28
28
*
29
29
*/
30
- contract ValidatorSelection is Staking , TimeFns , IValidatorSelection {
30
+ contract ValidatorSelection is Staking , IValidatorSelection {
31
31
using EnumerableSet for EnumerableSet.AddressSet;
32
32
33
33
using SlotLib for Slot;
34
34
using EpochLib for Epoch;
35
+ using TimeLib for Timestamp;
36
+ using TimeLib for Slot;
37
+ using TimeLib for Epoch;
35
38
36
39
// The target number of validators in a committee
37
40
// @todo #8021
38
41
uint256 public immutable TARGET_COMMITTEE_SIZE;
39
42
40
- // The time that the contract was deployed
41
- Timestamp public immutable GENESIS_TIME;
42
-
43
43
ValidatorSelectionStorage private validatorSelectionStore;
44
44
45
45
constructor (
@@ -50,14 +50,22 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection {
50
50
uint256 _slotDuration ,
51
51
uint256 _epochDuration ,
52
52
uint256 _targetCommitteeSize
53
- )
54
- Staking (_stakingAsset, _minimumStake, _slashingQuorum, _roundSize)
55
- TimeFns (_slotDuration, _epochDuration)
56
- {
57
- GENESIS_TIME = Timestamp.wrap (block .timestamp );
58
- SLOT_DURATION = _slotDuration;
59
- EPOCH_DURATION = _epochDuration;
53
+ ) Staking (_stakingAsset, _minimumStake, _slashingQuorum, _roundSize) {
60
54
TARGET_COMMITTEE_SIZE = _targetCommitteeSize;
55
+
56
+ TimeLib.initialize (block .timestamp , _slotDuration, _epochDuration);
57
+ }
58
+
59
+ function getGenesisTime () external view override (IValidatorSelection) returns (Timestamp) {
60
+ return Timestamp.wrap (TimeLib.getStorage ().genesisTime);
61
+ }
62
+
63
+ function getSlotDuration () external view override (IValidatorSelection) returns (uint256 ) {
64
+ return TimeLib.getStorage ().slotDuration;
65
+ }
66
+
67
+ function getEpochDuration () external view override (IValidatorSelection) returns (uint256 ) {
68
+ return TimeLib.getStorage ().epochDuration;
61
69
}
62
70
63
71
/**
@@ -224,7 +232,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection {
224
232
override (IValidatorSelection)
225
233
returns (Timestamp)
226
234
{
227
- return GENESIS_TIME + toTimestamp (_slotNumber );
235
+ return _slotNumber. toTimestamp ();
228
236
}
229
237
230
238
/**
@@ -275,7 +283,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection {
275
283
* @return The computed epoch
276
284
*/
277
285
function getEpochAt (Timestamp _ts ) public view override (IValidatorSelection) returns (Epoch) {
278
- return _ts < GENESIS_TIME ? Epoch. wrap ( 0 ) : epochFromTimestamp (_ts - GENESIS_TIME );
286
+ return _ts. epochFromTimestamp ();
279
287
}
280
288
281
289
/**
@@ -286,7 +294,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection {
286
294
* @return The computed slot
287
295
*/
288
296
function getSlotAt (Timestamp _ts ) public view override (IValidatorSelection) returns (Slot) {
289
- return _ts < GENESIS_TIME ? Slot. wrap ( 0 ) : slotFromTimestamp (_ts - GENESIS_TIME );
297
+ return _ts. slotFromTimestamp ();
290
298
}
291
299
292
300
/**
@@ -302,7 +310,7 @@ contract ValidatorSelection is Staking, TimeFns, IValidatorSelection {
302
310
override (IValidatorSelection)
303
311
returns (Epoch)
304
312
{
305
- return Epoch. wrap ( _slotNumber.unwrap () / EPOCH_DURATION );
313
+ return _slotNumber.epochFromSlot ( );
306
314
}
307
315
308
316
// Can be used to add validators without setting up the epoch, useful for the initial set.
0 commit comments