Skip to content

Commit

Permalink
reduce size of validatorSet contract
Browse files Browse the repository at this point in the history
  • Loading branch information
dean65 committed Feb 16, 2022
1 parent 7bd0969 commit 3b1fe03
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
36 changes: 18 additions & 18 deletions contracts/BSCValidatorSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
}

function swap(address[] memory set, uint i, uint j) internal pure {
address tmp = set[i];
set[i]=set[j];
set[j]=tmp;
address tmp = set[i];
set[i]=set[j];
set[j]=tmp;
}

function getMiningValidators(uint256 epochNumber) public view returns(address[] memory) {
Expand Down Expand Up @@ -496,41 +496,41 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
/*********************** Param update ********************************/
function updateParam(string calldata key, bytes calldata value) override external onlyInit onlyGov{
if (Memory.compareStrings(key, "expireTimeSecondGap")) {
require(value.length == 32, "length of expireTimeSecondGap mismatch");
require(value.length == 32, "length mismatch");
uint256 newExpireTimeSecondGap = BytesToTypes.bytesToUint256(32, value);
require(newExpireTimeSecondGap >=100 && newExpireTimeSecondGap <= 1e5, "the expireTimeSecondGap is out of range");
require(newExpireTimeSecondGap >=100 && newExpireTimeSecondGap <= 1e5, "out of range");
expireTimeSecondGap = newExpireTimeSecondGap;
} else if (Memory.compareStrings(key, "burnRatio")) {
require(value.length == 32, "length of burnRatio mismatch");
require(value.length == 32, "length mismatch");
uint256 newBurnRatio = BytesToTypes.bytesToUint256(32, value);
require(newBurnRatio <= BURN_RATIO_SCALE, "the burnRatio must be no greater than 10000");
require(newBurnRatio <= BURN_RATIO_SCALE, "must be no greater than 10000");
burnRatio = newBurnRatio;
burnRatioInitialized = true;
} else if (Memory.compareStrings(key, "maxNumOfMaintaining")) {
require(value.length == 32, "length of maxNumOfMaintaining mismatch");
require(value.length == 32, "length mismatch");
uint256 newMaxNumOfMaintaining = BytesToTypes.bytesToUint256(32, value);
require(newMaxNumOfMaintaining < MAX_NUM_OF_VALIDATORS, "the maxNumOfMaintaining must be less than MAX_NUM_OF_VALIDATORS");
require(newMaxNumOfMaintaining < MAX_NUM_OF_VALIDATORS, "must be less than MAX_NUM_OF_VALIDATORS");
maxNumOfMaintaining = newMaxNumOfMaintaining;
} else if (Memory.compareStrings(key, "maintainSlashScale")) {
require(value.length == 32, "length of maintainSlashScale mismatch");
require(value.length == 32, "length mismatch");
uint256 newMaintainSlashScale = BytesToTypes.bytesToUint256(32, value);
require(newMaintainSlashScale > 0, "the maintainSlashScale must be greater than 0");
require(newMaintainSlashScale > 0, "must be greater than 0");
maintainSlashScale = newMaintainSlashScale;
} else if (Memory.compareStrings(key, "maxNumOfWorkingCandidates")) {
require(value.length == 32, "length of maxNumOfWorkingCandidates mismatch");
require(value.length == 32, "length mismatch");
uint256 newMaxNumOfWorkingCandidates = BytesToTypes.bytesToUint256(32, value);
require(newMaxNumOfWorkingCandidates >= 0, "the maxNumOfWorkingCandidates must be not less than 0");
require(newMaxNumOfWorkingCandidates <= maxNumOfCandidates, "the maxNumOfWorkingCandidates must be not less than maxNumOfCandidates");
require(newMaxNumOfWorkingCandidates >= 0, "must be not less than 0");
require(newMaxNumOfWorkingCandidates <= maxNumOfCandidates, "must be not less than maxNumOfCandidates");
maxNumOfWorkingCandidates = newMaxNumOfWorkingCandidates;
} else if (Memory.compareStrings(key, "maxNumOfCandidates")) {
require(value.length == 32, "length of maxNumOfCandidates mismatch");
require(value.length == 32, "length mismatch");
uint256 newMaxNumOfCandidates = BytesToTypes.bytesToUint256(32, value);
require(newMaxNumOfCandidates >= 0, "the maxNumOfCandidates must be not less than 0");
require(newMaxNumOfCandidates >= 0, "must be not less than 0");
maxNumOfCandidates = newMaxNumOfCandidates;
} else if (Memory.compareStrings(key, "numOfActiveValidators")) {
require(value.length == 32, "length of numOfActiveValidators mismatch");
require(value.length == 32, "length mismatch");
uint256 newNumOfActiveValidators = BytesToTypes.bytesToUint256(32, value);
require(newNumOfActiveValidators > 0, "the numOfActiveValidators must be greater than 0");
require(newNumOfActiveValidators > 0, "must be greater than 0");
numOfActiveValidators = newNumOfActiveValidators;
} else {
require(false, "unknown param");
Expand Down
36 changes: 18 additions & 18 deletions contracts/BSCValidatorSet.template
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
}

function swap(address[] memory set, uint i, uint j) internal pure {
address tmp = set[i];
set[i]=set[j];
set[j]=tmp;
address tmp = set[i];
set[i]=set[j];
set[j]=tmp;
}

function getMiningValidators(uint256 epochNumber) public view returns(address[] memory) {
Expand Down Expand Up @@ -504,41 +504,41 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
/*********************** Param update ********************************/
function updateParam(string calldata key, bytes calldata value) override external onlyInit onlyGov{
if (Memory.compareStrings(key, "expireTimeSecondGap")) {
require(value.length == 32, "length of expireTimeSecondGap mismatch");
require(value.length == 32, "length mismatch");
uint256 newExpireTimeSecondGap = BytesToTypes.bytesToUint256(32, value);
require(newExpireTimeSecondGap >=100 && newExpireTimeSecondGap <= 1e5, "the expireTimeSecondGap is out of range");
require(newExpireTimeSecondGap >=100 && newExpireTimeSecondGap <= 1e5, "out of range");
expireTimeSecondGap = newExpireTimeSecondGap;
} else if (Memory.compareStrings(key, "burnRatio")) {
require(value.length == 32, "length of burnRatio mismatch");
require(value.length == 32, "length mismatch");
uint256 newBurnRatio = BytesToTypes.bytesToUint256(32, value);
require(newBurnRatio <= BURN_RATIO_SCALE, "the burnRatio must be no greater than 10000");
require(newBurnRatio <= BURN_RATIO_SCALE, "must be no greater than 10000");
burnRatio = newBurnRatio;
burnRatioInitialized = true;
} else if (Memory.compareStrings(key, "maxNumOfMaintaining")) {
require(value.length == 32, "length of maxNumOfMaintaining mismatch");
require(value.length == 32, "length mismatch");
uint256 newMaxNumOfMaintaining = BytesToTypes.bytesToUint256(32, value);
require(newMaxNumOfMaintaining < MAX_NUM_OF_VALIDATORS, "the maxNumOfMaintaining must be less than MAX_NUM_OF_VALIDATORS");
require(newMaxNumOfMaintaining < MAX_NUM_OF_VALIDATORS, "must be less than MAX_NUM_OF_VALIDATORS");
maxNumOfMaintaining = newMaxNumOfMaintaining;
} else if (Memory.compareStrings(key, "maintainSlashScale")) {
require(value.length == 32, "length of maintainSlashScale mismatch");
require(value.length == 32, "length mismatch");
uint256 newMaintainSlashScale = BytesToTypes.bytesToUint256(32, value);
require(newMaintainSlashScale > 0, "the maintainSlashScale must be greater than 0");
require(newMaintainSlashScale > 0, "must be greater than 0");
maintainSlashScale = newMaintainSlashScale;
} else if (Memory.compareStrings(key, "maxNumOfWorkingCandidates")) {
require(value.length == 32, "length of maxNumOfWorkingCandidates mismatch");
require(value.length == 32, "length mismatch");
uint256 newMaxNumOfWorkingCandidates = BytesToTypes.bytesToUint256(32, value);
require(newMaxNumOfWorkingCandidates >= 0, "the maxNumOfWorkingCandidates must be not less than 0");
require(newMaxNumOfWorkingCandidates <= maxNumOfCandidates, "the maxNumOfWorkingCandidates must be not less than maxNumOfCandidates");
require(newMaxNumOfWorkingCandidates >= 0, "must be not less than 0");
require(newMaxNumOfWorkingCandidates <= maxNumOfCandidates, "must be not less than maxNumOfCandidates");
maxNumOfWorkingCandidates = newMaxNumOfWorkingCandidates;
} else if (Memory.compareStrings(key, "maxNumOfCandidates")) {
require(value.length == 32, "length of maxNumOfCandidates mismatch");
require(value.length == 32, "length mismatch");
uint256 newMaxNumOfCandidates = BytesToTypes.bytesToUint256(32, value);
require(newMaxNumOfCandidates >= 0, "the maxNumOfCandidates must be not less than 0");
require(newMaxNumOfCandidates >= 0, "must be not less than 0");
maxNumOfCandidates = newMaxNumOfCandidates;
} else if (Memory.compareStrings(key, "numOfActiveValidators")) {
require(value.length == 32, "length of numOfActiveValidators mismatch");
require(value.length == 32, "length mismatch");
uint256 newNumOfActiveValidators = BytesToTypes.bytesToUint256(32, value);
require(newNumOfActiveValidators > 0, "the numOfActiveValidators must be greater than 0");
require(newNumOfActiveValidators > 0, "must be greater than 0");
numOfActiveValidators = newNumOfActiveValidators;
} else {
require(false, "unknown param");
Expand Down

0 comments on commit 3b1fe03

Please sign in to comment.