@@ -42,6 +42,9 @@ contract MCR {
42
42
// preserved records of unstake by address per epoch
43
43
mapping (uint256 => mapping ( address => uint256 )) public epochUnstakes;
44
44
45
+ // track the total stake of the epoch (computed at rollover)
46
+ mapping (uint256 => uint256 ) public epochTotalStake;
47
+
45
48
// map each block height to an epoch
46
49
mapping (uint256 => uint256 ) public blockHeightEpochAssignments;
47
50
@@ -81,26 +84,6 @@ contract MCR {
81
84
return BlockCommitment (height, commitment, blockId);
82
85
}
83
86
84
- // gets the the genesis stake required
85
- function getGenesisStakeRequired () public view returns (uint256 ) {
86
- return genesisStakeRequired;
87
- }
88
-
89
- // gets the the genesis stake accumulated
90
- function getGenesisStakeAccumulated () public view returns (uint256 ) {
91
- return genesisStakeAccumulated;
92
- }
93
-
94
- // gets the epoch duration
95
- function getEpochDuration () public view returns (uint256 ) {
96
- return epochDuration;
97
- }
98
-
99
- // gets the leading block tolerance
100
- function getLeadingBlockTolerance () public view returns (uint256 ) {
101
- return leadingBlockTolerance;
102
- }
103
-
104
87
// gets whether the genesis ceremony has ended
105
88
function hasGenesisCeremonyEnded () public view returns (bool ) {
106
89
return genesisStakeAccumulated >= genesisStakeRequired;
@@ -148,12 +131,7 @@ contract MCR {
148
131
149
132
// gets the total stake for a given epoch
150
133
function getTotalStakeForEpoch (uint256 epoch ) public view returns (uint256 ) {
151
-
152
- uint256 totalStake = 0 ;
153
- for (uint256 i = 0 ; i < validators.length (); i++ ){
154
- totalStake += getStakeAtEpoch (validators.at (i), epoch);
155
- }
156
- return totalStake;
134
+ return epochTotalStake[epoch];
157
135
}
158
136
159
137
// gets the total stake for the current epoch
@@ -206,7 +184,9 @@ contract MCR {
206
184
// roll over the genesis epoch to a timestamp epoch
207
185
for (uint256 i = 0 ; i < validators.length (); i++ ){
208
186
address validatorAddress = validators.at (i);
209
- epochStakes[getCurrentEpoch ()][validatorAddress] = epochStakes[0 ][validatorAddress];
187
+ uint256 stake = epochStakes[0 ][validatorAddress];
188
+ epochStakes[getCurrentEpoch ()][validatorAddress] = stake;
189
+ epochTotalStake[getCurrentEpoch ()] += stake;
210
190
}
211
191
212
192
@@ -249,6 +229,9 @@ contract MCR {
249
229
// the amount of stake rolled over is stake[currentEpoch] - unstake[nextEpoch]
250
230
epochStakes[epochNumber + 1 ][validatorAddress] += epochStakes[epochNumber][validatorAddress] - epochUnstakes[epochNumber + 1 ][validatorAddress];
251
231
232
+ // also precompute the total stake for the epoch
233
+ epochTotalStake[epochNumber + 1 ] += epochStakes[epochNumber + 1 ][validatorAddress];
234
+
252
235
// the unstake is then paid out
253
236
// note: this is the only place this takes place
254
237
// there's not risk of double payout, so long as rollOverValidator is only called once per epoch
@@ -307,6 +290,8 @@ contract MCR {
307
290
// note: we could keep track of seen commitments in a set
308
291
// but since the operations we're doing are very cheap, the set actually adds overhead
309
292
293
+ uint256 supermajority = (2 * getTotalStakeForEpoch (blockEpoch))/ 3 ;
294
+
310
295
// iterate over the validator set
311
296
for (uint256 i = 0 ; i < validators.length (); i++ ){
312
297
@@ -318,7 +303,7 @@ contract MCR {
318
303
// check the total stake on the commitment
319
304
uint256 totalStakeOnCommitment = commitmentStakes[blockCommitment.height][blockCommitment.commitment];
320
305
321
- if (totalStakeOnCommitment > ( 2 * getTotalStakeForEpoch (blockEpoch)) / 3 ) {
306
+ if (totalStakeOnCommitment > supermajority ) {
322
307
323
308
// accept the block commitment (this may trigger a roll over of the epoch)
324
309
acceptBlockCommitment (blockCommitment, blockEpoch);
0 commit comments