Skip to content

Commit 0655ca3

Browse files
author
Bernhard Scholz
committed
Reformatting code
1 parent dffbd41 commit 0655ca3

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

contracts/sfc/ConstantsManager.sol

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ contract ConstantsManager is Ownable {
3333
uint256 public gasPriceBalancingCounterweight;
3434

3535
// epoch threshold for stop counting alive epochs (avoid diminishing impact of new uptimes) and
36-
// is also the minimum number of epochs necessary for enabling the deactivation.
36+
// is also the minimum number of epochs necessary for enabling the deactivation.
3737
int32 public numEpochsAliveThreshold;
3838

3939
// minimum average uptime in Q1.30 format; acceptable bounds [0,0.9]
@@ -208,7 +208,8 @@ contract ConstantsManager is Ownable {
208208
if (v < 0) {
209209
revert ValueTooSmall();
210210
}
211-
if (v > 966367641) { // 0.9 in Q1.30
211+
if (v > 966367641) {
212+
// 0.9 in Q1.30
212213
revert ValueTooLarge();
213214
}
214215
minAverageUptime = v;

contracts/sfc/SFC.sol

+13-10
Original file line numberDiff line numberDiff line change
@@ -382,39 +382,42 @@ contract SFC is SFCBase, Version {
382382
for (uint256 i = 0; i < validatorIDs.length; i++) {
383383
uint256 validatorID = validatorIDs[i];
384384
// compute normalised uptime as a percentage in the Q1.30 fixed-point format
385-
uint256 normalisedUptime = uptimes[i] * (1 << 30)/ epochDuration;
385+
uint256 normalisedUptime = (uptimes[i] * (1 << 30)) / epochDuration;
386386
if (normalisedUptime < 0) {
387387
normalisedUptime = 0;
388388
} else if (normalisedUptime > 1 << 30) {
389389
normalisedUptime = 1 << 30;
390390
}
391-
// update average uptime data structure
391+
// update average uptime data structure
392392
// Assumes that if in the previous snapshot the validator
393393
// does not exist, the map returns zero.
394394
int32 n = prevSnapshot.averageData[validatorID].numEpochsAlive;
395395
int64 tmp;
396-
if (n > 0) {
397-
tmp = int64(n-1) * int64(snapshot.averageData[validatorID].averageUptime) + int64(uint64(normalisedUptime));
398-
if (n > 1) {
399-
tmp += (int64(n) * int64(prevSnapshot.averageData[validatorID].averageUptimeError)) / int64(n-1);
396+
if (n > 0) {
397+
tmp =
398+
int64(n - 1) *
399+
int64(snapshot.averageData[validatorID].averageUptime) +
400+
int64(uint64(normalisedUptime));
401+
if (n > 1) {
402+
tmp += (int64(n) * int64(prevSnapshot.averageData[validatorID].averageUptimeError)) / int64(n - 1);
400403
}
401404
snapshot.averageData[validatorID].averageUptimeError = int32(tmp % int64(n));
402405
tmp /= int64(n);
403406
} else {
404407
tmp = int64(uint64(normalisedUptime));
405408
}
406409
if (tmp < 0) {
407-
tmp = 0;
408-
} else if (tmp > 1 << 30){
409-
tmp = 1 << 30;
410+
tmp = 0;
411+
} else if (tmp > 1 << 30) {
412+
tmp = 1 << 30;
410413
}
411414
snapshot.averageData[validatorID].averageUptime = int32(tmp);
412415
if (n < c.numEpochsAliveThreshold()) {
413416
snapshot.averageData[validatorID].numEpochsAlive = n + 1;
414417
}
415418
// remove validator if average uptime drops below min average uptime
416419
// (by setting minAverageUptime to zero, this check is ignored)
417-
if (int32(tmp) < c.minAverageUptime() && n >= c.numEpochsAliveThreshold() ) {
420+
if (int32(tmp) < c.minAverageUptime() && n >= c.numEpochsAliveThreshold()) {
418421
_setValidatorDeactivated(validatorIDs[i], OFFLINE_BIT);
419422
_syncValidator(validatorIDs[i], false);
420423
}

contracts/sfc/SFCState.sol

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ contract SFCState is Initializable, Ownable {
4848
mapping(address => mapping(uint256 => uint256)) public stashedRewardsUntilEpoch;
4949

5050
struct WithdrawalRequest {
51-
uint256 epoch; // epoch where undelegated
52-
uint256 time; // when undelegated
51+
uint256 epoch; // epoch where undelegated
52+
uint256 time; // when undelegated
5353
uint256 amount;
5454
}
5555

@@ -73,12 +73,12 @@ contract SFCState is Initializable, Ownable {
7373

7474
// data structure to compute average uptime for each active validator
7575
struct AverageData {
76-
// average uptime
76+
// average uptime
7777
int32 averageUptime;
7878
// average uptime error term
7979
int32 averageUptimeError;
8080
// number of alive epochs (counts only up to numEpochsAliveThreshold)
81-
int32 numEpochsAlive;
81+
int32 numEpochsAlive;
8282
}
8383

8484
struct EpochSnapshot {
@@ -88,7 +88,7 @@ contract SFCState is Initializable, Ownable {
8888
mapping(uint256 => uint256) accumulatedRewardPerToken;
8989
// validator ID => accumulated online time
9090
mapping(uint256 => uint256) accumulatedUptime;
91-
// validator ID => average uptime as a percentage
91+
// validator ID => average uptime as a percentage
9292
mapping(uint256 => AverageData) averageData;
9393
// validator ID => gas fees from txs originated by the validator
9494
mapping(uint256 => uint256) accumulatedOriginatedTxsFee;

0 commit comments

Comments
 (0)