Skip to content

Commit

Permalink
added deactivation procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Scholz committed Oct 29, 2024
1 parent 8cd2f30 commit dffbd41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions contracts/sfc/ConstantsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ contract ConstantsManager is Ownable {
uint256 public targetGasPowerPerSecond;
uint256 public gasPriceBalancingCounterweight;

// number of epochs for counting the average uptime of validators
// epoch threshold for stop counting alive epochs (avoid diminishing impact of new uptimes) and
// is also the minimum number of epochs necessary for enabling the deactivation.
int32 public numEpochsAliveThreshold;

// minimum average uptime
// minimum average uptime in Q1.30 format; acceptable bounds [0,0.9]
int32 public minAverageUptime;

/**
Expand Down
8 changes: 8 additions & 0 deletions contracts/sfc/SFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,14 @@ contract SFC is SFCBase, Version {
) internal {
for (uint256 i = 0; i < validatorIDs.length; i++) {
uint256 validatorID = validatorIDs[i];
// compute normalised uptime as a percentage in the Q1.30 fixed-point format
uint256 normalisedUptime = uptimes[i] * (1 << 30)/ epochDuration;
if (normalisedUptime < 0) {
normalisedUptime = 0;
} else if (normalisedUptime > 1 << 30) {
normalisedUptime = 1 << 30;
}
// update average uptime data structure
// Assumes that if in the previous snapshot the validator
// does not exist, the map returns zero.
int32 n = prevSnapshot.averageData[validatorID].numEpochsAlive;
Expand All @@ -410,6 +412,12 @@ contract SFC is SFCBase, Version {
if (n < c.numEpochsAliveThreshold()) {
snapshot.averageData[validatorID].numEpochsAlive = n + 1;
}
// remove validator if average uptime drops below min average uptime
// (by setting minAverageUptime to zero, this check is ignored)
if (int32(tmp) < c.minAverageUptime() && n >= c.numEpochsAliveThreshold() ) {
_setValidatorDeactivated(validatorIDs[i], OFFLINE_BIT);
_syncValidator(validatorIDs[i], false);
}
}
}

Expand Down

0 comments on commit dffbd41

Please sign in to comment.